@toptal/davinci-graphql-codegen 0.1.1-alpha-feature-comm-620-graphql-codegen.1451 → 0.1.2-alpha-feature-comm-745-monolith-support.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 +7 -0
- package/package.json +3 -3
- 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/generate/schema.js +2 -1
- 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/src/utils/process-args.js +1 -4
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
|
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.2+8fc0ca70",
|
|
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.112+8fc0ca70",
|
|
32
32
|
"chalk": "^4.1.2",
|
|
33
33
|
"graphql": "^15.7.1"
|
|
34
34
|
},
|
|
35
|
-
"gitHead": "
|
|
35
|
+
"gitHead": "8fc0ca7045783a208b099ef47f4c5bd498cc7e26"
|
|
36
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
|
+
: `${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',
|
package/src/generate/schema.js
CHANGED
|
@@ -6,6 +6,7 @@ const {
|
|
|
6
6
|
autoGenerationComments
|
|
7
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: [
|
|
@@ -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`)
|
|
@@ -9,13 +9,10 @@ const processArgs = args => {
|
|
|
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
|
|