@toptal/davinci-graphql-codegen 0.1.1 → 0.1.2-alpha-feature-comm-745-monolith-support.3
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/package.json +7 -6
- package/src/commands/generate-operations.js +12 -1
- package/src/commands/generate-schema.js +13 -1
- package/src/generate/operations.js +21 -8
- package/src/read-config/read-config.js +16 -4
- package/src/services/schema-loader.js +10 -1
- package/src/utils/is-package.js +3 -0
- package/dist-package/package.json +0 -35
- package/src/utils/detect-schema-source.test.js +0 -29
- package/src/utils/parse-gs-uri.test.js +0 -12
- package/src/utils/process-args.test.js +0 -10
- package/src/utils/to-array.test.js +0 -15
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@toptal/davinci-graphql-codegen",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2-alpha-feature-comm-745-monolith-support.3+a01b4a66",
|
|
4
4
|
"description": "Codegen",
|
|
5
5
|
"author": "Toptal",
|
|
6
6
|
"license": "ISC",
|
|
@@ -20,9 +20,6 @@
|
|
|
20
20
|
"sideEffects": false,
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"@google-cloud/storage": "^5.16.1",
|
|
23
|
-
"@toptal/davinci-cli-shared": "^1.5.0",
|
|
24
|
-
"chalk": "^4.1.2",
|
|
25
|
-
"graphql": "^15.7.1",
|
|
26
23
|
"@graphql-codegen/add": "^3.1.0",
|
|
27
24
|
"@graphql-codegen/cli": "^2.2.0",
|
|
28
25
|
"@graphql-codegen/introspection": "^2.1.0",
|
|
@@ -30,6 +27,10 @@
|
|
|
30
27
|
"@graphql-codegen/typescript": "^2.2.2",
|
|
31
28
|
"@graphql-codegen/typescript-operations": "^2.1.4",
|
|
32
29
|
"@graphql-codegen/typescript-resolvers": "^2.2.1",
|
|
33
|
-
"@graphql-typed-document-node/core": "^3.1.0"
|
|
34
|
-
|
|
30
|
+
"@graphql-typed-document-node/core": "^3.1.0",
|
|
31
|
+
"@toptal/davinci-cli-shared": "1.5.1-alpha-feature-comm-745-monolith-support.113+a01b4a66",
|
|
32
|
+
"chalk": "^4.1.2",
|
|
33
|
+
"graphql": "^15.7.1"
|
|
34
|
+
},
|
|
35
|
+
"gitHead": "a01b4a66eafbf5a935e54774fab61433717d2fb2"
|
|
35
36
|
}
|
|
@@ -1,12 +1,15 @@
|
|
|
1
|
+
const chalk = require('chalk')
|
|
2
|
+
|
|
1
3
|
const { generateOperations } = require('../generate')
|
|
2
4
|
const readConfig = require('../read-config')
|
|
3
5
|
const processArgs = require('../utils/process-args')
|
|
4
6
|
|
|
5
7
|
const args = processArgs(process.argv.slice(2))
|
|
6
8
|
const operation = args.operation
|
|
9
|
+
const configDir = args.configDir
|
|
7
10
|
|
|
8
11
|
const codegenGenerateOperations = async () => {
|
|
9
|
-
const codegen = await readConfig()
|
|
12
|
+
const codegen = await readConfig(configDir)
|
|
10
13
|
|
|
11
14
|
switch (operation) {
|
|
12
15
|
case 'generate-operations':
|
|
@@ -25,6 +28,14 @@ const codegenGenerateOperations = async () => {
|
|
|
25
28
|
const codegenGenerateOperationsCreator = {
|
|
26
29
|
command: 'generate-operations',
|
|
27
30
|
description: 'generate graphql operation types based off generated schemas',
|
|
31
|
+
options: [
|
|
32
|
+
{
|
|
33
|
+
label: `Custom dir where ${chalk.green(
|
|
34
|
+
'codegen.json'
|
|
35
|
+
)} config file is located`,
|
|
36
|
+
name: '--configDir'
|
|
37
|
+
}
|
|
38
|
+
],
|
|
28
39
|
action: () => {
|
|
29
40
|
codegenGenerateOperations()
|
|
30
41
|
}
|
|
@@ -1,13 +1,17 @@
|
|
|
1
|
+
const chalk = require('chalk')
|
|
2
|
+
|
|
1
3
|
const { generateSchema } = require('../generate')
|
|
2
4
|
const readConfig = require('../read-config')
|
|
3
5
|
const processArgs = require('../utils/process-args')
|
|
4
6
|
|
|
5
7
|
const args = processArgs(process.argv.slice(2))
|
|
8
|
+
|
|
6
9
|
const operation = args.operation
|
|
7
10
|
const projectId = args.projectId || 'toptal-hub'
|
|
11
|
+
const configDir = args.configDir
|
|
8
12
|
|
|
9
13
|
const codegenGenerateSchema = async () => {
|
|
10
|
-
const codegen = await readConfig()
|
|
14
|
+
const codegen = await readConfig(configDir)
|
|
11
15
|
|
|
12
16
|
switch (operation) {
|
|
13
17
|
case 'generate-schema': {
|
|
@@ -29,6 +33,14 @@ const codegenGenerateSchema = async () => {
|
|
|
29
33
|
const codegenGenerateSchemaCreator = {
|
|
30
34
|
command: 'generate-schema',
|
|
31
35
|
description: 'generate graphql schemas',
|
|
36
|
+
options: [
|
|
37
|
+
{
|
|
38
|
+
label: `Custom dir where ${chalk.green(
|
|
39
|
+
'codegen.json'
|
|
40
|
+
)} config file is located`,
|
|
41
|
+
name: '--configDir'
|
|
42
|
+
}
|
|
43
|
+
],
|
|
32
44
|
action: () => {
|
|
33
45
|
codegenGenerateSchema()
|
|
34
46
|
}
|
|
@@ -5,17 +5,30 @@ const {
|
|
|
5
5
|
autoGenerationComments
|
|
6
6
|
} = require('../config/config')
|
|
7
7
|
const getRelativeFilePath = require('../utils/get-relative-file-path')
|
|
8
|
+
const isPackage = require('../utils/is-package')
|
|
8
9
|
|
|
9
10
|
const generateOperations = async ({ schema, documents }) => {
|
|
10
11
|
const docsPath = getRelativeFilePath(documents)
|
|
11
12
|
|
|
12
|
-
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
.
|
|
18
|
-
|
|
13
|
+
let target, schemaPath
|
|
14
|
+
const isMonorepoPkg = isPackage(schema)
|
|
15
|
+
|
|
16
|
+
if (isMonorepoPkg) {
|
|
17
|
+
// @toptal/modularity-template-graphql/talent -> talent
|
|
18
|
+
target = schema.split('/').pop()
|
|
19
|
+
// @toptal/modularity-template-graphql/talent -> @toptal/modularity-template-graphql/talent
|
|
20
|
+
schemaPath = schema
|
|
21
|
+
.split('/')
|
|
22
|
+
.slice(0, 2)
|
|
23
|
+
.join('/')
|
|
24
|
+
} else {
|
|
25
|
+
//
|
|
26
|
+
target = schema
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const schemaPathResolution = isMonorepoPkg
|
|
30
|
+
? require.resolve(`${schemaPath}/${target}/schema.graphql`)
|
|
31
|
+
: getRelativeFilePath(`${target}/schema.graphql`)
|
|
19
32
|
|
|
20
33
|
await generate(
|
|
21
34
|
{
|
|
@@ -25,7 +38,7 @@ const generateOperations = async ({ schema, documents }) => {
|
|
|
25
38
|
},
|
|
26
39
|
generates: {
|
|
27
40
|
[schemaPath]: {
|
|
28
|
-
schema:
|
|
41
|
+
schema: schemaPathResolution,
|
|
29
42
|
preset: 'near-operation-file',
|
|
30
43
|
presetConfig: {
|
|
31
44
|
extension: '.ts',
|
|
@@ -3,11 +3,23 @@ const chalk = require('chalk')
|
|
|
3
3
|
const getRelativeFilePath = require('../utils/get-relative-file-path')
|
|
4
4
|
const toArray = require('../utils/to-array')
|
|
5
5
|
|
|
6
|
-
const readConfig = async
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
const readConfig = async configDir => {
|
|
7
|
+
let codegenPath
|
|
8
|
+
|
|
9
|
+
if (configDir) {
|
|
10
|
+
console.log(
|
|
11
|
+
`🔍 Searching for ${chalk.bold('codegen.json')} file in [${chalk.green(
|
|
12
|
+
configDir
|
|
13
|
+
)}] custom directory`
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
codegenPath = getRelativeFilePath(`${configDir}/codegen.json`)
|
|
17
|
+
} else {
|
|
18
|
+
console.log(`🔍 Searching for ${chalk.bold('codegen.json')} file`)
|
|
9
19
|
|
|
10
|
-
|
|
20
|
+
codegenPath = getRelativeFilePath('codegen.json')
|
|
21
|
+
}
|
|
22
|
+
let codegenConfig
|
|
11
23
|
|
|
12
24
|
try {
|
|
13
25
|
codegenConfig = require(codegenPath)
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
const
|
|
1
|
+
const chalk = require('chalk')
|
|
2
|
+
const { existsSync, copyFileSync, mkdirSync } = require('fs')
|
|
2
3
|
|
|
3
4
|
const gsSchemaLoader = require('./gs-schema-loader')
|
|
4
5
|
const getRelativeFilePath = require('../utils/get-relative-file-path')
|
|
@@ -9,6 +10,14 @@ const {
|
|
|
9
10
|
} = require('../utils/detect-schema-source')
|
|
10
11
|
|
|
11
12
|
module.exports = async (schema, target, projectId) => {
|
|
13
|
+
if (!existsSync(target)) {
|
|
14
|
+
console.log("📁 Destination target doesn't exist, creating one for you...")
|
|
15
|
+
mkdirSync(target)
|
|
16
|
+
console.log(
|
|
17
|
+
`✅ Successfully created [${chalk.green(target)}] target folder`
|
|
18
|
+
)
|
|
19
|
+
}
|
|
20
|
+
|
|
12
21
|
const schemaPath = isSchemaFromHttp(schema)
|
|
13
22
|
? schema
|
|
14
23
|
: getRelativeFilePath(`${target}/schema.graphql`)
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@toptal/davinci-graphql-codegen",
|
|
3
|
-
"version": "0.1.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": "^5.16.1",
|
|
23
|
-
"@toptal/davinci-cli-shared": "^1.5.0",
|
|
24
|
-
"chalk": "^4.1.2",
|
|
25
|
-
"graphql": "^15.7.1",
|
|
26
|
-
"@graphql-codegen/add": "^3.1.0",
|
|
27
|
-
"@graphql-codegen/cli": "^2.2.0",
|
|
28
|
-
"@graphql-codegen/introspection": "^2.1.0",
|
|
29
|
-
"@graphql-codegen/typed-document-node": "^2.1.4",
|
|
30
|
-
"@graphql-codegen/typescript": "^2.2.2",
|
|
31
|
-
"@graphql-codegen/typescript-operations": "^2.1.4",
|
|
32
|
-
"@graphql-codegen/typescript-resolvers": "^2.2.1",
|
|
33
|
-
"@graphql-typed-document-node/core": "^3.1.0"
|
|
34
|
-
}
|
|
35
|
-
}
|
|
@@ -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
|
-
})
|