# PRODUCTS

query getProduct($id: ID!) {
    product(id: $id) {
        id
        title
        handle
        descriptionHtml
        vendor
        productType
        tags
        status
        createdAt
        updatedAt
        publishedAt
        templateSuffix
        options {
            id
            name
            position
            optionValues {
                id
                name
                hasVariants
            }
        }
        variants(first: 250) {
            edges {
                node {
                    id
                    title
                    price
                    compareAtPrice
                    sku
                    barcode
                    inventoryQuantity
                    selectedOptions {
                        name
                        value
                    }
                    position
                    taxable
                    createdAt
                    updatedAt
                }
            }
        }
        media(first: 250) {
            edges {
                node {
                    ... on MediaImage {
                        id
                        image {
                            url
                            altText
                        }
                        alt
                    }
                }
            }
        }
        collections(first: 250) {
            edges {
                node {
                    id
                    handle
                    title
                    description
                    updatedAt
                }
            }
        }
    }
}

query getProductBasic($id: ID!) {
    product(id: $id) {
        id
        title
        handle
        descriptionHtml
        vendor
        productType
        tags
        status
        createdAt
        updatedAt
        publishedAt
        templateSuffix
    }
}

query getProductVariants($id: ID!, $first: Int = 250, $after: String) {
    product(id: $id) {
        id
        variants(first: $first, after: $after) {
            edges {
                node {
                    id
                    title
                    price
                    compareAtPrice
                    sku
                    barcode
                    selectedOptions {
                        name
                        value
                    }
                    position
                    createdAt
                    updatedAt
                }
            }
            pageInfo {
                hasNextPage
                hasPreviousPage
                startCursor
                endCursor
            }
        }
    }
}

query listProducts($first: Int = 50, $after: String, $query: String) {
    products(first: $first, after: $after, query: $query) {
        edges {
            node {
                id
                title
                handle
                vendor
                productType
                status
                createdAt
                updatedAt
                publishedAt
            }
        }
        pageInfo {
            hasNextPage
            hasPreviousPage
            startCursor
            endCursor
        }
    }
}

query getMultipleProductsForCollectionSync($ids: [ID!]!) {
    nodes(ids: $ids) {
        ... on Product {
            id
            collections(first: 250) {
                edges {
                    node {
                        id
                        handle
                    }
                }
            }
            variants(first: 250) {
                edges {
                    node {
                        id
                        position
                    }
                }
            }
        }
    }
}

query getProductCollections($productId: ID!) {
  product(id: $productId) {
    collections(first: 100) {
      edges {
        node {
          id
          handle
        }
      }
      pageInfo {
        hasNextPage
        endCursor
      }
    }
  }
}

query enrichProductData($productId: ID!) {
  product(id: $productId) {
    collections(first: 100) {
      edges {
        node {
          id
          handle
        }
      }
      pageInfo {
        hasNextPage
        endCursor
      }
    }
    images(first: 250) {
      edges {
        node {
          id
          url
          altText
          height
          width
        }
      }
    }
    media(first: 250) {
      edges {
        node {
          id
          ... on MediaImage {
            alt
            status
            image {
              url
              width
              height
            }
            originalSource {
              url
            }
          }
        }
      }
    }
    variants(first: 250) {
      edges {
        node {
          id
          image {
            id
            url
            altText
            height
            width
          }
        }
      }
    }
  }
}

# COLLECTIONS

query getCollection($id: ID!) {
    collection(id: $id) {
        id
        handle
        title
        description
        updatedAt
        products(first: 250) {
            edges {
                node {
                    id
                    title
                    handle
                }
            }
            pageInfo {
                hasNextPage
                hasPreviousPage
                startCursor
                endCursor
            }
        }
    }
}

query getCollectionBasic($id: ID!) {
    collection(id: $id) {
        id
        handle
        title
        description
        updatedAt
    }
}

query listCollections($first: Int = 50, $after: String, $query: String) {
    collections(first: $first, after: $after, query: $query) {
        edges {
            node {
                id
                handle
                title
                description
                updatedAt
            }
        }
        pageInfo {
            hasNextPage
            hasPreviousPage
            startCursor
            endCursor
        }
    }
}

