@toptal/davinci-graphql-codegen 0.1.1-alpha-feature-comm-620-graphql-codegen.1441 → 0.1.2-alpha-feature-comm-745-monolith-support.1
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 +7 -0
- package/bin/davinci-graphql-codegen.js +0 -23
- package/package.json +3 -3
- package/src/commands/generate-operations.js +2 -3
- package/src/commands/generate-schema.js +17 -4
- package/src/{shared-config/shared-config.js → config/config.js} +0 -0
- package/src/config/index.js +3 -0
- package/src/generate/operations.js +6 -3
- package/src/generate/schema.js +3 -2
- package/src/read-config/read-config.js +18 -6
- package/src/services/gs-schema-loader.js +2 -2
- package/src/services/schema-loader.js +12 -3
- package/src/{services → utils}/detect-schema-source.js +0 -0
- package/src/{services → utils}/get-relative-file-path.js +0 -0
- package/src/{services → utils}/parse-gs-uri.js +0 -0
- package/src/{services → utils}/process-args.js +2 -5
- package/src/{services → utils}/to-array.js +0 -0
- package/src/shared-config/index.js +0 -3
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
# @toptal/davinci-graphql-codegen
|
|
2
|
+
|
|
3
|
+
## 0.1.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#1153](https://github.com/toptal/davinci/pull/1153) [`b51f6179`](https://github.com/toptal/davinci/commit/b51f61791640b552b3d861cfe14fcb3e6ebedb56) Thanks [@alexvcasillas](https://github.com/alexvcasillas)! - Release for GraphQL Codegen
|
|
@@ -9,26 +9,3 @@ cliEngine.loadCommands([
|
|
|
9
9
|
codegenGenerateSchemaCreator,
|
|
10
10
|
codegenGenerateOperationsCreator
|
|
11
11
|
])
|
|
12
|
-
|
|
13
|
-
cliEngine.help(
|
|
14
|
-
() => `
|
|
15
|
-
Commands:
|
|
16
|
-
|
|
17
|
-
help [command...] Provides help for a given command
|
|
18
|
-
exit Exits application
|
|
19
|
-
generate-operations generate graphql operation types based off generated schemas
|
|
20
|
-
generate-schema generate graphql schemas
|
|
21
|
-
`
|
|
22
|
-
)
|
|
23
|
-
|
|
24
|
-
const args = cliEngine.bootstrap({ use: 'minimist' })
|
|
25
|
-
|
|
26
|
-
// eslint-disable-next-line @typescript-eslint/no-shadow
|
|
27
|
-
cliEngine.catchErrorCommand((args, cb) => {
|
|
28
|
-
cliEngine.execCommand(`${args.commands.join(' ')}`)
|
|
29
|
-
cb()
|
|
30
|
-
})
|
|
31
|
-
|
|
32
|
-
if (args._ && args._.length) {
|
|
33
|
-
cliEngine.execCommand(`${args._.join(' ')}`)
|
|
34
|
-
}
|
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.1+989f544e",
|
|
4
4
|
"description": "Codegen",
|
|
5
5
|
"author": "Toptal",
|
|
6
6
|
"license": "ISC",
|
|
@@ -28,9 +28,9 @@
|
|
|
28
28
|
"@graphql-codegen/typescript-operations": "^2.1.4",
|
|
29
29
|
"@graphql-codegen/typescript-resolvers": "^2.2.1",
|
|
30
30
|
"@graphql-typed-document-node/core": "^3.1.0",
|
|
31
|
-
"@toptal/davinci-cli-shared": "1.5.1-alpha-feature-comm-
|
|
31
|
+
"@toptal/davinci-cli-shared": "1.5.1-alpha-feature-comm-745-monolith-support.111+989f544e",
|
|
32
32
|
"chalk": "^4.1.2",
|
|
33
33
|
"graphql": "^15.7.1"
|
|
34
34
|
},
|
|
35
|
-
"gitHead": "
|
|
35
|
+
"gitHead": "989f544e0c1e14ccd4d1f8a5d559cb091697d864"
|
|
36
36
|
}
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
const { generateOperations } = require('../generate')
|
|
2
2
|
const readConfig = require('../read-config')
|
|
3
|
-
const processArgs = require('../
|
|
3
|
+
const processArgs = require('../utils/process-args')
|
|
4
4
|
|
|
5
5
|
const args = processArgs(process.argv.slice(2))
|
|
6
6
|
const operation = args.operation
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
async function codegenGenerateOperations() {
|
|
8
|
+
const codegenGenerateOperations = async () => {
|
|
10
9
|
const codegen = await readConfig()
|
|
11
10
|
|
|
12
11
|
switch (operation) {
|
|
@@ -1,14 +1,19 @@
|
|
|
1
|
+
const chalk = require('chalk')
|
|
2
|
+
|
|
1
3
|
const { generateSchema } = require('../generate')
|
|
2
4
|
const readConfig = require('../read-config')
|
|
3
|
-
const processArgs = require('../
|
|
5
|
+
const processArgs = require('../utils/process-args')
|
|
4
6
|
|
|
5
7
|
const args = processArgs(process.argv.slice(2))
|
|
8
|
+
|
|
9
|
+
console.log(args)
|
|
10
|
+
|
|
6
11
|
const operation = args.operation
|
|
7
12
|
const projectId = args.projectId || 'toptal-hub'
|
|
13
|
+
const configDir = args.configDir
|
|
8
14
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const codegen = await readConfig()
|
|
15
|
+
const codegenGenerateSchema = async () => {
|
|
16
|
+
const codegen = await readConfig(configDir)
|
|
12
17
|
|
|
13
18
|
switch (operation) {
|
|
14
19
|
case 'generate-schema': {
|
|
@@ -30,6 +35,14 @@ async function codegenGenerateSchema() {
|
|
|
30
35
|
const codegenGenerateSchemaCreator = {
|
|
31
36
|
command: 'generate-schema',
|
|
32
37
|
description: 'generate graphql schemas',
|
|
38
|
+
options: [
|
|
39
|
+
{
|
|
40
|
+
label: `Custom dir where ${chalk.green(
|
|
41
|
+
'codegen.json'
|
|
42
|
+
)} config file is located`,
|
|
43
|
+
name: '--configDir'
|
|
44
|
+
}
|
|
45
|
+
],
|
|
33
46
|
action: () => {
|
|
34
47
|
codegenGenerateSchema()
|
|
35
48
|
}
|
|
File without changes
|
|
@@ -3,8 +3,8 @@ const { generate } = require('@graphql-codegen/cli')
|
|
|
3
3
|
const {
|
|
4
4
|
commonOperationTypesConfig,
|
|
5
5
|
autoGenerationComments
|
|
6
|
-
} = require('../
|
|
7
|
-
const getRelativeFilePath = require('../
|
|
6
|
+
} = require('../config/config')
|
|
7
|
+
const getRelativeFilePath = require('../utils/get-relative-file-path')
|
|
8
8
|
|
|
9
9
|
const generateOperations = async ({ schema, documents }) => {
|
|
10
10
|
const docsPath = getRelativeFilePath(documents)
|
|
@@ -12,7 +12,10 @@ const generateOperations = async ({ schema, documents }) => {
|
|
|
12
12
|
// @toptal/modularity-template-graphql/talent -> talent
|
|
13
13
|
const target = schema.split('/').pop()
|
|
14
14
|
// @toptal/modularity-template-graphql/talent -> @toptal/modularity-template-graphql/talent
|
|
15
|
-
const schemaPath = schema
|
|
15
|
+
const schemaPath = schema
|
|
16
|
+
.split('/')
|
|
17
|
+
.slice(0, 2)
|
|
18
|
+
.join('/')
|
|
16
19
|
|
|
17
20
|
await generate(
|
|
18
21
|
{
|
package/src/generate/schema.js
CHANGED
|
@@ -4,8 +4,9 @@ const chalk = require('chalk')
|
|
|
4
4
|
const {
|
|
5
5
|
commonSchemaTypesConfig,
|
|
6
6
|
autoGenerationComments
|
|
7
|
-
} = require('../
|
|
7
|
+
} = require('../config/config')
|
|
8
8
|
const schemaLoader = require('../services/schema-loader')
|
|
9
|
+
const { isSchemaFromHttp } = require('../utils/detect-schema-source')
|
|
9
10
|
|
|
10
11
|
const generateSchema = async ({ schema, target, projectId }) => {
|
|
11
12
|
const {
|
|
@@ -23,7 +24,7 @@ const generateSchema = async ({ schema, target, projectId }) => {
|
|
|
23
24
|
// plugins: ['introspection']
|
|
24
25
|
// },
|
|
25
26
|
[destinationPathTs]: {
|
|
26
|
-
schema: schema
|
|
27
|
+
schema: isSchemaFromHttp(schema)
|
|
27
28
|
? schema
|
|
28
29
|
: require.resolve(schemaPath),
|
|
29
30
|
plugins: [
|
|
@@ -1,13 +1,25 @@
|
|
|
1
1
|
const chalk = require('chalk')
|
|
2
2
|
|
|
3
|
-
const getRelativeFilePath = require('../
|
|
4
|
-
const toArray = require('../
|
|
3
|
+
const getRelativeFilePath = require('../utils/get-relative-file-path')
|
|
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,7 +1,7 @@
|
|
|
1
1
|
const { Storage } = require('@google-cloud/storage')
|
|
2
2
|
|
|
3
|
-
const getRelativeFilePath = require('../
|
|
4
|
-
const parseGSURI = require('
|
|
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
|
|
@@ -1,14 +1,23 @@
|
|
|
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
|
-
const getRelativeFilePath = require('
|
|
5
|
+
const getRelativeFilePath = require('../utils/get-relative-file-path')
|
|
5
6
|
const {
|
|
6
7
|
isSchemaFromBucket,
|
|
7
8
|
isLocalSchema,
|
|
8
9
|
isSchemaFromHttp
|
|
9
|
-
} = require('
|
|
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`)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -2,20 +2,17 @@ const processArgs = args => {
|
|
|
2
2
|
const obj = {}
|
|
3
3
|
|
|
4
4
|
args.forEach(arg => {
|
|
5
|
-
if (arg.includes('generate
|
|
5
|
+
if (arg.includes('generate-')) {
|
|
6
6
|
obj.operation = arg
|
|
7
7
|
|
|
8
8
|
return
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
// Eg: Parts -> ['projectId', 'toptal-hub']
|
|
12
|
-
const
|
|
12
|
+
const [key, value] = arg
|
|
13
13
|
.split(/(?:--)([a-zA-Z]*)(?:=)([a-zA-Z-]*)/i)
|
|
14
14
|
.filter(Boolean)
|
|
15
15
|
|
|
16
|
-
const key = parts[0]
|
|
17
|
-
const value = parts[1]
|
|
18
|
-
|
|
19
16
|
obj[key] = value
|
|
20
17
|
})
|
|
21
18
|
|
|
File without changes
|