Created
May 13, 2025 00:14
-
-
Save 0xameer/33c25936b8c5b53144f8e7f54e189a16 to your computer and use it in GitHub Desktop.
hasura-ecomm-app-deploy-rest-end-points.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| 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