4.1.0 • Published 2 months ago

@toptal/davinci-graphql-codegen v4.1.0

Weekly downloads
-
License
SEE LICENSE IN LI...
Repository
-
Last release
2 months ago

⚛ GraphQL Codegen

GraphQL Codegen is a library developed by Toptal with the idea in mind of improving DX when generating types for your application. Easy to configure (almost no-config) and extend, and easy to import and use. With this library you'd be able to generate types for all your schemas without worring much about implementation details, and if you need to customize or use a specific plugin to suit your needs, it would be piece of cake just by adding the plugin name to the config (package specific or global).

🛠 Generating Schema Types

In order to generate schema types for your GraphQL Gateway the reccomended way is that you create a lib/graphql package in your monorepo and create a codegen.json file were you will store some configuration needed for later usage. This file will contain a structure like the following1:

[
  {
    "schema": "gs://gqlgw-introspection/staging_talent_schema.graphql",
    "target": "talent"
  },
  {
    "schema": "gs://gqlgw-introspection/staging_staff_schema.graphql",
    "target": "staff"
  },
  {
    "schema": "gs://gqlgw-introspection/staging_lens_schema.graphql",
    "target": "lens"
  }
]

The array contains many objects with the following shape:

{
  schema: string
  target: string
}

The schema property will point to a protocol (https:// or gs://) or a relative path where the schema will be fetched from. The target property will indicate where the schema is going to be stored.

Captura de pantalla 2021-10-11 a las 11 03 00

1 This structure might be subject to change in a future iteration of this project

After creating the package and applying the default configurations you should add Davinci as a dependency of @toptal/modularity-template-graphql (it's how we name this package within our monorepo to resolve to libs/graphql) and add this script to your package.json:

"generate-schema": "davinci graphql-codegen generate-schema"

When you run the above command, it will iterate over the schemas you have configured in your codegen.json and then create those schemas locally for you to commit to your repo, and then make use of them for generating operation types.

🛠 Generating Operation Types

In order to generate operation types for your GraphQL Gateway, you'd need to add this script to your package.json.

"generate-operations": "davinci graphql-codegen generate-operations"

Then create a codegen.json file at the root folder of your package that contains the following data/structure:

{
  "schema": "@toptal/modularity-template-graphql/talent",
  "documents": "src/**/*.gql"
}

The schema property in the codegen.json file is where this utility is going to go search for your schema, parse it and then generate the appropriate typescript types for all your GraphQL operations. In this example we're telling the utility to use the schema located at @toptal/modularity-tempalte-graphql, which is the package were we will store our schemas. In this example, @toptal/modularity-template-graphql/talent will resolve to libs/graphql/talent, but it can be any package were you'd like to store your schemas at.

The documents property is a glob pattern that tells this utility where your GraphQL operations are located. Please note that this glob pattern does not start with ./ as we use process.env.INIT_CWD to resolve where this utility was launched from and therefore, using ./src/**/*.gql will break the implementation and won't be able to resolve your files.

4.1.0

4 months ago

3.1.0

9 months ago

2.1.0

9 months ago

3.3.0

9 months ago

3.2.0

9 months ago

4.0.5

6 months ago

4.0.4

6 months ago

4.0.7

6 months ago

4.0.6

6 months ago

4.0.1

7 months ago

4.0.0

7 months ago

4.0.3

6 months ago

4.0.2

7 months ago

4.0.8

6 months ago

3.0.0

9 months ago

3.4.0

9 months ago

3.4.3

8 months ago

3.4.2

8 months ago

3.4.1

8 months ago

3.4.6

7 months ago

3.4.5

8 months ago

2.0.2

10 months ago

2.0.1

10 months ago

2.0.0

11 months ago

1.2.5

12 months ago

1.2.4

12 months ago

1.2.3

12 months ago

1.2.2

12 months ago

1.1.4

1 year ago

1.2.0

1 year ago

1.2.1

1 year ago

1.1.1

1 year ago

1.1.0

1 year ago

1.1.3

1 year ago

1.1.2

1 year ago

1.0.10

1 year ago

1.0.9

1 year ago

1.0.8

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

0.2.24

1 year ago

0.2.23

1 year ago

0.2.22

1 year ago

0.3.0

1 year ago

0.3.1

1 year ago

0.4.1

1 year ago

0.4.0

1 year ago

0.4.2

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago

1.0.3

1 year ago

0.2.21

1 year ago

0.2.20

2 years ago

0.2.19

2 years ago

0.2.18

2 years ago

0.2.17

2 years ago

0.2.16

2 years ago

0.2.15

2 years ago

0.2.14

2 years ago

0.2.13

2 years ago

0.2.12

2 years ago

0.2.11

2 years ago

0.2.10

2 years ago

0.2.7

2 years ago

0.2.6

2 years ago

0.2.9

2 years ago

0.2.8

2 years ago

0.2.5

2 years ago

0.2.4

2 years ago

0.2.1

2 years ago

0.2.3

2 years ago

0.2.2

2 years ago

0.2.0

2 years ago

0.1.1

2 years ago