[DOCS] How to generate automatic typescript types from your graphql schema. [Hasura] #2290
nirmaanlabs
started this conversation in
General
Replies: 2 comments
-
Hey @nirmaanlabs, thank you for the issue. I think this will be a great guide! Would you like to add it yourself to our Guides & Concepts section in the docs? If you want, here's a guide that you can follow to start with https://refine.dev/docs/contributing/#starting-documentation-in-watch-mode 🙏 |
Beta Was this translation helpful? Give feedback.
0 replies
-
@aliemir I am pulled into different things right now. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Is this issue related to an existing part of the documentation? If so, please provide a link
I am not sure about this
Describe the thing to improve
A clear and concise description of problems.
If you are using Hasura as backend service, you may want to generate typescript types for your queries/mutation and use them with refine.
Step 1. Export graphql schema file from hasura. You can follow this guide
I will use apollo's new
rover cli
. Install apollo rover cli using following commandnpm install --save-dev @apollo/rover
Generate Graphql schema using the following command.
npx rover graph introspect http://localhost:8080/v1/graphql -H "X-Hasura-Admin-Secret:adminsecretkey" | out-file schema.graphql -encoding utf8
If you are curious about the
-encoding utf8
flag read hereStep 2. Generate typescript types from
schema.graphql
fileCreate a file
codegen.yml
in the same level where yourpackage json
existInstall required packages using following command
npm i -D @graphql-codegen/cli @graphql-codegen/typed-document-node @graphql-codegen/typescript @graphql-codegen/typescript-operations
My
devDependencies
tree look like this nowAdd
codegen
script cmd inpackage.json
to generate typesNow run
npm run codegen
and and new filegenerated.ts
will be created insidesrc
directoryThis video explain more about automatic types from graphql schema
related #1713
Beta Was this translation helpful? Give feedback.
All reactions