I’m trying to use Shopify Graphql to create a custom basket with cartCreate Which is new and accessible on the 2020-10 endpoint:
https:// { shop } .myshopify.com/api/2020-10/graphql.json
This is my full code :
import Cookies from "js-cookie";
import { GraphQLClient, gql } from "graphql-request";
async function shopifyRequest() {
const graphQLClient = new GraphQLClient(
"https://jamiegalbreath.myshopify.com/api/2020-10/graphql.json",
{
headers: {
"Content-Type": "application/json",
"X-Shopify-Storefront-Access-Token":
process.env.REACT_APP_SHOPIFY_STOREFRONT_ACCESS_TOKEN,
},
}
);
const mutation = gql`
mutation {
cartCreate {
cart {
id
}
userErrors {
code
field
message
}
}
}
`;
const variables = {};
const data = await graphQLClient.request(mutation, variables);
}
export async function test() {
await shopifyRequest()
.then(() => {
console.log("DONE");
})
.catch((error) => console.error(error));
}
When the function returns I get an error: Field ‘cartCreate’ doesn’t exist on type ‘Mutation’
I am working on : Choice Hotels