@toptal/davinci-graphql-codegen 0.4.3-alpha-fix-bundle-analyze-e1cf8407.5 → 0.4.3-alpha-feature-esm-migration-e551c09d.30
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/bin/davinci-graphql-codegen.js +3 -4
- package/package.json +12 -8
- 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 +4 -3
- package/src/generate/operations.js +13 -11
- package/src/generate/schema.js +14 -11
- package/src/index.js +4 -4
- package/src/read-config/index.js +2 -2
- package/src/read-config/read-config.js +27 -10
- package/src/services/get-monolith-schema-path.js +12 -8
- package/src/services/get-monolith-schema-path.test.js +22 -0
- package/src/services/get-monorepo-schema-path.js +11 -3
- package/src/services/get-monorepo-schema-path.test.js +22 -0
- package/src/services/get-schema-path.js +11 -9
- 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 +2 -2
- 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 +1 -1
- package/src/utils/process-args.js +1 -1
- package/src/utils/process-args.test.js +1 -1
- package/src/utils/to-array.js +1 -1
- package/src/utils/to-array.test.js +1 -1
- package/src/services/get-schema-path.test.js +0 -71
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
import cliEngine from '@toptal/davinci-cli-shared'
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const codegenGenerateSchemaCreator = require('../src/commands/generate-schema')
|
|
6
|
-
const codegenGenerateOperationsCreator = require('../src/commands/generate-operations')
|
|
4
|
+
import codegenGenerateSchemaCreator from '../src/commands/generate-schema.js'
|
|
5
|
+
import codegenGenerateOperationsCreator from '../src/commands/generate-operations.js'
|
|
7
6
|
|
|
8
7
|
cliEngine.loadCommands(
|
|
9
8
|
[codegenGenerateSchemaCreator, codegenGenerateOperationsCreator],
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@toptal/davinci-graphql-codegen",
|
|
3
|
-
"version": "0.4.3-alpha-
|
|
3
|
+
"version": "0.4.3-alpha-feature-esm-migration-e551c09d.30+e551c09d",
|
|
4
4
|
"description": "Codegen",
|
|
5
5
|
"author": "Toptal",
|
|
6
6
|
"license": "ISC",
|
|
@@ -11,14 +11,15 @@
|
|
|
11
11
|
"bin": {
|
|
12
12
|
"davinci-graphql-codegen": "./bin/davinci-graphql-codegen.js"
|
|
13
13
|
},
|
|
14
|
-
"
|
|
14
|
+
"type": "module",
|
|
15
|
+
"exports": "./index.js",
|
|
15
16
|
"files": [
|
|
16
17
|
"src",
|
|
17
18
|
"bin",
|
|
18
19
|
"CHANGELOG.md"
|
|
19
20
|
],
|
|
20
21
|
"scripts": {
|
|
21
|
-
"test": "
|
|
22
|
+
"test": "NODE_OPTIONS='--experimental-vm-modules --no-warnings' yarn jest"
|
|
22
23
|
},
|
|
23
24
|
"sideEffects": false,
|
|
24
25
|
"dependencies": {
|
|
@@ -32,16 +33,19 @@
|
|
|
32
33
|
"@graphql-codegen/typescript-operations": "^2.3.5",
|
|
33
34
|
"@graphql-codegen/typescript-resolvers": "^2.2.1",
|
|
34
35
|
"@graphql-typed-document-node/core": "^3.1.0",
|
|
35
|
-
"@toptal/davinci-cli-shared": "1.10.3-alpha-
|
|
36
|
-
"@toptal/davinci-monorepo": "6.8.9-alpha-
|
|
36
|
+
"@toptal/davinci-cli-shared": "1.10.3-alpha-feature-esm-migration-e551c09d.30+e551c09d",
|
|
37
|
+
"@toptal/davinci-monorepo": "6.8.9-alpha-feature-esm-migration-e551c09d.30+e551c09d",
|
|
37
38
|
"chalk": "^4.1.2",
|
|
38
39
|
"deepmerge": "^4.2.2",
|
|
39
40
|
"fs-extra": "^10.1.0",
|
|
40
|
-
"graphql": "^15.7.1"
|
|
41
|
-
"prettier": "^2.6.2"
|
|
41
|
+
"graphql": "^15.7.1"
|
|
42
42
|
},
|
|
43
43
|
"peerDependencies": {
|
|
44
44
|
"prettier": "^2.6.2"
|
|
45
45
|
},
|
|
46
|
-
"
|
|
46
|
+
"devDependencies": {
|
|
47
|
+
"@jest/globals": "^29.3.1",
|
|
48
|
+
"prettier": "^2.6.2"
|
|
49
|
+
},
|
|
50
|
+
"gitHead": "e551c09d98a4e340ab16afb27a42fe52a8548d00"
|
|
47
51
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
import chalk from 'chalk'
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
import { generateOperations } from '../generate/index.js'
|
|
4
|
+
import readConfig from '../read-config/index.js'
|
|
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
|
+
export default codegenGenerateOperationsCreator
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
import chalk from 'chalk'
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
import { generateSchema } from '../generate/index.js'
|
|
4
|
+
import readConfig from '../read-config/index.js'
|
|
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
|
+
export default codegenGenerateSchemaCreator
|
package/src/config/config.js
CHANGED
|
@@ -23,7 +23,7 @@ const commonTypesConfig = {
|
|
|
23
23
|
},
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
const commonSchemaTypesConfig = {
|
|
26
|
+
export 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 @@ const commonSchemaTypesConfig = {
|
|
|
33
33
|
optionalResolveType: true,
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
const commonOperationTypesConfig = {
|
|
36
|
+
export const commonOperationTypesConfig = {
|
|
37
37
|
...commonTypesConfig,
|
|
38
38
|
dedupeFragments: true,
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
const autoGenerationComments = [
|
|
41
|
+
export const autoGenerationComments = [
|
|
42
42
|
'/* eslint-disable */',
|
|
43
43
|
'/* ⚠️ THIS IS AN AUTOGENERATED FILE, DO NOT EDIT ⚠️ */',
|
|
44
44
|
]
|
|
45
45
|
|
|
46
|
-
|
|
46
|
+
export default {
|
|
47
47
|
commonOperationTypesConfig,
|
|
48
48
|
commonSchemaTypesConfig,
|
|
49
49
|
autoGenerationComments,
|
package/src/config/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
|
|
1
|
+
import config from './config.js'
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
export default config
|
package/src/generate/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import generateOperations from './operations.js'
|
|
2
|
+
import generateSchema from './schema.js'
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
export { generateOperations, generateSchema }
|
|
5
|
+
export default { generateOperations, generateSchema }
|
|
@@ -1,16 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import chalk from 'chalk'
|
|
2
|
+
import { generate } from '@graphql-codegen/cli'
|
|
3
|
+
import fs from 'fs-extra'
|
|
4
|
+
import prettier from 'prettier'
|
|
5
|
+
import { dirname } from 'path'
|
|
6
|
+
import merge from 'deepmerge'
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
import {
|
|
9
9
|
commonOperationTypesConfig,
|
|
10
10
|
autoGenerationComments,
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
} from '../config/config.js'
|
|
12
|
+
import getSchemaPath from '../services/get-schema-path.js'
|
|
13
|
+
import getRelativeFilePath from '../utils/get-relative-file-path.js'
|
|
14
|
+
|
|
15
|
+
const { readFileSync, writeFileSync } = fs
|
|
14
16
|
|
|
15
17
|
const generateOperations = async ({ schema, documents, extension, config }) => {
|
|
16
18
|
const docsPath = getRelativeFilePath(documents)
|
|
@@ -65,4 +67,4 @@ const generateOperations = async ({ schema, documents, extension, config }) => {
|
|
|
65
67
|
)
|
|
66
68
|
}
|
|
67
69
|
|
|
68
|
-
|
|
70
|
+
export default generateOperations
|
package/src/generate/schema.js
CHANGED
|
@@ -1,15 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { generate } from '@graphql-codegen/cli'
|
|
2
|
+
import chalk from 'chalk'
|
|
3
|
+
import { createRequire } from 'module'
|
|
4
|
+
import { readFileSync, writeFileSync } from 'fs'
|
|
5
|
+
import prettier from 'prettier'
|
|
6
|
+
import { dirname } from 'path'
|
|
6
7
|
|
|
7
|
-
|
|
8
|
+
import {
|
|
8
9
|
commonSchemaTypesConfig,
|
|
9
10
|
autoGenerationComments,
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
} from '../config/config.js'
|
|
12
|
+
import schemaLoader from '../services/schema-loader.js'
|
|
13
|
+
import { isSchemaFromHttp } from '../utils/detect-schema-source.js'
|
|
14
|
+
|
|
15
|
+
const localRequire = createRequire(import.meta.url)
|
|
13
16
|
|
|
14
17
|
const generateSchema = async ({ schema, target, projectId }) => {
|
|
15
18
|
const { schema: schemaPath, destination: destinationPathTs } =
|
|
@@ -27,7 +30,7 @@ const generateSchema = async ({ schema, target, projectId }) => {
|
|
|
27
30
|
[destinationPathTs]: {
|
|
28
31
|
schema: isSchemaFromHttp(schema)
|
|
29
32
|
? schema
|
|
30
|
-
:
|
|
33
|
+
: localRequire.resolve(schemaPath),
|
|
31
34
|
plugins: [
|
|
32
35
|
'typescript',
|
|
33
36
|
'typescript-resolvers',
|
|
@@ -64,4 +67,4 @@ const generateSchema = async ({ schema, target, projectId }) => {
|
|
|
64
67
|
)
|
|
65
68
|
}
|
|
66
69
|
|
|
67
|
-
|
|
70
|
+
export default generateSchema
|
package/src/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import codegenGenerateSchemaCreator from './commands/generate-schema.js'
|
|
2
|
+
import codegenGenerateOperationsCreator from './commands/generate-operations.js'
|
|
3
|
+
import config from './config'
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
export default {
|
|
6
6
|
commands: [codegenGenerateSchemaCreator, codegenGenerateOperationsCreator],
|
|
7
7
|
config,
|
|
8
8
|
}
|
package/src/read-config/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
|
|
1
|
+
import readConfig from './read-config.js'
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
export default readConfig
|
|
@@ -1,13 +1,32 @@
|
|
|
1
|
-
|
|
1
|
+
import chalk from 'chalk'
|
|
2
|
+
import { createRequire } from 'module'
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
|
|
4
|
+
import getRelativeFilePath from '../utils/get-relative-file-path.js'
|
|
5
|
+
import toArray from '../utils/to-array.js'
|
|
5
6
|
|
|
6
|
-
const
|
|
7
|
-
|
|
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
|
+
}
|
|
8
24
|
|
|
25
|
+
const readConfig = async config => {
|
|
9
26
|
const configFileName = config ? config.split('/').pop() : 'codegen.json'
|
|
10
27
|
|
|
28
|
+
let codegenPath
|
|
29
|
+
|
|
11
30
|
if (config) {
|
|
12
31
|
console.log(
|
|
13
32
|
`🔍 Searching for ${chalk.bold(
|
|
@@ -19,15 +38,13 @@ const readConfig = async config => {
|
|
|
19
38
|
console.log(`🔍 Searching for ${chalk.bold(configFileName)} file`)
|
|
20
39
|
codegenPath = getRelativeFilePath(configFileName)
|
|
21
40
|
}
|
|
22
|
-
let codegenConfig
|
|
23
41
|
|
|
24
42
|
try {
|
|
25
|
-
|
|
43
|
+
return toArray(await importCodgenConfig(codegenPath))
|
|
26
44
|
} catch (error) {
|
|
45
|
+
console.log(error)
|
|
27
46
|
throw new Error(`❌ There is no ${chalk.bold(configFileName)} file`)
|
|
28
47
|
}
|
|
29
|
-
|
|
30
|
-
return toArray(codegenConfig)
|
|
31
48
|
}
|
|
32
49
|
|
|
33
|
-
|
|
50
|
+
export default readConfig
|
|
@@ -1,11 +1,15 @@
|
|
|
1
|
-
|
|
1
|
+
import getRelativeFilePath from '../utils/get-relative-file-path.js'
|
|
2
2
|
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
export const createGetMonolithSchemaPathResolver =
|
|
4
|
+
relativeFilePathResolver => schemaPath => {
|
|
5
|
+
const schemaPathResolution = relativeFilePathResolver(
|
|
6
|
+
`${schemaPath}/schema.graphql`
|
|
7
|
+
)
|
|
7
8
|
|
|
8
|
-
|
|
9
|
-
}
|
|
9
|
+
return { target: schemaPath, schemaPath, schemaPathResolution }
|
|
10
|
+
}
|
|
10
11
|
|
|
11
|
-
|
|
12
|
+
const getMonolithSchemaPath =
|
|
13
|
+
createGetMonolithSchemaPathResolver(getRelativeFilePath)
|
|
14
|
+
|
|
15
|
+
export default getMonolithSchemaPath
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { jest } from '@jest/globals'
|
|
2
|
+
|
|
3
|
+
import { createGetMonolithSchemaPathResolver } from './get-monolith-schema-path'
|
|
4
|
+
|
|
5
|
+
const schemaPathResolution =
|
|
6
|
+
'home/users/alexvcasillas/toptal/screening-wizard/src/modules/graphql/schema.graphql'
|
|
7
|
+
const getRelativeFilePathMock = jest.fn(() => schemaPathResolution)
|
|
8
|
+
const getMonolithSchemaPath = createGetMonolithSchemaPathResolver(
|
|
9
|
+
getRelativeFilePathMock
|
|
10
|
+
)
|
|
11
|
+
|
|
12
|
+
describe('getMonolithSchemaPath', () => {
|
|
13
|
+
it('returns target, schemaPath and schemaPathResolution', () => {
|
|
14
|
+
const schemaPath = 'src/modules/graphql'
|
|
15
|
+
|
|
16
|
+
expect(getMonolithSchemaPath(schemaPath)).toEqual({
|
|
17
|
+
target: schemaPath,
|
|
18
|
+
schemaPath,
|
|
19
|
+
schemaPathResolution,
|
|
20
|
+
})
|
|
21
|
+
})
|
|
22
|
+
})
|
|
@@ -1,14 +1,22 @@
|
|
|
1
|
-
|
|
1
|
+
import { createRequire } from 'module'
|
|
2
|
+
|
|
3
|
+
const localRequire = createRequire(import.meta.url)
|
|
4
|
+
|
|
5
|
+
export const createGetMonorepoSchemaPathResolver = pathResolver => schema => {
|
|
2
6
|
// @toptal/modularity-template-graphql/talent -> talent
|
|
3
7
|
const target = schema.split('/').pop()
|
|
4
8
|
// @toptal/modularity-template-graphql/talent -> @toptal/modularity-template-graphql
|
|
5
9
|
const schemaPath = schema.split('/').slice(0, 2).join('/')
|
|
6
10
|
|
|
7
|
-
const schemaPathResolution =
|
|
11
|
+
const schemaPathResolution = pathResolver(
|
|
8
12
|
`${schemaPath}/${target}/schema.graphql`
|
|
9
13
|
)
|
|
10
14
|
|
|
11
15
|
return { target, schemaPath, schemaPathResolution }
|
|
12
16
|
}
|
|
13
17
|
|
|
14
|
-
|
|
18
|
+
const getMonorepoSchemaPath = createGetMonorepoSchemaPathResolver(
|
|
19
|
+
localRequire.resolve
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
export default getMonorepoSchemaPath
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { jest } from '@jest/globals'
|
|
2
|
+
|
|
3
|
+
import { createGetMonorepoSchemaPathResolver } from './get-monorepo-schema-path'
|
|
4
|
+
|
|
5
|
+
const pathResolverMock = jest.fn(
|
|
6
|
+
() => 'home/users/johndoe/toptal/libs/graphql/schema.graphql'
|
|
7
|
+
)
|
|
8
|
+
const getMonorepoSchemaPath =
|
|
9
|
+
createGetMonorepoSchemaPathResolver(pathResolverMock)
|
|
10
|
+
|
|
11
|
+
describe('getMonorepoSchemaPath', () => {
|
|
12
|
+
it('returns target, schemaPath and schemaPathResolution', () => {
|
|
13
|
+
const schemaPath = '@toptal/modularity-template-graphql/talent'
|
|
14
|
+
|
|
15
|
+
expect(getMonorepoSchemaPath(schemaPath)).toEqual({
|
|
16
|
+
target: 'talent',
|
|
17
|
+
schemaPath: '@toptal/modularity-template-graphql',
|
|
18
|
+
schemaPathResolution:
|
|
19
|
+
'home/users/johndoe/toptal/libs/graphql/schema.graphql',
|
|
20
|
+
})
|
|
21
|
+
})
|
|
22
|
+
})
|
|
@@ -1,14 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
utils: { checkIfMonorepo },
|
|
3
|
-
} = require('@toptal/davinci-monorepo')
|
|
1
|
+
import monorepo from '@toptal/davinci-monorepo'
|
|
4
2
|
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
import getMonorepoSchemaPath from './get-monorepo-schema-path.js'
|
|
4
|
+
import getMonolithSchemaPath from './get-monolith-schema-path.js'
|
|
5
|
+
|
|
6
|
+
const { checkIfMonorepo } = monorepo.utils
|
|
7
7
|
|
|
8
8
|
const getSchemaPath = schema => {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
if (checkIfMonorepo({ considerYarnWorkspaces: true })) {
|
|
10
|
+
return getMonorepoSchemaPath(schema)
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
return getMonolithSchemaPath(schema)
|
|
12
14
|
}
|
|
13
15
|
|
|
14
|
-
|
|
16
|
+
export default getSchemaPath
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
import { Storage } from '@google-cloud/storage'
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
import getRelativeFilePath from '../utils/get-relative-file-path.js'
|
|
4
|
+
import parseGSURI from '../utils/parse-gs-uri.js'
|
|
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
|
+
export default gsSchemaLoader
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import chalk from 'chalk'
|
|
2
|
+
import { existsSync, copyFileSync, mkdirSync } from 'fs'
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
import gsSchemaLoader from './gs-schema-loader.js'
|
|
5
|
+
import getRelativeFilePath from '../utils/get-relative-file-path.js'
|
|
6
|
+
import {
|
|
7
7
|
isSchemaFromBucket,
|
|
8
8
|
isLocalSchema,
|
|
9
9
|
isSchemaFromHttp,
|
|
10
|
-
}
|
|
10
|
+
} from '../utils/detect-schema-source.js'
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
export default 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
|
-
const isSchemaFromBucket = schema => {
|
|
1
|
+
export const isSchemaFromBucket = schema => {
|
|
2
2
|
return schema.startsWith('gs://')
|
|
3
3
|
}
|
|
4
4
|
|
|
5
|
-
const isSchemaFromHttp = schema => {
|
|
5
|
+
export const isSchemaFromHttp = schema => {
|
|
6
6
|
return schema.startsWith('https://')
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
-
const isLocalSchema = schema => {
|
|
9
|
+
export const isLocalSchema = schema => {
|
|
10
10
|
return !isSchemaFromBucket(schema) && !isSchemaFromHttp(schema)
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
export default {
|
|
14
14
|
isSchemaFromBucket,
|
|
15
15
|
isSchemaFromHttp,
|
|
16
16
|
isLocalSchema,
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
import {
|
|
2
2
|
isSchemaFromBucket,
|
|
3
3
|
isSchemaFromHttp,
|
|
4
4
|
isLocalSchema,
|
|
5
|
-
}
|
|
5
|
+
} from './detect-schema-source.js'
|
|
6
6
|
|
|
7
7
|
const gsBucketSchema = 'gs://toptal.net/gateway/graphql/talent'
|
|
8
8
|
const httpSchema = 'https://toptal.net/gateway/graphql/talent'
|
package/src/utils/to-array.js
CHANGED
|
@@ -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
|
-
})
|