Sanity GraphQL code generator starter
This starter has all the setup needed to generate code from your GraphQL queries.
README
Features
A Next.js starter project with Sanity and GraphQL/Typescript code generation.
- GraphQL code generation with Typescript integration.
- VSCode auto-complete for GraphQL queries.
- Embedded studio on /studio route.
Note: This setup can easily be installed on Remix or any other framework.
Getting Started
1 - create a .env file on the root folder.
#.env
NEXT_PUBLIC_SANITY_PROJECT_ID=projectId
NEXT_PUBLIC_SANITY_DATASET=production2 - Deploy GraphQL api
npm run graphql-deploy
3 - Start the development server:
npm run dev4 - Add some content:
Open http://localhost:3000/studio and publish a few blog posts.
5 - See the result
Notes
All the queries are being placed on the queries.graphql file. If you prefer to use tags on typescript files, you will have to edit graphql.config.ts and codegen.ts.
Troubleshoot
Make sure to restart the VSCode GraphQL process whenever you deploy schema changes!

Need some help?
Look for Gustavo Bremm on Sanity Slack.