@constructive-io/graphql-codegen 2.17.41 → 2.17.43
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/codegen.js +3 -3
- package/esm/codegen.js +3 -3
- package/esm/gql.js +7 -6
- package/gql.js +7 -6
- package/package.json +5 -6
package/codegen.js
CHANGED
|
@@ -206,11 +206,11 @@ async function runCodegen(opts, cwd) {
|
|
|
206
206
|
filename: sdkFile,
|
|
207
207
|
schema: schema,
|
|
208
208
|
documents,
|
|
209
|
-
config: { scalars: options.scalars || {} },
|
|
209
|
+
config: { scalars: options.scalars || {}, dedupeOperationSuffix: true },
|
|
210
210
|
plugins: [
|
|
211
211
|
{ typescript: {} },
|
|
212
212
|
{ 'typescript-operations': {} },
|
|
213
|
-
{ 'typescript-graphql-request': {} }
|
|
213
|
+
{ 'typescript-graphql-request': { dedupeOperationSuffix: true } }
|
|
214
214
|
],
|
|
215
215
|
pluginMap: {
|
|
216
216
|
typescript: typescriptPlugin,
|
|
@@ -243,7 +243,7 @@ async function runCodegen(opts, cwd) {
|
|
|
243
243
|
filename: reactQueryFile,
|
|
244
244
|
schema: schema,
|
|
245
245
|
documents,
|
|
246
|
-
config: rqConfig,
|
|
246
|
+
config: { ...rqConfig, dedupeOperationSuffix: true },
|
|
247
247
|
plugins: [
|
|
248
248
|
{ typescript: {} },
|
|
249
249
|
{ 'typescript-operations': {} },
|
package/esm/codegen.js
CHANGED
|
@@ -166,11 +166,11 @@ export async function runCodegen(opts, cwd) {
|
|
|
166
166
|
filename: sdkFile,
|
|
167
167
|
schema: schema,
|
|
168
168
|
documents,
|
|
169
|
-
config: { scalars: options.scalars || {} },
|
|
169
|
+
config: { scalars: options.scalars || {}, dedupeOperationSuffix: true },
|
|
170
170
|
plugins: [
|
|
171
171
|
{ typescript: {} },
|
|
172
172
|
{ 'typescript-operations': {} },
|
|
173
|
-
{ 'typescript-graphql-request': {} }
|
|
173
|
+
{ 'typescript-graphql-request': { dedupeOperationSuffix: true } }
|
|
174
174
|
],
|
|
175
175
|
pluginMap: {
|
|
176
176
|
typescript: typescriptPlugin,
|
|
@@ -203,7 +203,7 @@ export async function runCodegen(opts, cwd) {
|
|
|
203
203
|
filename: reactQueryFile,
|
|
204
204
|
schema: schema,
|
|
205
205
|
documents,
|
|
206
|
-
config: rqConfig,
|
|
206
|
+
config: { ...rqConfig, dedupeOperationSuffix: true },
|
|
207
207
|
plugins: [
|
|
208
208
|
{ typescript: {} },
|
|
209
209
|
{ 'typescript-operations': {} },
|
package/esm/gql.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
// TODO: use inflection for all the things
|
|
2
2
|
// const { singularize } = require('inflection');
|
|
3
3
|
import * as t from 'gql-ast';
|
|
4
|
-
// @ts-ignore
|
|
5
4
|
import inflection from 'inflection';
|
|
6
|
-
import plz from 'pluralize';
|
|
7
5
|
const NON_MUTABLE_PROPS = [
|
|
8
6
|
'id',
|
|
9
7
|
'createdAt',
|
|
@@ -58,6 +56,9 @@ function extractNamedTypeName(node) {
|
|
|
58
56
|
n = n.type;
|
|
59
57
|
return n && n.name ? n.name : null;
|
|
60
58
|
}
|
|
59
|
+
function singularModel(name) {
|
|
60
|
+
return inflection.singularize(name);
|
|
61
|
+
}
|
|
61
62
|
export const createGqlMutation = ({ operationName, mutationName, selectArgs, variableDefinitions, modelName, selections, useModel = true, }) => {
|
|
62
63
|
const opSel = !modelName
|
|
63
64
|
? [
|
|
@@ -425,7 +426,7 @@ export const createOne = ({ operationName, mutation, selection, }, typeNameOverr
|
|
|
425
426
|
console.log('no input field for mutation for ' + mutationName);
|
|
426
427
|
return;
|
|
427
428
|
}
|
|
428
|
-
const modelName = inflection.camelize([
|
|
429
|
+
const modelName = inflection.camelize([singularModel(mutation.model)].join('_'), true);
|
|
429
430
|
const allAttrs = objectToArray(mutation.properties.input.properties[modelName].properties);
|
|
430
431
|
const attrs = allAttrs.filter((field) => field.name === 'id' ? Boolean(field.isNotNull) : !NON_MUTABLE_PROPS.includes(field.name));
|
|
431
432
|
const useRaw = selection?.mutationInputMode === 'raw';
|
|
@@ -521,7 +522,7 @@ export const patchOne = ({ operationName, mutation, selection, }, typeNameOverri
|
|
|
521
522
|
console.log('no input field for mutation for ' + mutationName);
|
|
522
523
|
return;
|
|
523
524
|
}
|
|
524
|
-
const modelName = inflection.camelize([
|
|
525
|
+
const modelName = inflection.camelize([singularModel(mutation.model)].join('_'), true);
|
|
525
526
|
// @ts-ignore
|
|
526
527
|
const allAttrs = objectToArray(mutation.properties.input.properties['patch']?.properties || {});
|
|
527
528
|
const patchAttrs = allAttrs.filter(
|
|
@@ -530,7 +531,7 @@ export const patchOne = ({ operationName, mutation, selection, }, typeNameOverri
|
|
|
530
531
|
const patchByAttrs = objectToArray(mutation.properties.input.properties).filter((n) => n.name !== 'patch');
|
|
531
532
|
const patchers = patchByAttrs.map((p) => p.name);
|
|
532
533
|
const useCollapsedOpt = selection?.mutationInputMode === 'patchCollapsed';
|
|
533
|
-
const ModelPascal = inflection.camelize(
|
|
534
|
+
const ModelPascal = inflection.camelize(singularModel(mutation.model), false);
|
|
534
535
|
const patchTypeName = `${ModelPascal}Patch`;
|
|
535
536
|
const inputTypeName = resolveTypeName('input', mutation.properties?.input?.type || mutation.properties?.input, typeNameOverrides);
|
|
536
537
|
let unresolved = 0;
|
|
@@ -645,7 +646,7 @@ export const deleteOne = ({ operationName, mutation, }, typeNameOverrides, typeI
|
|
|
645
646
|
console.log('no input field for mutation for ' + mutationName);
|
|
646
647
|
return;
|
|
647
648
|
}
|
|
648
|
-
const modelName = inflection.camelize([
|
|
649
|
+
const modelName = inflection.camelize([singularModel(mutation.model)].join('_'), true);
|
|
649
650
|
// @ts-ignore
|
|
650
651
|
const deleteAttrs = objectToArray(mutation.properties.input.properties);
|
|
651
652
|
const inputTypeName = resolveTypeName('input', mutation.properties?.input?.type || mutation.properties?.input, typeNameOverrides);
|
package/gql.js
CHANGED
|
@@ -41,9 +41,7 @@ exports.getSelections = getSelections;
|
|
|
41
41
|
// TODO: use inflection for all the things
|
|
42
42
|
// const { singularize } = require('inflection');
|
|
43
43
|
const t = __importStar(require("gql-ast"));
|
|
44
|
-
// @ts-ignore
|
|
45
44
|
const inflection_1 = __importDefault(require("inflection"));
|
|
46
|
-
const pluralize_1 = __importDefault(require("pluralize"));
|
|
47
45
|
const NON_MUTABLE_PROPS = [
|
|
48
46
|
'id',
|
|
49
47
|
'createdAt',
|
|
@@ -98,6 +96,9 @@ function extractNamedTypeName(node) {
|
|
|
98
96
|
n = n.type;
|
|
99
97
|
return n && n.name ? n.name : null;
|
|
100
98
|
}
|
|
99
|
+
function singularModel(name) {
|
|
100
|
+
return inflection_1.default.singularize(name);
|
|
101
|
+
}
|
|
101
102
|
const createGqlMutation = ({ operationName, mutationName, selectArgs, variableDefinitions, modelName, selections, useModel = true, }) => {
|
|
102
103
|
const opSel = !modelName
|
|
103
104
|
? [
|
|
@@ -472,7 +473,7 @@ const createOne = ({ operationName, mutation, selection, }, typeNameOverrides, t
|
|
|
472
473
|
console.log('no input field for mutation for ' + mutationName);
|
|
473
474
|
return;
|
|
474
475
|
}
|
|
475
|
-
const modelName = inflection_1.default.camelize([
|
|
476
|
+
const modelName = inflection_1.default.camelize([singularModel(mutation.model)].join('_'), true);
|
|
476
477
|
const allAttrs = objectToArray(mutation.properties.input.properties[modelName].properties);
|
|
477
478
|
const attrs = allAttrs.filter((field) => field.name === 'id' ? Boolean(field.isNotNull) : !NON_MUTABLE_PROPS.includes(field.name));
|
|
478
479
|
const useRaw = selection?.mutationInputMode === 'raw';
|
|
@@ -569,7 +570,7 @@ const patchOne = ({ operationName, mutation, selection, }, typeNameOverrides, ty
|
|
|
569
570
|
console.log('no input field for mutation for ' + mutationName);
|
|
570
571
|
return;
|
|
571
572
|
}
|
|
572
|
-
const modelName = inflection_1.default.camelize([
|
|
573
|
+
const modelName = inflection_1.default.camelize([singularModel(mutation.model)].join('_'), true);
|
|
573
574
|
// @ts-ignore
|
|
574
575
|
const allAttrs = objectToArray(mutation.properties.input.properties['patch']?.properties || {});
|
|
575
576
|
const patchAttrs = allAttrs.filter(
|
|
@@ -578,7 +579,7 @@ const patchOne = ({ operationName, mutation, selection, }, typeNameOverrides, ty
|
|
|
578
579
|
const patchByAttrs = objectToArray(mutation.properties.input.properties).filter((n) => n.name !== 'patch');
|
|
579
580
|
const patchers = patchByAttrs.map((p) => p.name);
|
|
580
581
|
const useCollapsedOpt = selection?.mutationInputMode === 'patchCollapsed';
|
|
581
|
-
const ModelPascal = inflection_1.default.camelize(
|
|
582
|
+
const ModelPascal = inflection_1.default.camelize(singularModel(mutation.model), false);
|
|
582
583
|
const patchTypeName = `${ModelPascal}Patch`;
|
|
583
584
|
const inputTypeName = resolveTypeName('input', mutation.properties?.input?.type || mutation.properties?.input, typeNameOverrides);
|
|
584
585
|
let unresolved = 0;
|
|
@@ -694,7 +695,7 @@ const deleteOne = ({ operationName, mutation, }, typeNameOverrides, typeIndex) =
|
|
|
694
695
|
console.log('no input field for mutation for ' + mutationName);
|
|
695
696
|
return;
|
|
696
697
|
}
|
|
697
|
-
const modelName = inflection_1.default.camelize([
|
|
698
|
+
const modelName = inflection_1.default.camelize([singularModel(mutation.model)].join('_'), true);
|
|
698
699
|
// @ts-ignore
|
|
699
700
|
const deleteAttrs = objectToArray(mutation.properties.input.properties);
|
|
700
701
|
const inputTypeName = resolveTypeName('input', mutation.properties?.input?.type || mutation.properties?.input, typeNameOverrides);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@constructive-io/graphql-codegen",
|
|
3
|
-
"version": "2.17.
|
|
3
|
+
"version": "2.17.43",
|
|
4
4
|
"description": "Generate queries and mutations for use with Graphile",
|
|
5
5
|
"author": "Constructive <developers@constructive.io>",
|
|
6
6
|
"main": "index.js",
|
|
@@ -29,9 +29,9 @@
|
|
|
29
29
|
"test:watch": "jest --watch"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"@constructive-io/graphql-test": "^2.11.
|
|
32
|
+
"@constructive-io/graphql-test": "^2.11.36",
|
|
33
33
|
"@types/babel__generator": "^7.27.0",
|
|
34
|
-
"@types/
|
|
34
|
+
"@types/inflection": "^2.0.0",
|
|
35
35
|
"makage": "^0.1.9"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
@@ -48,8 +48,7 @@
|
|
|
48
48
|
"graphql-request": "6.1.0",
|
|
49
49
|
"graphql-tag": "2.12.6",
|
|
50
50
|
"inflection": "^1.12.0",
|
|
51
|
-
"introspectron": "^2.14.
|
|
52
|
-
"pluralize": "^8.0.0"
|
|
51
|
+
"introspectron": "^2.14.41"
|
|
53
52
|
},
|
|
54
53
|
"keywords": [
|
|
55
54
|
"graphql",
|
|
@@ -58,5 +57,5 @@
|
|
|
58
57
|
"graphile",
|
|
59
58
|
"constructive"
|
|
60
59
|
],
|
|
61
|
-
"gitHead": "
|
|
60
|
+
"gitHead": "bec3240e4e0f93b8edb386734eeb560403f574da"
|
|
62
61
|
}
|