@toptal/davinci-graphql-codegen 0.2.25-alpha-fix-execute-graphql-command-f9d910f2.16 → 0.3.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,13 @@
1
1
  # @toptal/davinci-graphql-codegen
2
2
 
3
+ ## 0.3.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#1799](https://github.com/toptal/davinci/pull/1799) [`103a3ec9`](https://github.com/toptal/davinci/commit/103a3ec94aa9ca9d9d83aab4cbcb510e26bf6071) Thanks [@separatio](https://github.com/separatio)! - ---
8
+
9
+ - upgrade required minimum Node version to 14 LTS
10
+
3
11
  ## 0.2.24
4
12
 
5
13
  ### Patch Changes
@@ -9,4 +9,3 @@ cliEngine.loadCommands(
9
9
  [codegenGenerateSchemaCreator, codegenGenerateOperationsCreator],
10
10
  'davinci-graphql-codegen'
11
11
  )
12
- cliEngine.bootstrap()
@@ -0,0 +1,37 @@
1
+ {
2
+ "name": "@toptal/davinci-graphql-codegen",
3
+ "version": "0.3.0",
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.5",
34
+ "chalk": "^4.1.2",
35
+ "graphql": "^15.7.1"
36
+ }
37
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@toptal/davinci-graphql-codegen",
3
- "version": "0.2.25-alpha-fix-execute-graphql-command-f9d910f2.16+f9d910f2",
3
+ "version": "0.3.0",
4
4
  "description": "Codegen",
5
5
  "author": "Toptal",
6
6
  "license": "ISC",
@@ -29,12 +29,9 @@
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.1-alpha-fix-execute-graphql-command-f9d910f2.16+f9d910f2",
33
- "@toptal/davinci-monorepo": "6.8.6-alpha-fix-execute-graphql-command-f9d910f2.16+f9d910f2",
32
+ "@toptal/davinci-cli-shared": "^1.10.0",
33
+ "@toptal/davinci-monorepo": "6.8.5",
34
34
  "chalk": "^4.1.2",
35
- "fs-extra": "^10.1.0",
36
- "graphql": "^15.7.1",
37
- "prettier": "^2.6.2"
38
- },
39
- "gitHead": "f9d910f255c0f3a91e4181beb4b1883fd158551e"
35
+ "graphql": "^15.7.1"
36
+ }
40
37
  }
@@ -1,7 +1,5 @@
1
1
  const chalk = require('chalk')
2
2
  const { generate } = require('@graphql-codegen/cli')
3
- const { readFileSync, writeFileSync } = require('fs-extra')
4
- const prettier = require('prettier')
5
3
 
6
4
  const {
7
5
  commonOperationTypesConfig,
@@ -44,21 +42,7 @@ const generateOperations = async ({ schema, documents, extension }) => {
44
42
  },
45
43
  },
46
44
  hooks: {
47
- afterAllFileWrite: [
48
- async (...filePaths) => {
49
- for (const path of filePaths) {
50
- const rawText = readFileSync(path, 'utf8')
51
- const options = await prettier.resolveConfig(process.cwd())
52
-
53
- const formattedText = prettier.format(rawText, {
54
- parser: 'typescript',
55
- ...options,
56
- })
57
-
58
- writeFileSync(path, formattedText)
59
- }
60
- },
61
- ],
45
+ afterAllFileWrite: 'prettier --write',
62
46
  },
63
47
  },
64
48
  true
@@ -1,7 +1,5 @@
1
1
  const { generate } = require('@graphql-codegen/cli')
2
2
  const chalk = require('chalk')
3
- const { readFileSync, writeFileSync } = require('fs')
4
- const prettier = require('prettier')
5
3
 
6
4
  const {
7
5
  commonSchemaTypesConfig,
@@ -39,21 +37,7 @@ const generateSchema = async ({ schema, target, projectId }) => {
39
37
  },
40
38
  },
41
39
  hooks: {
42
- afterAllFileWrite: [
43
- async (...filePaths) => {
44
- for (const path of filePaths) {
45
- const rawText = readFileSync(path, 'utf8')
46
- const options = await prettier.resolveConfig(process.cwd())
47
-
48
- const formattedText = prettier.format(rawText, {
49
- parser: 'typescript',
50
- ...options,
51
- })
52
-
53
- writeFileSync(path, formattedText)
54
- }
55
- },
56
- ],
40
+ afterAllFileWrite: 'prettier --write',
57
41
  },
58
42
  config: {
59
43
  ...commonSchemaTypesConfig,
@@ -6,7 +6,7 @@ const getMonorepoSchemaPath = require('./get-monorepo-schema-path')
6
6
  const getMonolithSchemaPath = require('./get-monolith-schema-path')
7
7
 
8
8
  const getSchemaPath = schema => {
9
- return checkIfMonorepo({ considerWorkspaces: true })
9
+ return checkIfMonorepo()
10
10
  ? getMonorepoSchemaPath(schema)
11
11
  : getMonolithSchemaPath(schema)
12
12
  }
@@ -0,0 +1,59 @@
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
+ it('returns target, schemaPath and schemaPathResolution for monorepo', () => {
35
+ checkIfMonorepo.mockReturnValue(() => true)
36
+
37
+ const { target, schemaPath, schemaPathResolution } =
38
+ getSchemaPath(monorepoSchema)
39
+
40
+ expect(target).toBe('talent')
41
+ expect(schemaPath).toBe('@toptal/modularity-template-graphql')
42
+ expect(schemaPathResolution).toBe(
43
+ 'home/users/alexvcasillas/toptal/libs/graphql/schema.graphql'
44
+ )
45
+ })
46
+
47
+ it('returns target, schemaPath and schemaPathResolution for monolith', () => {
48
+ checkIfMonorepo.mockReturnValue(false)
49
+
50
+ const { target, schemaPath, schemaPathResolution } =
51
+ getSchemaPath(monolithSchema)
52
+
53
+ expect(target).toBe('src/modules/graphql')
54
+ expect(schemaPath).toBe('src/modules/graphql')
55
+ expect(schemaPathResolution).toBe(
56
+ 'home/users/alexvcasillas/toptal/screening-wizard/src/modules/graphql/schema.graphql'
57
+ )
58
+ })
59
+ })
@@ -0,0 +1,29 @@
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
+ })
@@ -0,0 +1,12 @@
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
+ })
@@ -0,0 +1,10 @@
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
+ })
@@ -0,0 +1,15 @@
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
+ })