@toptal/davinci-graphql-codegen 0.3.1 → 0.3.2-alpha-feat-support-external-config-4fdb4b62.7

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
@@ -81,6 +81,25 @@ yarn davinci-graphql-codegen generate-schema --config=./graphql/codegen-schema.j
81
81
 
82
82
  The above script will search for `codegen-schema.json` within `./graphql`.
83
83
 
84
+ ## Using custom config
85
+
86
+ To override default config, a config option could be added in `codegen.json`.
87
+
88
+ ```json
89
+ // codegen.json
90
+ [
91
+ {
92
+ "schema": "@toptal/modularity-template-graphql/talent",
93
+ "documents": "src/**/*.gql",
94
+ "config": {
95
+ "skipTypename": false
96
+ }
97
+ }
98
+ ]
99
+ ```
100
+
101
+ > List of options could be find in https://the-guild.dev/graphql/codegen/plugins/typescript/typescript-operations
102
+
84
103
  ## Customizing the extension of generated files
85
104
 
86
105
  When generating operations, we have set a default setting that generates your operation types within a file named the same as where your query or mutation is and it will have the `.ts` extension. This is due to that the default extension for your queries or mutations should be `.graphql`. But you might have your query within a `.ts` file that comes with, for instance, a hook that makes use of this query, and if you'd run GraphQL Codegen Operations as is, you'll have that `.ts` file ovewriten. But you can avoid this conflict via CLI with the following command:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@toptal/davinci-graphql-codegen",
3
- "version": "0.3.1",
3
+ "version": "0.3.2-alpha-feat-support-external-config-4fdb4b62.7+4fdb4b62",
4
4
  "description": "Codegen",
5
5
  "author": "Toptal",
6
6
  "license": "ISC",
@@ -29,14 +29,16 @@
29
29
  "@graphql-codegen/typescript-operations": "^2.3.5",
30
30
  "@graphql-codegen/typescript-resolvers": "^2.2.1",
31
31
  "@graphql-typed-document-node/core": "^3.1.0",
32
- "@toptal/davinci-cli-shared": "^1.10.0",
33
- "@toptal/davinci-monorepo": "6.8.6",
32
+ "@toptal/davinci-cli-shared": "1.10.1-alpha-feat-support-external-config-4fdb4b62.23+4fdb4b62",
33
+ "@toptal/davinci-monorepo": "6.8.7-alpha-feat-support-external-config-4fdb4b62.7+4fdb4b62",
34
34
  "chalk": "^4.1.2",
35
+ "deepmerge": "^4.2.2",
36
+ "fs-extra": "^10.1.0",
35
37
  "graphql": "^15.7.1",
36
- "prettier": "^2.6.2",
37
- "fs-extra": "^10.1.0"
38
+ "prettier": "^2.6.2"
38
39
  },
39
40
  "peerDependencies": {
40
41
  "prettier": "^2.6.2"
41
- }
42
+ },
43
+ "gitHead": "4fdb4b62be02769af1e55476bafb82f031b5ebbd"
42
44
  }
