1

I have following mutation from shopify graphql to add a variant to an existing product

Query

mutation UpdateProductMutation ($id: ID!, $options: [String!], $variants: [ProductVariantInput!]) {
  productUpdate(input: {id: $id, options: $options, variants: $variants}) {
    product {
      id,
      title,
      publishedAt,
      options {
        values
      }
      variants(first: 100) {
        edges {
          node {
            id,
            title
          }
        }
      }
    }
    userErrors {
      field,
      message
    }
  }
}

Values

{
    "id": "gid://shopify/Product/5388344426634",
    "options": [
        "size",
        "color"
    ],
    "variants": [
        {
            "options": [
                "xxl",
                "black"
            ]
        }
    ]
}

Response

{
  "data": {
    "productUpdate": {
      "product": {
        "id": "gid:\/\/shopify\/Product\/5388344426634",
        "title": "hello-kitty123s",
        "publishedAt": null,
        "options": [
          {
            "values": [
              "xxl"
            ]
          },
          {
            "values": [
              "black"
            ]
          }
        ],
        "variants": {
          "edges": [
            {
              "node": {
                "id": "gid:\/\/shopify\/ProductVariant\/34937293373578",
                "title": "xxl \/ black"
              }
            }
          ]
        }
      },
      "userErrors": []
    }
  },
  "extensions": {
    "cost": {
      "requestedQueryCost": 113,
      "actualQueryCost": 14,
      "throttleStatus": {
        "maximumAvailable": 1000.0,
        "currentlyAvailable": 986,
        "restoreRate": 50.0
      }
    }
  }
}

Is there a way I can get ONLY newly created product variant in the response without having to paginate of the variants or passing a a really huge number in the query i.e variants(first: 100)

java_doctor_101
  • 3,287
  • 4
  • 46
  • 78

0 Answers0