query getCollectionProducts($id: ID!, $first: Int = 250, $after: String) {
    collection(id: $id) {
        id
        handle
        title
        products(first: $first, after: $after) {
            edges {
                node {
                    id
                    title
                    handle
                    vendor
                    productType
                    status
                    createdAt
                    updatedAt
                }
            }
            pageInfo {
                hasNextPage
                hasPreviousPage
                startCursor
                endCursor
            }
        }
    }
}

# METAFIELDS

query getShopMetafield($namespace: String!, $key: String!) {
  shop {
    metafield(namespace: $namespace, key: $key) {
      id
      namespace
      key
      value
      type
      createdAt
      updatedAt
    }
  }
}

# SHOPS

query getShop {
  shop { id }
}

query getShopDetails {
  shop {
    id
    name
    email
    primaryDomain {
      host
    }
    myshopifyDomain
    createdAt
    updatedAt
  }
}

# BULK OPERATIONS

query getBulkOperation($id: ID!) {
  node(id: $id) {
    ... on BulkOperation {
      id
      status
      errorCode
      createdAt
      completedAt
      fileSize
      url
    }
  }
}

# MUTATIONS

mutation createProduct($product: ProductCreateInput!, $media: [CreateMediaInput!]!) {
  productCreate(product: $product, media: $media) {
    product {
      id
      title
      handle
      status
      variants(first: 10) {
        edges {
          node {
            id
            price
            barcode
            createdAt
          }
        }
      }
    }
    userErrors {
      field
      message
    }
  }
}

mutation updateProduct($product: ProductUpdateInput!) {
  productUpdate(product: $product) {
    product {
      id
      title
      handle
      bodyHtml
      vendor
      productType
      tags
      status
      createdAt
      updatedAt
    }
    userErrors {
      field
      message
    }
  }
}

mutation deleteProduct($input: ProductDeleteInput!) {
  productDelete(input: $input) {
    deletedProductId
    userErrors {
      field
      message
    }
  }
}

mutation createProductVariantsBulk($productId: ID!, $variants: [ProductVariantsBulkInput!]!) {
  productVariantsBulkCreate(productId: $productId, variants: $variants) {
    productVariants { id }
    userErrors { field message }
  }
}

mutation updateVariants($productId: ID!, $variants: [ProductVariantsBulkInput!]!) {
  productVariantsBulkUpdate(productId: $productId, variants: $variants) {
    productVariants {
      id
      price
      barcode
      createdAt
    }
    userErrors {
      field
      message
    }
  }
}

# COLLECTION MUTATIONS

mutation createCollection($input: CollectionInput!) {
  collectionCreate(input: $input) {
    collection {
      id
      title
      handle
      updatedAt
    }
    userErrors {
      field
      message
    }
  }
}

mutation updateCollection($input: CollectionInput!) {
  collectionUpdate(input: $input) {
    collection {
      id
      title
      handle
      updatedAt
    }
    userErrors {
      field
      message
    }
  }
}

mutation addProductToCollection($id: ID!, $productIds: [ID!]!) {
  collectionAddProducts(id: $id, productIds: $productIds) {
    collection {
      id
      products(first: 10) {
        edges {
          node { id }
        }
      }
    }
    userErrors { field message }
  }
}

mutation removeProductFromCollection($id: ID!, $productIds: [ID!]!) {
  collectionRemoveProducts(id: $id, productIds: $productIds) {
    job { id }
    userErrors { field message }
  }
}

mutation deleteCollection($input: CollectionDeleteInput!) {
  collectionDelete(input: $input) {
    deletedCollectionId
    userErrors { field message }
  }
}


# METAFIELDS

mutation setMetafield($metafields: [MetafieldsSetInput!]!) {
  metafieldsSet(metafields: $metafields) {
    metafields {
      id
      namespace
      key
      value
      type
      createdAt
      updatedAt
    }
    userErrors {
      field
      message
    }
  }
}

# BULK OPERATIONS

mutation bulkFetchProducts($query: String!) {
  bulkOperationRunQuery(query: $query) {
    bulkOperation {
      id
      status
    }
    userErrors {
      field
      message
    }
  }
}
