Skip to content

Latest commit

 

History

History
38 lines (26 loc) · 2.43 KB

File metadata and controls

38 lines (26 loc) · 2.43 KB

Linear Codegen Test

This custom graphql-code-generator plugin takes the Linear GraphQL GraphQL fragments and operations, generated by the Linear Codegen Document, and outputs a typed jest test. This aims to tests exposes all GraphQL models and operations available on the introspection query.

Usage must contain a neighbouring test-client file to expose two functions:

  • startClient to optionally start a mock GraphQL server, used in the beforeAll hook
  • stopClient to optionally stop a mock GraphQL server, used in the afterAll hook

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.test.yml.

Output

The @linear/sdk uses this code generator plugin to generate:

A describe block for each root query, that returns a model that is not an item of a collection, containing:

  • a test to return the model, asserting the return type
  • a test for each nested query on the model, or first item in a collection, asserting the return type

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 tests
  5. The printed tests are returned to be printed

License


Licensed under the MIT License.