This custom graphql-code-generator plugin takes the Linear GraphQL GraphQL fragments and operations, generated by the Linear Codegen Document, and outputs a typed Linear SDK. This exposes all GraphQL models and operations available on the introspection query.
It requires that GraphQL types-document-nodes have been generated and linked to this plugin using the codegen config documentFile property, using the plugins:
- @graphql-codegen/typescript
- @graphql-codegen/typescript-operations
- @graphql-codegen/typed-document-node
Usage in codegen.sdk.yml.
The @linear/sdk uses this code generator plugin to generate:
A model class for each model in the Linear API, initialized by the response fragment, and containing:
- all scalar fields on the model
- private required fields for any nested object with a matching query
- public getters, using the private required fields, for requesting any nested object with query
- public properties for any nested objects with no matching query
- connection helpers if the model matches the Relay connection shape
An operation class for each query and mutation in the Linear API, containing a fetch function which:
- accepts all required variables as args
- accepts all optional variables as a final object arg
- calls the
LinearGraphQLClient.requestfunction to return the model from the production Linear API - constructs the model and returns
An operation class for each nested query within a model, containing a fetch function which:
- uses the parent variables defined by the constructor scope
- accepts all required variables for the child query as args
- accepts all optional variables for the child query as a final object arg
- calls the
LinearGraphQLClient.requestfunction to return the model from the production Linear API - constructs the model and returns
An SDK class containing a public getter for each root query and mutation which:
- accepts all required variables as args
- accepts all optional variables as a final object arg
- creates the operation class
- calls the
fetchfunction and returns
- The GraphQL schema is parsed using a reusable ContextVisitor to provide consistent information across the Linear code generator plugins
- The context is visited using the ModelVisitor to return a list of parsed Linear models
- The models and context are parsed to return a map of all operations for each nested resource
- The parsed models, operations and context are used to print models, operations and the sdk
- The printed models, operations and sdk are returned to be printed
Licensed under the MIT License.