Hi, apologies if this has already been asked. Does anyone know of a way to leverage Typescript to constrain the shape/selection set of a query? Say you’re writing a function that receives QueryOptions as an argument, and the function executes the query specified by QueryOptions.query.
Let’s say the function is expecting a query with this shape:
Now suppose we pass the function a query that is missing pageInfo in the selection set, or that aliases edges. Is there any way to have Typescript catch this, or would you have to provide your own validation of the query DocumentNode?
Using this config, generated code will be placed into src/generated and graphql.schema.json is in main directory.
Then you need script in package.json
"codegen": "graphql-codegen --config codegen.yml"
That’s it. You need to make sure that graphql server is responding correctly on http://localhost:4000
Then run the script. It will call the server, pull out config and generate typings for you. You will get types for your data, resolvers, everything.