I’m testing gql cart mutations and queries with storefront api.
When I tried fetching ‘cost’ field on type ‘CartLine’, I got error message for the query.
It said
"Field 'cost' doesn't exist on type 'CartLine'"
Not only the cost field, there are other fields that make same error such as ‘discountAllocations’ field on ‘Cart.’
Why does this error occur? And how can I fix this problem?
Below is the code I executed:
const variables = {id: cartId, numCartLines: 10};
const input = {query: queries.CART_CREATE_MUTATION, variables};
const response = await fetch("https://thisisneverthat.com/api/graphql", {
method: "post",
headers: {
"Content-Type": "application/json",
"Accept": "application/json",
// https://shopify.dev/api/usage/versioning
"X-Shopify-API-Version": "2023-01",
"X-Shopify-Storefront-Access-Token": STOREFRONT_ACCESS_TOKEN
},
body: JSON.stringify(input)
});
const data = await response.json();
Cart Query:
const CART_QUERY = `
query CartInfo($id: ID!, $numCartLines: Int=250) {
cart(id: $id) {
id
totalQuantity
discountAllocations {
discountedAmount {
amount
currencyCode
}
}
discountCodes {
applicable
code
}
lines(first: $numCartLines) {
edges {
node {
id
quantity
cost {
totalAmount {
amount
currencyCode
}
}
}
}
}
}
}
`;
Error message:
{
errors: [
{
message: "Field 'totalQuantity' doesn't exist on type 'Cart'",
locations: [Array],
path: [Array],
extensions: [Object]
},
{
message: "Field 'discountAllocations' doesn't exist on type 'Cart'",
locations: [Array],
path: [Array],
extensions: [Object]
},
{
message: "Field 'cost' doesn't exist on type 'CartLine'",
locations: [Array],
path: [Array],
extensions: [Object]
}
]
}