@toptal/davinci-graphql-codegen 3.3.1-alpha-FX-NULL-fix-lockflie-294b78dc.0 → 3.4.0

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/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # @toptal/davinci-graphql-codegen
2
2
 
3
+ ## 3.4.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#2093](https://github.com/toptal/davinci/pull/2093) [`63d9c99f`](https://github.com/toptal/davinci/commit/63d9c99f657ca2be1d2f21f24f6288500699fcf5) Thanks [@sashuk](https://github.com/sashuk)!
8
+ - add ability to configure schema generation
9
+
3
10
  ## 3.3.0
4
11
 
5
12
  ### Minor Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@toptal/davinci-graphql-codegen",
3
- "version": "3.3.1-alpha-FX-NULL-fix-lockflie-294b78dc.0+294b78dc",
3
+ "version": "3.4.0",
4
4
  "description": "Codegen",
5
5
  "author": "Toptal",
6
6
  "license": "SEE LICENSE IN LICENSE.MD",
@@ -39,9 +39,9 @@
39
39
  "@graphql-tools/load": "^7.8.14",
40
40
  "@graphql-tools/schema": "^9.0.19",
41
41
  "@graphql-typed-document-node/core": "^3.2.0",
42
- "@toptal/davinci-cli-shared": "2.3.3-alpha-FX-NULL-fix-lockflie-294b78dc.40+294b78dc",
43
- "@toptal/davinci-graphql-codegen-extensions": "1.0.4-alpha-FX-NULL-fix-lockflie-294b78dc.25+294b78dc",
44
- "@toptal/davinci-monorepo": "8.2.3-alpha-FX-NULL-fix-lockflie-294b78dc.40+294b78dc",
42
+ "@toptal/davinci-cli-shared": "^2.3.2",
43
+ "@toptal/davinci-graphql-codegen-extensions": "1.0.3",
44
+ "@toptal/davinci-monorepo": "8.2.2",
45
45
  "babel-plugin-extract-export": "^0.1.0",
46
46
  "chalk": "^4.1.2",
47
47
  "deepmerge": "^4.2.2",
@@ -57,6 +57,5 @@
57
57
  "@jest/globals": "^29.4.2",
58
58
  "graphql": "^16",
59
59
  "prettier": "^2.6.2"
60
- },
61
- "gitHead": "294b78dc4ea443d76798f506debf6d0e085b2de4"
60
+ }
62
61
  }
@@ -3,7 +3,7 @@
3
3
  exports[`generateSchema generates graphql schemas 1`] = `
4
4
  "{
5
5
  "_events": {},
6
- "_eventsCount": 2,
6
+ "_eventsCount": 3,
7
7
  "commands": [],
8
8
  "options": [
9
9
  {
@@ -32,6 +32,20 @@ exports[`generateSchema generates graphql schemas 1`] = `
32
32
  "negate": false,
33
33
  "hidden": false,
34
34
  "conflictsWith": []
35
+ },
36
+ {
37
+ "flags": "-v, --verbose",
38
+ "description": "Turns on the verbose mode",
39
+ "required": false,
40
+ "optional": false,
41
+ "variadic": false,
42
+ "mandatory": false,
43
+ "short": "-v",
44
+ "long": "--verbose",
45
+ "negate": false,
46
+ "defaultValue": false,
47
+ "hidden": false,
48
+ "conflictsWith": []
35
49
  }
36
50
  ],
37
51
  "parent": null,
@@ -44,10 +58,12 @@ exports[`generateSchema generates graphql schemas 1`] = `
44
58
  "_scriptPath": null,
45
59
  "_name": "generate-schema",
46
60
  "_optionValues": {
47
- "projectId": "toptal-hub"
61
+ "projectId": "toptal-hub",
62
+ "verbose": false
48
63
  },
49
64
  "_optionValueSources": {
50
- "projectId": "default"
65
+ "projectId": "default",
66
+ "verbose": "default"
51
67
  },
52
68
  "_storeOptionsAsProperties": false,
53
69
  "_executableHandler": false,
@@ -4,18 +4,26 @@ import { generateSchema } from '../generate/index.js'
4
4
  import readConfig from '../read-config/index.js'
5
5
  import { getConfigurationType } from '../services/get-configutation-type.js'
6
6
 
7
- const codegenGenerateSchema = async ({ projectId, config }) => {
7
+ const codegenGenerateSchema = async ({ projectId, config, verbose }) => {
8
+ process.env.VERBOSE = verbose
9
+
8
10
  const codegenConfigurations = await readConfig(config)
9
11
 
10
12
  for (const codegenConfiguration of codegenConfigurations) {
11
13
  if (getConfigurationType(codegenConfiguration) === 'schema') {
12
- const { schema, documents, target } = codegenConfiguration
14
+ const {
15
+ schema,
16
+ documents,
17
+ target,
18
+ config: customConfig,
19
+ } = codegenConfiguration
13
20
 
14
21
  await generateSchema({
15
22
  schema,
16
23
  documents,
17
24
  target,
18
25
  projectId,
26
+ config: customConfig,
19
27
  })
20
28
  } else {
21
29
  console.log(
@@ -40,4 +48,5 @@ export const createGenerateSchemaCommand = program =>
40
48
  '-c, --config <path>',
41
49
  `Path to your custom ${chalk.green('codegen.json')} config file`
42
50
  )
51
+ .option('-v, --verbose', 'Turns on the verbose mode', false)
43
52
  .action(codegenGenerateSchema)
@@ -18,6 +18,7 @@ const generateSchema = async ({
18
18
  schema: originalSchema,
19
19
  target,
20
20
  projectId,
21
+ config,
21
22
  }) => {
22
23
  const { schema, destination } = await schemaLoader(
23
24
  castArray(originalSchema),
@@ -27,56 +28,62 @@ const generateSchema = async ({
27
28
 
28
29
  console.log(`ℹ️ Generating [${chalk.green(target)}] schema`)
29
30
 
30
- await generate(
31
- {
32
- schema: schema,
33
- generates: {
34
- [destination]: {
35
- schema:
36
- schema instanceof URL
37
- ? String(schema)
38
- : {
39
- [localRequire.resolve(schema)]: {
40
- loader: localRequire.resolve(
41
- '@toptal/davinci-graphql-codegen-extensions/schema-loader'
42
- ),
43
- },
31
+ const gqlConfiguration = {
32
+ schema: schema,
33
+ generates: {
34
+ [destination]: {
35
+ schema:
36
+ schema instanceof URL
37
+ ? String(schema)
38
+ : {
39
+ [localRequire.resolve(schema)]: {
40
+ loader: localRequire.resolve(
41
+ '@toptal/davinci-graphql-codegen-extensions/schema-loader'
42
+ ),
44
43
  },
45
- plugins: [
46
- 'typescript',
47
- 'typescript-resolvers',
48
- '@toptal/davinci-graphql-codegen-extensions/enums-plugin',
49
- {
50
- add: {
51
- content: autoGenerationComments,
52
44
  },
45
+ plugins: [
46
+ 'typescript',
47
+ 'typescript-resolvers',
48
+ '@toptal/davinci-graphql-codegen-extensions/enums-plugin',
49
+ {
50
+ add: {
51
+ content: autoGenerationComments,
53
52
  },
54
- ],
55
- },
56
- },
57
- hooks: {
58
- afterAllFileWrite: [
59
- async (...filePaths) => {
60
- for (const path of filePaths) {
61
- const rawText = readFileSync(path, 'utf8')
62
- const options = await prettier.resolveConfig(dirname(path))
63
-
64
- const formattedText = prettier.format(rawText, {
65
- parser: 'typescript',
66
- ...options,
67
- })
68
-
69
- writeFileSync(path, formattedText)
70
- }
71
53
  },
72
54
  ],
73
- },
74
- config: {
75
- ...commonSchemaTypesConfig,
55
+ config,
76
56
  },
77
57
  },
78
- true
79
- )
58
+ hooks: {
59
+ afterAllFileWrite: [
60
+ async (...filePaths) => {
61
+ for (const path of filePaths) {
62
+ const rawText = readFileSync(path, 'utf8')
63
+ const options = await prettier.resolveConfig(dirname(path))
64
+
65
+ const formattedText = prettier.format(rawText, {
66
+ parser: 'typescript',
67
+ ...options,
68
+ })
69
+
70
+ writeFileSync(path, formattedText)
71
+ }
72
+ },
73
+ ],
74
+ },
75
+ config: {
76
+ ...commonSchemaTypesConfig,
77
+ },
78
+ }
79
+
80
+ if (process.env.VERBOSE) {
81
+ console.log(`ℹ️ GQL configuration:
82
+ ${JSON.stringify(gqlConfiguration, null, 2)}
83
+ `)
84
+ }
85
+
86
+ await generate(gqlConfiguration, true)
80
87
  }
81
88
 
82
89
  export default generateSchema