Generate a SDK for your GraphQL API using GraphQL Codegen.
npm i buro26-graphql-codegen-sdk
Create a codegen.ts file in the root of your project with the following content:
Add a script to your package.json to run the codegen:
{
"scripts": {
"codegen": "graphql-codegen"
}
}
Run the codegen script:
npm run codegen
Create a codegen.ts file in the root of your project with the following content:
import {createConfig} from 'buro26-graphql-codegen-sdk'
export default createConfig({
schema: 'http://localhost:1337/graphql',
documents: 'src/lib/my-api/queries/**/!(*.generated).{ts,tsx}',
typesImportPath: '@/lib/my-api/generated/types',
schemaImportPath: '@/lib/my-api/generated/schema',
types: {
path: 'src/lib/my-api/generated/types.ts'
},
sdl: {
path: './schema.graphql'
},
client: {
path: 'src/lib/my-api/generated/client-factory.ts',
config: {
logger: true
}
},
zod: {
path: 'src/lib/my-api/generated/schema.ts',
config: {
exportFormDataSchema: true,
},
}
})
Add a script to your package.json to run the codegen:
{
"scripts": {
"codegen": "graphql-codegen"
}
}
Run the codegen script:
npm run codegen
On more how to use the generated client, see the buro26-graphql-codegen-client package.
On more how to use the generated zod schema, see the buro26-graphql-codegen-zod package.
To run tests, run the following command:
bun test
Wish to contribute to this project? Pull the project from the repository and create a merge request.
Buro26 - https://buro26.digital
Special thanks to all contributors and the open-source community for their support and contributions.
This project is licensed under the MIT License - see the LICENSE file for details.
The project is currently in active development. We are continuously working on adding new features and improving the existing ones. Check the issues section for the latest updates and planned features.
Feel free to reach out if you have any questions or suggestions!