@@ -6,11 +6,12 @@ const readConfig = require('../read-config')
6
6
  const codegenGenerateOperations = async ({ config, extension = '.ts' }) => {
7
7
  const codegen = await readConfig(config)
8
8
 
9
- for await (const { schema, documents } of codegen) {
9
+ for await (const { schema, documents, customConfig = {} } of codegen) {
10
10
  await generateOperations({
11
11
  schema,
12
12
  documents,
13
13
  extension,
14
+ customConfig,
14
15
  })
15
16
  }
16
17
  }
@@ -3,6 +3,7 @@ const { generate } = require('@graphql-codegen/cli')
3
3
  const { readFileSync, writeFileSync } = require('fs-extra')
4
4
  const prettier = require('prettier')
5
5
  const { dirname } = require('path')
6
+ const merge = require('deepmerge')
6
7
 
7
8
  const {
8
9
  commonOperationTypesConfig,
@@ -11,7 +12,7 @@ const {
11
12
  const getSchemaPath = require('../services/get-schema-path')
12
13
  const getRelativeFilePath = require('../utils/get-relative-file-path')
13
14
 
14
- const generateOperations = async ({ schema, documents, extension }) => {
15
+ const generateOperations = async ({ schema, documents, extension, config }) => {
15
16
  const docsPath = getRelativeFilePath(documents)
16
17
 
17
18
  const { target, schemaPath, schemaPathResolution } = getSchemaPath(schema)
@@ -22,9 +23,7 @@ const generateOperations = async ({ schema, documents, extension }) => {
22
23
  await generate(
23
24
  {
24
25
  documents: docsPath,
25
- config: {
26
- ...commonOperationTypesConfig,
27
- },
26
+ config: merge(commonOperationTypesConfig, config),
28
27
  generates: {
29
28
  [schemaPath]: {
30
29
  schema: schemaPathResolution,
@@ -1,42 +0,0 @@
1
- {
2
- "name": "@toptal/davinci-graphql-codegen",
3
- "version": "0.3.1",
4
- "description": "Codegen",
5
- "author": "Toptal",
6
- "license": "ISC",
7
- "homepage": "https://github.com/toptal/davinci/tree/master/packages/graphql-codegen#readme",
8
- "publishConfig": {
9
- "access": "public"
10
- },
11
- "bin": {
12
- "davinci-graphql-codegen": "./bin/davinci-graphql-codegen.js"
13
- },
14
- "main": "./src/index.js",
15
- "scripts": {
16
- "build:package": "../../bin/build-package.js",
17
- "prepublishOnly": "../../bin/prepublish.js",
18
- "test": "echo \"Error: no test specified\" && exit 1"
19
- },
20
- "sideEffects": false,
21
- "dependencies": {
22
- "@google-cloud/storage": "^6.2.3",
23
- "@graphql-codegen/add": "^3.1.0",
24
- "@graphql-codegen/cli": "^2.11.3",
25
- "@graphql-codegen/introspection": "^2.2.0",
26
- "@graphql-codegen/near-operation-file-preset": "^2.4.4",
27
- "@graphql-codegen/typed-document-node": "^2.3.2",
28
- "@graphql-codegen/typescript": "^2.2.2",
29
- "@graphql-codegen/typescript-operations": "^2.3.5",
30
- "@graphql-codegen/typescript-resolvers": "^2.2.1",
31
- "@graphql-typed-document-node/core": "^3.1.0",
32
- "@toptal/davinci-cli-shared": "^1.10.0",
33
- "@toptal/davinci-monorepo": "6.8.6",
34
- "chalk": "^4.1.2",
35
- "graphql": "^15.7.1",
36
- "prettier": "^2.6.2",
37
- "fs-extra": "^10.1.0"
38
- },
39
- "peerDependencies": {
40
- "prettier": "^2.6.2"
41
- }
42
- }
@@ -1,71 +0,0 @@
1
- jest.mock('@toptal/davinci-monorepo', () => ({
2
- commands: [],
3
- utils: { checkIfMonorepo: jest.fn() },
4
- }))
5
-
6
- jest.mock('./get-monorepo-schema-path', () =>
7
- jest.fn(() => ({
8
- target: 'talent',
9
- schemaPath: '@toptal/modularity-template-graphql',
10
- schemaPathResolution:
11
- 'home/users/alexvcasillas/toptal/libs/graphql/schema.graphql',
12
- }))
13
- )
14
-
15
- jest.mock('./get-monolith-schema-path', () =>
16
- jest.fn(() => ({
17
- target: 'src/modules/graphql',
18
- schemaPath: 'src/modules/graphql',
19
- schemaPathResolution:
20
- 'home/users/alexvcasillas/toptal/screening-wizard/src/modules/graphql/schema.graphql',
21
- }))
22
- )
23
-
24
- const {
25
- utils: { checkIfMonorepo },
26
- } = require('@toptal/davinci-monorepo')
27
-
28
- const getSchemaPath = require('./get-schema-path')
29
-
30
- const monorepoSchema = '@toptal/modularity-template-graphql/talent'
31
- const monolithSchema = 'src/modules/graphql'
32
-
33
- describe('getSchemaPath', () => {
34
- beforeEach(() => {
35
- checkIfMonorepo.mockReset()
36
- })
37
-
38
- it('returns target, schemaPath and schemaPathResolution for monorepo', () => {
39
- checkIfMonorepo.mockReturnValue(() => true)
40
-
41
- const { target, schemaPath, schemaPathResolution } =
42
- getSchemaPath(monorepoSchema)
43
-
44
- expect(checkIfMonorepo).toHaveBeenCalledTimes(1)
45
- expect(checkIfMonorepo).toHaveBeenCalledWith({
46
- considerYarnWorkspaces: true,
47
- })
48
- expect(target).toBe('talent')
49
- expect(schemaPath).toBe('@toptal/modularity-template-graphql')
50
- expect(schemaPathResolution).toBe(
51
- 'home/users/alexvcasillas/toptal/libs/graphql/schema.graphql'
52
- )
53
- })
54
-
55
- it('returns target, schemaPath and schemaPathResolution for monolith', () => {
56
- checkIfMonorepo.mockReturnValue(false)
57
-
58
- const { target, schemaPath, schemaPathResolution } =
59
- getSchemaPath(monolithSchema)
60
-
61
- expect(checkIfMonorepo).toHaveBeenCalledTimes(1)
62
- expect(checkIfMonorepo).toHaveBeenCalledWith({
63
- considerYarnWorkspaces: true,
64
- })
65
- expect(target).toBe('src/modules/graphql')
66
- expect(schemaPath).toBe('src/modules/graphql')
67
- expect(schemaPathResolution).toBe(
68
- 'home/users/alexvcasillas/toptal/screening-wizard/src/modules/graphql/schema.graphql'
69
- )
70
- })
71
- })
@@ -1,29 +0,0 @@
1
- const {
2
- isSchemaFromBucket,
3
- isSchemaFromHttp,
4
- isLocalSchema,
5
- } = require('./detect-schema-source')
6
-
7
- const gsBucketSchema = 'gs://toptal.net/gateway/graphql/talent'
8
- const httpSchema = 'https://toptal.net/gateway/graphql/talent'
9
- const localSchema = '../../graphql/talent'
10
-
11
- describe('Detect Schema Sources', () => {
12
- it('detects that schema is from GS Bucket', () => {
13
- expect(isSchemaFromBucket(gsBucketSchema)).toBe(true)
14
- expect(isSchemaFromHttp(gsBucketSchema)).toBe(false)
15
- expect(isLocalSchema(gsBucketSchema)).toBe(false)
16
- })
17
-
18
- it('detects that schema is from http', () => {
19
- expect(isSchemaFromBucket(httpSchema)).toBe(false)
20
- expect(isSchemaFromHttp(httpSchema)).toBe(true)
21
- expect(isLocalSchema(httpSchema)).toBe(false)
22
- })
23
-
24
- it('detects that schema is from local folder', () => {
25
- expect(isSchemaFromBucket(localSchema)).toBe(false)
26
- expect(isSchemaFromHttp(localSchema)).toBe(false)
27
- expect(isLocalSchema(localSchema)).toBe(true)
28
- })
29
- })
@@ -1,12 +0,0 @@
1
- const parseGSURI = require('./parse-gs-uri')
2
-
3
- const bucketURI = 'gs://gqlgw-introspection/staging_talent_schema.graphql'
4
-
5
- describe('Parse Google Storage Bucket URI', () => {
6
- it('parses a Google Storage Bucket URI correctly', () => {
7
- const { bucketName, fileName } = parseGSURI(bucketURI)
8
-
9
- expect(bucketName).toBe('gqlgw-introspection')
10
- expect(fileName).toBe('staging_talent_schema.graphql')
11
- })
12
- })
@@ -1,10 +0,0 @@
1
- const processArgs = require('./process-args')
2
-
3
- describe('Argument processor', () => {
4
- it('process arguments correctly', () => {
5
- const args = processArgs(['generate-operations', '--projectId=toptal'])
6
-
7
- expect(args.operation).toBe('generate-operations')
8
- expect(args.projectId).toBe('toptal')
9
- })
10
- })
@@ -1,15 +0,0 @@
1
- const toArray = require('./to-array')
2
-
3
- describe('toArray', () => {
4
- it("converts a value into an array if it's not one", () => {
5
- const asArray = toArray('hello')
6
-
7
- expect(Array.isArray(asArray)).toBe(true)
8
- })
9
-
10
- it("returns the array as is if it's an array", () => {
11
- const asArray = toArray(['hello', 'there'])
12
-
13
- expect(Array.isArray(asArray)).toBe(true)
14
- })
15
- })