Skip to content

Instantly share code, notes, and snippets.

@0xameer
Created May 13, 2025 00:14
Show Gist options
  • Select an option

  • Save 0xameer/33c25936b8c5b53144f8e7f54e189a16 to your computer and use it in GitHub Desktop.

Select an option

Save 0xameer/33c25936b8c5b53144f8e7f54e189a16 to your computer and use it in GitHub Desktop.
hasura-ecomm-app-deploy-rest-end-points.ts
/*
This is an example snippet - you should consider tailoring it
to your service.
Note: we only handle the first operation here
*/
function fetchGraphQL(
operationsDoc: string,
operationName: string,
variables: Record<string, any>
) {
return fetch('undefined', {
method: 'POST',
body: JSON.stringify({
query: operationsDoc,
variables,
operationName,
}),
}).then(result => result.json());
}
const operation = `
query MyQuery @cached {
node(id: "")
}
`;
function fetchMyQuery() {
return fetchGraphQL(operations, MyQuery, {})
}
fetchMyQuery()
.then(({ data, errors }) => {
if (errors) {
console.error(errors);
}
console.log(data);
})
.catch(error => {
console.error(error);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment