@toptal/davinci-graphql-codegen 0.1.1-alpha-feature-comm-620-graphql-codegen.1420 → 0.1.1-alpha-feature-comm-620-graphql-codegen.1441

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,73 +1,68 @@
1
- # 🛠 Generating Operation Types
1
+ # ⚛ GraphQL Codegen
2
2
 
3
- In order to generate operation types for your GraphQL Gateway, you'd need to add this library as a dependency on your app/host/lib and the GraphQL schemas lib dependency too:
3
+ 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).
4
4
 
5
- ```
6
- yarn workspace @toptal/modularity-template-my-lib add @toptal/modularity-template-codegen@0.0.1 @toptal/modularity-template-graphql@0.0.1 @graphql-typed-document-node/core
7
- ```
5
+ # 🛠 Generating Schema Types
8
6
 
9
- _PS: Note that we specify the package version, otherwise, yarn will throw you an error saying that it cannot find the module._
7
+ 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 following<sup>1</sup>:
10
8
 
11
- Then add this `script` to your `package.json`.
12
-
13
- `libs/my-lib/package.json`
14
- ```
15
- "codegen:operations": "codegen generate:operations"
9
+ ```json
10
+ [
11
+ {
12
+ "schema": "gs://gqlgw-introspection/staging_talent_schema.graphql",
13
+ "target": "talent"
14
+ },
15
+ {
16
+ "schema": "gs://gqlgw-introspection/staging_staff_schema.graphql",
17
+ "target": "staff"
18
+ },
19
+ {
20
+ "schema": "gs://gqlgw-introspection/staging_lens_schema.graphql",
21
+ "target": "lens"
22
+ }
23
+ ]
16
24
  ```
17
25
 
18
- Then create a `codegen.json` file at the root folder of your package that contains the following data/structure:
26
+ The array contains many objects with the following shape:
19
27
 
20
- ```json
28
+ ```ts
21
29
  {
22
- "schema": "@toptal/modularity-template-graphql/talent",
23
- "documents": "src/**/*.gql"
30
+ schema: string
31
+ target: string
24
32
  }
25
33
  ```
26
34
 
27
- This `schema` property in the `codegen.json` file is where this utility is going to go fetch your schema to download it, parse it and then generate the appropriate typescript types for all your GraphQL operations. In this example we're telling the utility to fetch the schema from `@toptal/modularity-tempalte-graphql` which is the dependency that we have just installed and also telling it that the `schema` we would like to use is the `talent` schema. This is because we store our schemas within `lib/graphl` like so:
35
+ 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.
28
36
 
29
37
  ![Captura de pantalla 2021-10-11 a las 11 03 00](https://user-images.githubusercontent.com/9496960/136763291-7ab3f50e-17e0-4fc8-a4b5-965cc15ac0fd.png)
30
38
 
31
- `@toptal/modularity-template-graphql` will internally resolve to `lib/graphql`, this is a more convenient and comfortable way of working with the `lib/graphql` package and won't break implementations.
39
+ _<sup>1</sup> *This structure might be subject to change in a future iteration of this project*_
32
40
 
33
- **â„šī¸ Heads-up:** 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.
41
+ 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`:
34
42
 
35
- # 🛠 Generating Schema Types
43
+ ```
44
+ "generate-schema": "davinci graphql-codegen generate-schema"
45
+ ```
36
46
 
37
- In order to generate schema types for your GraphQL Gateway, you'd have to go to `lib/graphql` and modify the `codegen.json`. This file contains a structure like the following<sup>1</sup>:
47
+ 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.
48
+
49
+ # 🛠 Generating Operation Types
50
+
51
+ In order to generate operation types for your GraphQL Gateway, you'd need to add this `script` to your `package.json`.
38
52
 
39
- ```json
40
- [
41
- {
42
- "schema": "https://staging.toptal.net/gateway/graphql/talent/graphql",
43
- "target": "talent"
44
- },
45
- {
46
- "schema": "https://staging.toptal.net/gateway/graphql/gateway/graphql",
47
- "target": "gateway"
48
- },
49
- {
50
- "schema": "https://staging.toptal.net/gateway/graphql/lens/graphql",
51
- "target": "lens"
52
- },
53
- {
54
- "schema": "https://staging.toptal.net/gateway/graphql/chronicles/graphql",
55
- "target": "chronicles"
56
- },
57
- {
58
- "schema": "https://staging.toptal.net/gateway/graphql/staff/graphql",
59
- "target": "staff"
60
- }
61
- ]
53
+ ```
54
+ "generate-operations": "davinci graphql-codegen generate-operations"
62
55
  ```
63
56
 
64
- The array contains many objects with the following shape:
57
+ Then create a `codegen.json` file at the root folder of your package that contains the following data/structure:
65
58
 
66
- ```ts
67
- schema: string;
68
- target: string;
59
+ ```json
60
+ {
61
+ "schema": "@toptal/modularity-template-graphql/talent",
62
+ "documents": "src/**/*.gql"
63
+ }
69
64
  ```
70
65
 
71
- The `schema` property will point to the URL where the schema will be fetched from. The `target` property will indicate where the schema is going to be store. As per the example above, your should name it the same way as your gateway, for instance: the talent gateway would have a target of "talent". Later on, as you have already read on the "Generate Operation Types" section, you'd use this target to retrieve the schemas from like so: `@toptal/modularity-template-graphql/talent`.
66
+ 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.
72
67
 
73
- _<sup>1</sup> *This structure might be subject to change in a future iteration of this project*_
68
+ 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.
@@ -16,8 +16,8 @@ Commands:
16
16
 
17
17
  help [command...] Provides help for a given command
18
18
  exit Exits application
19
- generate:operations generate graphql operation types based off generated schemas
20
- generate:schema generate graphql schemas
19
+ generate-operations generate graphql operation types based off generated schemas
20
+ generate-schema generate graphql schemas
21
21
  `
22
22
  )
23
23
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@toptal/davinci-graphql-codegen",
3
- "version": "0.1.1-alpha-feature-comm-620-graphql-codegen.1420+772235c2",
3
+ "version": "0.1.1-alpha-feature-comm-620-graphql-codegen.1441+6a5ae6bf",
4
4
  "description": "Codegen",
5
5
  "author": "Toptal",
6
6
  "license": "ISC",
@@ -28,9 +28,9 @@
28
28
  "@graphql-codegen/typescript-operations": "^2.1.4",
29
29
  "@graphql-codegen/typescript-resolvers": "^2.2.1",
30
30
  "@graphql-typed-document-node/core": "^3.1.0",
31
- "@toptal/davinci-cli-shared": "1.5.1-alpha-feature-comm-620-graphql-codegen.83+772235c2",
31
+ "@toptal/davinci-cli-shared": "1.5.1-alpha-feature-comm-620-graphql-codegen.87+6a5ae6bf",
32
32
  "chalk": "^4.1.2",
33
33
  "graphql": "^15.7.1"
34
34
  },
35
- "gitHead": "772235c2a3e93c6d06cd233dc7c77a532831c83e"
35
+ "gitHead": "6a5ae6bf6d03c85803bd8892e2ee922df3f4f337"
36
36
  }
@@ -10,7 +10,7 @@ async function codegenGenerateOperations() {
10
10
  const codegen = await readConfig()
11
11
 
12
12
  switch (operation) {
13
- case 'generate:operations':
13
+ case 'generate-operations':
14
14
  for await (const { schema, documents } of codegen) {
15
15
  await generateOperations({
16
16
  schema,
@@ -24,7 +24,7 @@ async function codegenGenerateOperations() {
24
24
  }
25
25
 
26
26
  const codegenGenerateOperationsCreator = {
27
- command: 'generate:operations',
27
+ command: 'generate-operations',
28
28
  description: 'generate graphql operation types based off generated schemas',
29
29
  action: () => {
30
30
  codegenGenerateOperations()
@@ -11,7 +11,7 @@ async function codegenGenerateSchema() {
11
11
  const codegen = await readConfig()
12
12
 
13
13
  switch (operation) {
14
- case 'generate:schema': {
14
+ case 'generate-schema': {
15
15
  for await (const { schema, documents, target } of codegen) {
16
16
  await generateSchema({
17
17
  schema,
@@ -28,7 +28,7 @@ async function codegenGenerateSchema() {
28
28
  }
29
29
 
30
30
  const codegenGenerateSchemaCreator = {
31
- command: 'generate:schema',
31
+ command: 'generate-schema',
32
32
  description: 'generate graphql schemas',
33
33
  action: () => {
34
34
  codegenGenerateSchema()