@toptal/davinci-graphql-codegen 0.4.2-alpha-fx-3227-migrate-graphql-codegen-to-esm-b0005a16.21 → 0.4.2
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 +8 -0
- package/bin/davinci-graphql-codegen.js +4 -3
- package/package.json +14 -16
- package/src/commands/generate-operations.js +4 -4
- package/src/commands/generate-schema.js +4 -4
- package/src/config/config.js +4 -4
- package/src/config/index.js +2 -2
- package/src/generate/index.js +3 -4
- package/src/generate/operations.js +11 -13
- package/src/generate/schema.js +11 -14
- package/src/index.js +4 -4
- package/src/read-config/index.js +2 -2
- package/src/read-config/read-config.js +10 -27
- package/src/services/get-monolith-schema-path.js +8 -12
- package/src/services/get-monorepo-schema-path.js +3 -11
- package/src/services/get-schema-path.js +9 -11
- package/src/services/get-schema-path.test.js +71 -0
- package/src/services/gs-schema-loader.js +4 -4
- package/src/services/schema-loader.js +7 -7
- package/src/utils/detect-schema-source.js +4 -4
- package/src/utils/detect-schema-source.test.js +29 -0
- package/src/utils/get-relative-file-path.js +1 -1
- package/src/utils/parse-gs-uri.js +1 -1
- package/src/utils/parse-gs-uri.test.js +12 -0
- package/src/utils/process-args.js +1 -1
- package/src/utils/process-args.test.js +10 -0
- package/src/utils/to-array.js +1 -1
- package/src/utils/to-array.test.js +15 -0
- package/esbuild.js +0 -16
- package/jest.config.js +0 -3
- package/tsconfig.json +0 -8
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# @toptal/davinci-graphql-codegen
|
|
2
2
|
|
|
3
|
+
## 0.4.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [[`1457314e`](https://github.com/toptal/davinci/commit/1457314e7f449146077753dcc467565e6ce4d3d2)]:
|
|
8
|
+
- @toptal/davinci-cli-shared@1.10.2
|
|
9
|
+
- @toptal/davinci-monorepo@6.8.8
|
|
10
|
+
|
|
3
11
|
## 0.4.1
|
|
4
12
|
|
|
5
13
|
### Patch Changes
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import cliEngine from '@toptal/davinci-cli-shared'
|
|
3
2
|
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
const cliEngine = require('@toptal/davinci-cli-shared')
|
|
4
|
+
|
|
5
|
+
const codegenGenerateSchemaCreator = require('../src/commands/generate-schema')
|
|
6
|
+
const codegenGenerateOperationsCreator = require('../src/commands/generate-operations')
|
|
6
7
|
|
|
7
8
|
cliEngine.loadCommands(
|
|
8
9
|
[codegenGenerateSchemaCreator, codegenGenerateOperationsCreator],
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@toptal/davinci-graphql-codegen",
|
|
3
|
-
"version": "0.4.2
|
|
3
|
+
"version": "0.4.2",
|
|
4
4
|
"description": "Codegen",
|
|
5
5
|
"author": "Toptal",
|
|
6
6
|
"license": "ISC",
|
|
@@ -11,12 +11,14 @@
|
|
|
11
11
|
"bin": {
|
|
12
12
|
"davinci-graphql-codegen": "./bin/davinci-graphql-codegen.js"
|
|
13
13
|
},
|
|
14
|
-
"
|
|
15
|
-
"
|
|
14
|
+
"main": "src/index.js",
|
|
15
|
+
"files": [
|
|
16
|
+
"src",
|
|
17
|
+
"bin",
|
|
18
|
+
"CHANGELOG.md"
|
|
19
|
+
],
|
|
16
20
|
"scripts": {
|
|
17
|
-
"
|
|
18
|
-
"prepublishOnly": "../../bin/prepublish.js",
|
|
19
|
-
"test": "NODE_OPTIONS='--experimental-vm-modules --no-warnings' yarn jest"
|
|
21
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
20
22
|
},
|
|
21
23
|
"sideEffects": false,
|
|
22
24
|
"dependencies": {
|
|
@@ -30,19 +32,15 @@
|
|
|
30
32
|
"@graphql-codegen/typescript-operations": "^2.3.5",
|
|
31
33
|
"@graphql-codegen/typescript-resolvers": "^2.2.1",
|
|
32
34
|
"@graphql-typed-document-node/core": "^3.1.0",
|
|
33
|
-
"@toptal/davinci-cli-shared": "1.10.2
|
|
34
|
-
"@toptal/davinci-monorepo": "6.8.8
|
|
35
|
+
"@toptal/davinci-cli-shared": "^1.10.2",
|
|
36
|
+
"@toptal/davinci-monorepo": "6.8.8",
|
|
35
37
|
"chalk": "^4.1.2",
|
|
36
38
|
"deepmerge": "^4.2.2",
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
+
"graphql": "^15.7.1",
|
|
40
|
+
"prettier": "^2.6.2",
|
|
41
|
+
"fs-extra": "^10.1.0"
|
|
39
42
|
},
|
|
40
43
|
"peerDependencies": {
|
|
41
44
|
"prettier": "^2.6.2"
|
|
42
|
-
}
|
|
43
|
-
"devDependencies": {
|
|
44
|
-
"@jest/globals": "^29.3.1",
|
|
45
|
-
"prettier": "^2.6.2"
|
|
46
|
-
},
|
|
47
|
-
"gitHead": "b0005a1651c57d39a2a20fc68fb19d2908470c09"
|
|
45
|
+
}
|
|
48
46
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
const chalk = require('chalk')
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
const { generateOperations } = require('../generate')
|
|
4
|
+
const readConfig = require('../read-config')
|
|
5
5
|
|
|
6
6
|
const codegenGenerateOperations = async ({ config, extension = '.ts' }) => {
|
|
7
7
|
const codegen = await readConfig(config)
|
|
@@ -40,4 +40,4 @@ const codegenGenerateOperationsCreator = {
|
|
|
40
40
|
},
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
|
|
43
|
+
module.exports = codegenGenerateOperationsCreator
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
const chalk = require('chalk')
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
const { generateSchema } = require('../generate')
|
|
4
|
+
const readConfig = require('../read-config')
|
|
5
5
|
|
|
6
6
|
const codegenGenerateSchema = async ({ projectId = 'toptal-hub', config }) => {
|
|
7
7
|
const codegen = await readConfig(config)
|
|
@@ -36,4 +36,4 @@ const codegenGenerateSchemaCreator = {
|
|
|
36
36
|
},
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
|
|
39
|
+
module.exports = codegenGenerateSchemaCreator
|
package/src/config/config.js
CHANGED
|
@@ -23,7 +23,7 @@ const commonTypesConfig = {
|
|
|
23
23
|
},
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
|
|
26
|
+
const commonSchemaTypesConfig = {
|
|
27
27
|
...commonTypesConfig,
|
|
28
28
|
resolverTypeWrapperSignature:
|
|
29
29
|
'(parent: unknown, args: any) => ({ [K in keyof Partial<T>]: TypeOrMockList<T[K]> }) | null',
|
|
@@ -33,17 +33,17 @@ export const commonSchemaTypesConfig = {
|
|
|
33
33
|
optionalResolveType: true,
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
|
|
36
|
+
const commonOperationTypesConfig = {
|
|
37
37
|
...commonTypesConfig,
|
|
38
38
|
dedupeFragments: true,
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
|
|
41
|
+
const autoGenerationComments = [
|
|
42
42
|
'/* eslint-disable */',
|
|
43
43
|
'/* ⚠️ THIS IS AN AUTOGENERATED FILE, DO NOT EDIT ⚠️ */',
|
|
44
44
|
]
|
|
45
45
|
|
|
46
|
-
|
|
46
|
+
module.exports = {
|
|
47
47
|
commonOperationTypesConfig,
|
|
48
48
|
commonSchemaTypesConfig,
|
|
49
49
|
autoGenerationComments,
|
package/src/config/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
|
|
1
|
+
const config = require('./config')
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
module.exports = config
|
package/src/generate/index.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
const generateOperations = require('./operations')
|
|
2
|
+
const generateSchema = require('./schema')
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
export default { generateOperations, generateSchema }
|
|
4
|
+
module.exports = { generateOperations, generateSchema }
|
|
@@ -1,18 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
const chalk = require('chalk')
|
|
2
|
+
const { generate } = require('@graphql-codegen/cli')
|
|
3
|
+
const { readFileSync, writeFileSync } = require('fs-extra')
|
|
4
|
+
const prettier = require('prettier')
|
|
5
|
+
const { dirname } = require('path')
|
|
6
|
+
const merge = require('deepmerge')
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
const {
|
|
9
9
|
commonOperationTypesConfig,
|
|
10
10
|
autoGenerationComments,
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const { readFileSync, writeFileSync } = fs
|
|
11
|
+
} = require('../config/config')
|
|
12
|
+
const getSchemaPath = require('../services/get-schema-path')
|
|
13
|
+
const getRelativeFilePath = require('../utils/get-relative-file-path')
|
|
16
14
|
|
|
17
15
|
const generateOperations = async ({ schema, documents, extension, config }) => {
|
|
18
16
|
const docsPath = getRelativeFilePath(documents)
|
|
@@ -67,4 +65,4 @@ const generateOperations = async ({ schema, documents, extension, config }) => {
|
|
|
67
65
|
)
|
|
68
66
|
}
|
|
69
67
|
|
|
70
|
-
|
|
68
|
+
module.exports = generateOperations
|
package/src/generate/schema.js
CHANGED
|
@@ -1,18 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
import { dirname } from 'path'
|
|
1
|
+
const { generate } = require('@graphql-codegen/cli')
|
|
2
|
+
const chalk = require('chalk')
|
|
3
|
+
const { readFileSync, writeFileSync } = require('fs')
|
|
4
|
+
const prettier = require('prettier')
|
|
5
|
+
const { dirname } = require('path')
|
|
7
6
|
|
|
8
|
-
|
|
7
|
+
const {
|
|
9
8
|
commonSchemaTypesConfig,
|
|
10
9
|
autoGenerationComments,
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const localRequire = createRequire(import.meta.url)
|
|
10
|
+
} = require('../config/config')
|
|
11
|
+
const schemaLoader = require('../services/schema-loader')
|
|
12
|
+
const { isSchemaFromHttp } = require('../utils/detect-schema-source')
|
|
16
13
|
|
|
17
14
|
const generateSchema = async ({ schema, target, projectId }) => {
|
|
18
15
|
const { schema: schemaPath, destination: destinationPathTs } =
|
|
@@ -30,7 +27,7 @@ const generateSchema = async ({ schema, target, projectId }) => {
|
|
|
30
27
|
[destinationPathTs]: {
|
|
31
28
|
schema: isSchemaFromHttp(schema)
|
|
32
29
|
? schema
|
|
33
|
-
:
|
|
30
|
+
: require.resolve(schemaPath),
|
|
34
31
|
plugins: [
|
|
35
32
|
'typescript',
|
|
36
33
|
'typescript-resolvers',
|
|
@@ -67,4 +64,4 @@ const generateSchema = async ({ schema, target, projectId }) => {
|
|
|
67
64
|
)
|
|
68
65
|
}
|
|
69
66
|
|
|
70
|
-
|
|
67
|
+
module.exports = generateSchema
|
package/src/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
const codegenGenerateSchemaCreator = require('./commands/generate-schema')
|
|
2
|
+
const codegenGenerateOperationsCreator = require('./commands/generate-operations')
|
|
3
|
+
const config = require('./config')
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
module.exports = {
|
|
6
6
|
commands: [codegenGenerateSchemaCreator, codegenGenerateOperationsCreator],
|
|
7
7
|
config,
|
|
8
8
|
}
|
package/src/read-config/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
|
|
1
|
+
const readConfig = require('./read-config')
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
module.exports = readConfig
|
|
@@ -1,32 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
import { createRequire } from 'module'
|
|
1
|
+
const chalk = require('chalk')
|
|
3
2
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const importCodgenConfig = async path => {
|
|
8
|
-
try {
|
|
9
|
-
const localRequire = createRequire(import.meta.url)
|
|
10
|
-
|
|
11
|
-
return localRequire(path)
|
|
12
|
-
} catch (err) {
|
|
13
|
-
if (err.code === 'ERR_REQUIRE_ESM') {
|
|
14
|
-
const result = await import(path)
|
|
15
|
-
|
|
16
|
-
if (!result.default) {
|
|
17
|
-
throw Error('codegen has no default export')
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
return result.default
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
}
|
|
3
|
+
const getRelativeFilePath = require('../utils/get-relative-file-path')
|
|
4
|
+
const toArray = require('../utils/to-array')
|
|
24
5
|
|
|
25
6
|
const readConfig = async config => {
|
|
26
|
-
const configFileName = config ? config.split('/').pop() : 'codegen.json'
|
|
27
|
-
|
|
28
7
|
let codegenPath
|
|
29
8
|
|
|
9
|
+
const configFileName = config ? config.split('/').pop() : 'codegen.json'
|
|
10
|
+
|
|
30
11
|
if (config) {
|
|
31
12
|
console.log(
|
|
32
13
|
`🔍 Searching for ${chalk.bold(
|
|
@@ -38,13 +19,15 @@ const readConfig = async config => {
|
|
|
38
19
|
console.log(`🔍 Searching for ${chalk.bold(configFileName)} file`)
|
|
39
20
|
codegenPath = getRelativeFilePath(configFileName)
|
|
40
21
|
}
|
|
22
|
+
let codegenConfig
|
|
41
23
|
|
|
42
24
|
try {
|
|
43
|
-
|
|
25
|
+
codegenConfig = require(codegenPath)
|
|
44
26
|
} catch (error) {
|
|
45
|
-
console.log(error)
|
|
46
27
|
throw new Error(`❌ There is no ${chalk.bold(configFileName)} file`)
|
|
47
28
|
}
|
|
29
|
+
|
|
30
|
+
return toArray(codegenConfig)
|
|
48
31
|
}
|
|
49
32
|
|
|
50
|
-
|
|
33
|
+
module.exports = readConfig
|
|
@@ -1,15 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
const getRelativeFilePath = require('../utils/get-relative-file-path')
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
)
|
|
3
|
+
const getMonolithSchemaPath = schemaPath => {
|
|
4
|
+
const schemaPathResolution = getRelativeFilePath(
|
|
5
|
+
`${schemaPath}/schema.graphql`
|
|
6
|
+
)
|
|
8
7
|
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
return { target: schemaPath, schemaPath, schemaPathResolution }
|
|
9
|
+
}
|
|
11
10
|
|
|
12
|
-
|
|
13
|
-
createGetMonolithSchemaPathResolver(getRelativeFilePath)
|
|
14
|
-
|
|
15
|
-
export default getMonolithSchemaPath
|
|
11
|
+
module.exports = getMonolithSchemaPath
|
|
@@ -1,22 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const localRequire = createRequire(import.meta.url)
|
|
4
|
-
|
|
5
|
-
export const createGetMonorepoSchemaPathResolver = pathResolver => schema => {
|
|
1
|
+
const getMonorepoSchemaPath = schema => {
|
|
6
2
|
// @toptal/modularity-template-graphql/talent -> talent
|
|
7
3
|
const target = schema.split('/').pop()
|
|
8
4
|
// @toptal/modularity-template-graphql/talent -> @toptal/modularity-template-graphql
|
|
9
5
|
const schemaPath = schema.split('/').slice(0, 2).join('/')
|
|
10
6
|
|
|
11
|
-
const schemaPathResolution =
|
|
7
|
+
const schemaPathResolution = require.resolve(
|
|
12
8
|
`${schemaPath}/${target}/schema.graphql`
|
|
13
9
|
)
|
|
14
10
|
|
|
15
11
|
return { target, schemaPath, schemaPathResolution }
|
|
16
12
|
}
|
|
17
13
|
|
|
18
|
-
|
|
19
|
-
localRequire.resolve
|
|
20
|
-
)
|
|
21
|
-
|
|
22
|
-
export default getMonorepoSchemaPath
|
|
14
|
+
module.exports = getMonorepoSchemaPath
|
|
@@ -1,16 +1,14 @@
|
|
|
1
|
-
|
|
1
|
+
const {
|
|
2
|
+
utils: { checkIfMonorepo },
|
|
3
|
+
} = require('@toptal/davinci-monorepo')
|
|
2
4
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const { checkIfMonorepo } = monorepo.utils
|
|
5
|
+
const getMonorepoSchemaPath = require('./get-monorepo-schema-path')
|
|
6
|
+
const getMonolithSchemaPath = require('./get-monolith-schema-path')
|
|
7
7
|
|
|
8
8
|
const getSchemaPath = schema => {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
return getMonolithSchemaPath(schema)
|
|
9
|
+
return checkIfMonorepo({ considerYarnWorkspaces: true })
|
|
10
|
+
? getMonorepoSchemaPath(schema)
|
|
11
|
+
: getMonolithSchemaPath(schema)
|
|
14
12
|
}
|
|
15
13
|
|
|
16
|
-
|
|
14
|
+
module.exports = getSchemaPath
|
|
@@ -0,0 +1,71 @@
|
|
|
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,7 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
const { Storage } = require('@google-cloud/storage')
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
const getRelativeFilePath = require('../utils/get-relative-file-path')
|
|
4
|
+
const parseGSURI = require('../utils/parse-gs-uri')
|
|
5
5
|
|
|
6
6
|
const gsSchemaLoader = async (projectId, source, destination) => {
|
|
7
7
|
// Creates a Google Storage Client
|
|
@@ -17,4 +17,4 @@ const gsSchemaLoader = async (projectId, source, destination) => {
|
|
|
17
17
|
})
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
module.exports = gsSchemaLoader
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
const chalk = require('chalk')
|
|
2
|
+
const { existsSync, copyFileSync, mkdirSync } = require('fs')
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
const gsSchemaLoader = require('./gs-schema-loader')
|
|
5
|
+
const getRelativeFilePath = require('../utils/get-relative-file-path')
|
|
6
|
+
const {
|
|
7
7
|
isSchemaFromBucket,
|
|
8
8
|
isLocalSchema,
|
|
9
9
|
isSchemaFromHttp,
|
|
10
|
-
}
|
|
10
|
+
} = require('../utils/detect-schema-source')
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
module.exports = async (schema, target, projectId) => {
|
|
13
13
|
if (!existsSync(target)) {
|
|
14
14
|
console.log("📁 Destination target doesn't exist, creating one for you...")
|
|
15
15
|
mkdirSync(target)
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
|
|
1
|
+
const isSchemaFromBucket = schema => {
|
|
2
2
|
return schema.startsWith('gs://')
|
|
3
3
|
}
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
const isSchemaFromHttp = schema => {
|
|
6
6
|
return schema.startsWith('https://')
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
const isLocalSchema = schema => {
|
|
10
10
|
return !isSchemaFromBucket(schema) && !isSchemaFromHttp(schema)
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
module.exports = {
|
|
14
14
|
isSchemaFromBucket,
|
|
15
15
|
isSchemaFromHttp,
|
|
16
16
|
isLocalSchema,
|
|
@@ -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
|
+
})
|
package/src/utils/to-array.js
CHANGED
|
@@ -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
|
+
})
|
package/esbuild.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import esbuild from 'esbuild'
|
|
2
|
-
// Automatically exclude all node_modules from the bundled version
|
|
3
|
-
import { nodeExternalsPlugin } from 'esbuild-node-externals'
|
|
4
|
-
|
|
5
|
-
esbuild
|
|
6
|
-
.build({
|
|
7
|
-
entryPoints: ['./bin/davinci-graphql-codegen.ts'],
|
|
8
|
-
outdir: 'dist-package',
|
|
9
|
-
bundle: true,
|
|
10
|
-
minify: false,
|
|
11
|
-
platform: 'node',
|
|
12
|
-
sourcemap: true,
|
|
13
|
-
target: 'node14',
|
|
14
|
-
plugins: [nodeExternalsPlugin()],
|
|
15
|
-
})
|
|
16
|
-
.catch(() => process.exit(1))
|
package/jest.config.js
DELETED