Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: Field 'presentmentPrices' doesn't exist on type 'ProductVariant' #959

Open
1 of 2 tasks
pratikh2o opened this issue Jul 6, 2023 · 11 comments
Open
1 of 2 tasks

Comments

@pratikh2o
Copy link

pratikh2o commented Jul 6, 2023

Please complete the checklist before filing an issue:

  • Is this a "how to" question? For questions on how to use the SDK, implement features or other related questions, please use our forums.
  • Is this something you can debug and fix? Create a pull request and contribute! Bug fixes and documentation fixes are welcome. You can read our contribution guidelines for more details.

None of the above? Create an issue. Be sure to include all the necessary information for us to understand and reproduce the problem:

Bug details

Describe the bug
Hi, I am encountering an error while using the shopify-js-buy package version 2.9.0 in my app build process.

To Reproduce

  1. Install and use the shopify-js-buy package version 2.9.0 in your application.
  2. Build the application.
9:21:03 AM: ERROR [
9:21:03 AM:   {
9:21:03 AM:     message: Field 'presentmentPrices' doesn't exist on type 'ProductVariant',
9:21:03 AM:     locations: [
9:21:03 AM:       [Object]
9:21:03 AM:     ],
9:21:03 AM:     path: [
9:21:03 AM:       'fragment VariantFragment',
9:21:03 AM:       'presentmentPrices'
9:21:03 AM:     ],
9:21:03 AM:     extensions: {
9:21:03 AM:       code: 'undefinedField',
9:21:03 AM:       typeName: 'ProductVariant',
9:21:03 AM:       fieldName: 'presentmentPrices'
9:21:03 AM:     }
9:21:03 AM:   }
9:21:03 AM: ]

Framework using nuxtjs
Since yesterday, I have been encountering this error.

@darwinshameran
Copy link

We fixed this by upgrading the package.

@letterix
Copy link

letterix commented Jul 6, 2023

I made sure the package resolved to the latest version which made this particular error go away.
Do note that there seem to be differences in types of certain fields; type of all price fields went from a simple string to an object (where .amount was the new index). I'm not sure if this is due to the underlying API changes as we might have been on an older API version.

@MelroyPinto
Copy link

MelroyPinto commented Jul 6, 2023

I am using version 2.11 I'm getting error while I'm trying to fetch the collection. variant price is causing the issue. I see in the generated query two brackets are extra after price. please check the code below and please let me know how to resolve this.
The same code was working fine 2 years ago. But from yesterday its not working. if I comment out the price the code works fine

code :

const collectionQuery = this.client.graphQLClient.query((root) => {
root.addConnection('collections', { args: { first: 25 } }, (collection) => {
collection.add('title');
collection.add('description');
collection.addConnection('products', { args: { first: 200 } }, (product) => {
product.add('title');
product.add('description');
product.add('tags');
product.addConnection('images', { args: { first: 10 } }, (image) => {
image.add('id');
image.add('originalSrc');
});
product.add('metafields', {
args: {
identifiers: [
{ key: 'id', namespace: 'STI' },
{ key: 'pro', namespace: 'STL' },
],
},
}, (meta) => {
meta.add('value');
meta.add('key');
});
product.add('options', (option) => {
option.add('name');
option.add('values');
});
product.addConnection('variants', { args: { first: 50 } }, (variants) => {
variants.add('product');
variants.add('title');
variants.add('availableForSale');
variants.add('quantityAvailable');
variants.add('sku');
variants.add('selectedOptions', (selectedOption) => {
selectedOption.add('name');
selectedOption.add('value');
});
variants.add('price');
});
});
});
});
const { model } = await this.client.graphQLClient.send(collectionQuery);

query generated:

{"query":"query { collections (first: 25) { pageInfo { hasNextPage,hasPreviousPage },edges { cursor,node { id,title,description,products (first: 200) { pageInfo { hasNextPage,hasPreviousPage },edges { cursor,node { id,title,description,tags,images (first: 10) { pageInfo { hasNextPage,hasPreviousPage },edges { cursor,node { id,originalSrc } } },metafields (identifiers: [{key: "stylistId" namespace: "stylist_ids"} {key: "wigProperties" namespace: "STL_properties"}]) { id,value,key },options { id,name,values },variants (first: 50) { pageInfo { hasNextPage,hasPreviousPage },edges { cursor,node { id,product { id },title,availableForSale,quantityAvailable,sku,selectedOptions { name,value },price { } } } } } } } } } } }"}

@JeffJassky
Copy link

The same thing happened to my app yesterday. I have tried updating the package version but am still seeing this issue as well as several others.

Bug details

Describe the bug

When using the Shopify GraphQL API through the SDK, multiple queries are failing that were previously working. Errors received indicate both selectionMismatch and undefinedField issues.

To Reproduce

