GraphQL Codegen
We are using GraphQL Code generator to generate typings from the GraphQL API automatically.
Configuration
create Codegen.yml file for the configuration in each project folder.
Codegen.yml
overwrite: true
schema: "https://api.staging.cella.cloud/graphql"
documents: "**/**/*.graphql"
generates:
generated/graphql.ts:
plugins:
- "typescript"
- "typescript-operations"
- "typescript-react-query"
config:
fetcher: graphql-request
For local env development, you can set schema as localhost schema url.
Schema
Put your GraphQL file in GraphQL folder in each project(Web/Mobile)
For Example:
user.graphql - User schema
query GetMyInfo {
me {
username
password
organizationId
roleId
organization {
name
id
awsAccessKeyId
awsSecretAccessKey
parentOrganizationId
}
role {
name
id
permissions {
table
mode
roleId
id
}
}
id
email
}
}
Run codegen
You need to add script for codegen in package.json file.
{
"scripts": {
"gen": "graphql-codegen --config codegen.yml"
}
}
Running yarn gen command will generate graphql ts file in generated/graphql.ts