Skip to content

Latest commit

 

History

History
56 lines (42 loc) · 3.35 KB

File metadata and controls

56 lines (42 loc) · 3.35 KB

Linear Codegen SDK

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:

Usage in codegen.sdk.yml.

Output

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.request function 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.request function 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 fetch function and returns

Flow

  1. The GraphQL schema is parsed using a reusable ContextVisitor to provide consistent information across the Linear code generator plugins
  2. The context is visited using the ModelVisitor to return a list of parsed Linear models
  3. The models and context are parsed to return a map of all operations for each nested resource
  4. The parsed models, operations and context are used to print models, operations and the sdk
  5. The printed models, operations and sdk are returned to be printed

License


Licensed under the MIT License.