The error is consistently reproduced when making any queries involving the following fields: 'price', 'compareAtPrice', 'paymentDue', 'totalTax', 'subtotalPrice', 'totalPrice', 'totalShippingPrice', 'totalRefunded', 'presentmentPrices' and 'description'.

An example response from the API is included below, however, due to the formatting constraints, the JSON response is not included in a separate code block:

{
    "errors": [
        {
            "message": "Field must have selections (field 'price' returns MoneyV2 but has no selections. Did you mean 'price { ... }'?)",
            ...
        },
        {
            "message": "Field 'presentmentPrices' doesn't exist on type 'ProductVariant'",
            ...
        },
        ...
    ]
}

Unfortunately, I cannot provide the X-Request-ID as the errors are being handled within the SDK.

Expected behavior

The queries that were previously working should continue to work without any errors. If there were changes in the Shopify GraphQL API that would require updates to these queries, those changes should have been documented in the SDK's release notes or changelog.

Environment (please complete the following information):

  • OS: macOS and Ubuntu
  • Browser Chrome, Firefix, IE, Edge, Etc.
  • SDK Version: tested v2.20.0 (latest), v2.0.1 and several others.

Additional context

The application was working fine until recently. There were no changes made on our end that would have affected these queries. It seems possible that there was a change or update on Shopify's end that caused this issue.

@melissaluu
Copy link
Contributor

melissaluu commented Jul 6, 2023

👋 Each version of JS Buy SDK is directly linked to a Storefront API version and the SDK response will change as the underlying API evolves. As per our Changelog, it notes that there has been a few major changes in Storefront API in the last couple of release - notably API v2022-01 and v2022-10 where presentmentPrice was removed and all pricing fields return a MoneyV2 object instead of the Money scalar within the API. Updates were made in the SDK's predefined queries to address the changes.

An important thing to note is that the support for a JS Buy SDK version is directly linked to the corresponding Storefront API version - if an SDK version is calling an API version that is not supported, the server will respond with the oldest supported API version. For example, using SDK version v2.11.0, the SDK will try to request against Storefront API 2020-07 but the server will respond with Storefront API 2022-10 since it's the oldest supported version.

@melissaluu
Copy link
Contributor

melissaluu commented Jul 6, 2023

Also, if you are using the unoptimized version of the SDK to call custom queries or mutations, please ensure that they adhere to the responding Storefront API version's schema. You can check the X-Shopify-Api-Version response header to know which Storefront API version was used to serve the response.

@JeffJassky
Copy link

JeffJassky commented Jul 6, 2023

Hey @melissaluu and team, Thanks for the response!

So, a quick clarification:

  1. The oldest supported API version recently changed (like within the past week) and no longer supports these queries?
  2. We need to restructure our queries to align with the newer data structures?

If so, two follow up questions:

  1. Is there a standard timeline for API version deprecation, announcements, or notifications for when the oldest supported version changes?
  2. What documentation would be best to reference for migrating our graphql queries to align with new data structures?

Thanks for the help!

@melissaluu
Copy link
Contributor

Hi @JeffJassky,

Glad I can help!

The oldest supported API version recently changed (like within the past week) and no longer supports these queries?

A new version of the Storefront API is released every quarter so we just released v2023-07 and that bumped our oldest supported version to 2022-10. You can see the versions currently supported here. For queries that are expecting the Money scalar, those will need to be updated to query for a MoneyV2 object - changelog.

We need to restructure our queries to align with the newer data structures?

Yes - the Storefront API will continue to evolve and it's a good idea to keep your queries up to date.

Is there a standard timeline for API version deprecation, announcements, or notifications for when the oldest supported version changes?

As per the release schedule, a stable API version is supported for a minimum of 12 months.

What documentation would be best to reference for migrating our graphql queries to align with new data structures?

Our developer changelog, release notes and API docs are good references to help you migrate your queries.

@JeffJassky
Copy link

JeffJassky commented Jul 7, 2023

Thanks again @melissaluu.

So, unfortunately presentmentPrices has been discontinued entirely.

If you're trying to get prices for multiple currencies, it looks like we're supposed to use something called the @incontext directive, which is not currently supported by the js-buy-sdk.

However: there is an open feature request to add support for @incontext directive in #884 and further reference to it in #853

@crimsonhawk47
Copy link

crimsonhawk47 commented Jul 19, 2023

Updates were made in the SDK's predefined queries to address the changes.

Were they? It seems like the version was bumped up but the SDK wasn't updated with it. Types haven't been updated. The type for Cart.price, for instance, is still a string

@melissaluu
Copy link
Contributor

👋 @crimsonhawk47 - which version of the SDK are you using? Can you provide more details on where you're seeing the price string type?

Since SDK v2.17.0, all predefined queries' price related fields have been updated to get the MoneyV2 object. If you are using the unoptimized version of the SDK that's v2.17.0 or newer, the schema.json has also been updated and all price related fields will be the MoneyV2 type.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants