Skip to content
This repository was archived by the owner on Nov 20, 2023. It is now read-only.
This repository was archived by the owner on Nov 20, 2023. It is now read-only.

variantBySelectedOptions field doesn't exist on Product #131

Open

Description

@jibinycricket

Has this field been deprecated? I see it in the docs but it isn't found when I run the query below

Documentation
https://shopify.dev/docs/storefront-api/reference/products/product?api%5Bversion%5D=2021-01#fields-2021-01
image

query

{
  node(id: "Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0LzYxOTc2OTU1NzgyOTk=") {
    ... on Product {
      id
      variantBySelectedOptions(selectedOptions: [{name: "Size", value: "Full/Queen"}, {name: "Color", value: "Sienna"}])
    }
  }
}

response

{
  "errors": [
    {
      "message": "Field 'variantBySelectedOptions' doesn't exist on type 'Product'",
      "locations": [
        {
          "line": 5,
          "column": 7
        }
      ],
      "path": [
        "query",
        "node",
        "... on Product",
        "variantBySelectedOptions"
      ],
      "extensions": {
        "code": "undefinedField",
        "typeName": "Product",
        "fieldName": "variantBySelectedOptions"
      }
    }
  ]
}

Activity

  1. swalkinshaw commented on Feb 26, 2021

    @swalkinshaw
    Collaborator

    It definitely still exists.

    🤔 are you sure you're using the Storefront API and not the Admin API? Only easy explanation I could think of

  2. jibinycricket commented on Feb 26, 2021

    @jibinycricket
    Author

    Sorry. That was exactly the issue. I was using the Shopify GraphiQL App, but I didn't realize it only used the Admin API.

    Also here is an issue I noticed, that I want to just document in case its helpful for anyone in the future. When using JSON.stringify, the method applies quotes to both the key and the value causing the string to look like '[{"name": "Size", "value": "King/Cal King" }]', this for some reason causes a parsing error in the request, so you have to strip the quotes out of the keys in order for it to look like this '[{name: "Size", value: "King/Cal King" }]';

    My query looked like this

      let selectedOptionParams = [
        { name: "Size", value: "King/Cal King" }
      ];
    
      selectedOptionParams = JSON.stringify(selectedOptionParams).replace(/"(\w+)"\s*:/g, '$1:');
    
      this.api.post('/',{
        query: `{
          productByHandle(handle:"${productHandle}") {
            variantBySelectedOptions(selectedOptions:${selectedOptionParams}) {
              id
            }
          }
        }`,
      }).then(res => {
        console.debug(res.data);
      })    
    

    If there's a better way to stringify the object please let me know

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions