@constructive-io/graphql-query 2.5.0 → 2.5.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/ast.js +4 -7
- package/esm/ast.js +4 -4
- package/esm/query-builder.js +12 -12
- package/package.json +3 -3
- package/query-builder.js +12 -15
package/ast.js
CHANGED
|
@@ -32,14 +32,11 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
32
32
|
return result;
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
-
};
|
|
38
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
36
|
exports.deleteOne = exports.patchOne = exports.createOne = exports.getOne = exports.getMany = exports.getCount = exports.getAll = void 0;
|
|
40
37
|
exports.getSelections = getSelections;
|
|
41
38
|
const t = __importStar(require("gql-ast"));
|
|
42
|
-
const inflection_1 =
|
|
39
|
+
const inflection_1 = require("inflection");
|
|
43
40
|
const custom_ast_1 = require("./custom-ast");
|
|
44
41
|
const NON_MUTABLE_PROPS = ['createdAt', 'createdBy', 'updatedAt', 'updatedBy'];
|
|
45
42
|
const objectToArray = (obj) => Object.keys(obj).map((k) => ({
|
|
@@ -320,7 +317,7 @@ const createOne = ({ mutationName, operationName, mutation, selection, }) => {
|
|
|
320
317
|
if (!mutation.properties?.input?.properties) {
|
|
321
318
|
throw new Error(`No input field for mutation: ${mutationName}`);
|
|
322
319
|
}
|
|
323
|
-
const modelName = inflection_1.
|
|
320
|
+
const modelName = (0, inflection_1.camelize)([(0, inflection_1.singularize)(mutation.model)].join('_'), true);
|
|
324
321
|
const inputProperties = mutation.properties.input
|
|
325
322
|
.properties;
|
|
326
323
|
const modelProperties = inputProperties[modelName];
|
|
@@ -366,7 +363,7 @@ const patchOne = ({ mutationName, operationName, mutation, selection, }) => {
|
|
|
366
363
|
if (!mutation.properties?.input?.properties) {
|
|
367
364
|
throw new Error(`No input field for mutation: ${mutationName}`);
|
|
368
365
|
}
|
|
369
|
-
const modelName = inflection_1.
|
|
366
|
+
const modelName = (0, inflection_1.camelize)([(0, inflection_1.singularize)(mutation.model)].join('_'), true);
|
|
370
367
|
const inputProperties = mutation.properties.input
|
|
371
368
|
.properties;
|
|
372
369
|
const patchProperties = inputProperties['patch'];
|
|
@@ -419,7 +416,7 @@ const deleteOne = ({ mutationName, operationName, mutation, }) => {
|
|
|
419
416
|
if (!mutation.properties?.input?.properties) {
|
|
420
417
|
throw new Error(`No input field for mutation: ${mutationName}`);
|
|
421
418
|
}
|
|
422
|
-
const modelName = inflection_1.
|
|
419
|
+
const modelName = (0, inflection_1.camelize)([(0, inflection_1.singularize)(mutation.model)].join('_'), true);
|
|
423
420
|
const inputProperties = mutation.properties.input
|
|
424
421
|
.properties;
|
|
425
422
|
const deleteAttrs = objectToArray(inputProperties);
|
package/esm/ast.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as t from 'gql-ast';
|
|
2
|
-
import
|
|
2
|
+
import { camelize, singularize } from 'inflection';
|
|
3
3
|
import { getCustomAst } from './custom-ast';
|
|
4
4
|
const NON_MUTABLE_PROPS = ['createdAt', 'createdBy', 'updatedAt', 'updatedBy'];
|
|
5
5
|
const objectToArray = (obj) => Object.keys(obj).map((k) => ({
|
|
@@ -276,7 +276,7 @@ export const createOne = ({ mutationName, operationName, mutation, selection, })
|
|
|
276
276
|
if (!mutation.properties?.input?.properties) {
|
|
277
277
|
throw new Error(`No input field for mutation: ${mutationName}`);
|
|
278
278
|
}
|
|
279
|
-
const modelName =
|
|
279
|
+
const modelName = camelize([singularize(mutation.model)].join('_'), true);
|
|
280
280
|
const inputProperties = mutation.properties.input
|
|
281
281
|
.properties;
|
|
282
282
|
const modelProperties = inputProperties[modelName];
|
|
@@ -321,7 +321,7 @@ export const patchOne = ({ mutationName, operationName, mutation, selection, })
|
|
|
321
321
|
if (!mutation.properties?.input?.properties) {
|
|
322
322
|
throw new Error(`No input field for mutation: ${mutationName}`);
|
|
323
323
|
}
|
|
324
|
-
const modelName =
|
|
324
|
+
const modelName = camelize([singularize(mutation.model)].join('_'), true);
|
|
325
325
|
const inputProperties = mutation.properties.input
|
|
326
326
|
.properties;
|
|
327
327
|
const patchProperties = inputProperties['patch'];
|
|
@@ -373,7 +373,7 @@ export const deleteOne = ({ mutationName, operationName, mutation, }) => {
|
|
|
373
373
|
if (!mutation.properties?.input?.properties) {
|
|
374
374
|
throw new Error(`No input field for mutation: ${mutationName}`);
|
|
375
375
|
}
|
|
376
|
-
const modelName =
|
|
376
|
+
const modelName = camelize([singularize(mutation.model)].join('_'), true);
|
|
377
377
|
const inputProperties = mutation.properties.input
|
|
378
378
|
.properties;
|
|
379
379
|
const deleteAttrs = objectToArray(inputProperties);
|
package/esm/query-builder.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { print as gqlPrint } from 'graphql';
|
|
2
|
-
import
|
|
2
|
+
import { camelize, pluralize, underscore } from 'inflection';
|
|
3
3
|
import { createOne, deleteOne, getAll, getCount, getMany, getOne, patchOne, } from './ast';
|
|
4
4
|
import { validateMetaObject } from './meta-object';
|
|
5
5
|
export * as MetaObject from './meta-object';
|
|
@@ -94,13 +94,13 @@ export class QueryBuilder {
|
|
|
94
94
|
const getInputName = (mutationType) => {
|
|
95
95
|
switch (mutationType) {
|
|
96
96
|
case 'delete': {
|
|
97
|
-
return `Delete${
|
|
97
|
+
return `Delete${camelize(this._model)}Input`;
|
|
98
98
|
}
|
|
99
99
|
case 'create': {
|
|
100
|
-
return `Create${
|
|
100
|
+
return `Create${camelize(this._model)}Input`;
|
|
101
101
|
}
|
|
102
102
|
case 'patch': {
|
|
103
|
-
return `Update${
|
|
103
|
+
return `Update${camelize(this._model)}Input`;
|
|
104
104
|
}
|
|
105
105
|
default:
|
|
106
106
|
throw new Error('Unhandled mutation type' + mutationType);
|
|
@@ -129,7 +129,7 @@ export class QueryBuilder {
|
|
|
129
129
|
getMany({ select } = {}) {
|
|
130
130
|
this._op = 'getMany';
|
|
131
131
|
this._key = this._findQuery();
|
|
132
|
-
this.queryName(
|
|
132
|
+
this.queryName(camelize(['get', underscore(this._key), 'query'].join('_'), true));
|
|
133
133
|
const defn = this._introspection[this._key];
|
|
134
134
|
this.select(select);
|
|
135
135
|
this._ast = getMany({
|
|
@@ -144,7 +144,7 @@ export class QueryBuilder {
|
|
|
144
144
|
all({ select } = {}) {
|
|
145
145
|
this._op = 'getMany';
|
|
146
146
|
this._key = this._findQuery();
|
|
147
|
-
this.queryName(
|
|
147
|
+
this.queryName(camelize(['get', underscore(this._key), 'query', 'all'].join('_'), true));
|
|
148
148
|
const defn = this._introspection[this._key];
|
|
149
149
|
this.select(select);
|
|
150
150
|
this._ast = getAll({
|
|
@@ -158,7 +158,7 @@ export class QueryBuilder {
|
|
|
158
158
|
count() {
|
|
159
159
|
this._op = 'getMany';
|
|
160
160
|
this._key = this._findQuery();
|
|
161
|
-
this.queryName(
|
|
161
|
+
this.queryName(camelize(['get', underscore(this._key), 'count', 'query'].join('_'), true));
|
|
162
162
|
const defn = this._introspection[this._key];
|
|
163
163
|
this._ast = getCount({
|
|
164
164
|
queryName: this._queryName,
|
|
@@ -170,7 +170,7 @@ export class QueryBuilder {
|
|
|
170
170
|
getOne({ select } = {}) {
|
|
171
171
|
this._op = 'getOne';
|
|
172
172
|
this._key = this._findQuery();
|
|
173
|
-
this.queryName(
|
|
173
|
+
this.queryName(camelize(['get', underscore(this._key), 'query'].join('_'), true));
|
|
174
174
|
const defn = this._introspection[this._key];
|
|
175
175
|
this.select(select);
|
|
176
176
|
this._ast = getOne({
|
|
@@ -186,7 +186,7 @@ export class QueryBuilder {
|
|
|
186
186
|
this._op = 'mutation';
|
|
187
187
|
this._mutation = 'create';
|
|
188
188
|
this._key = this._findMutation();
|
|
189
|
-
this.queryName(
|
|
189
|
+
this.queryName(camelize([underscore(this._key), 'mutation'].join('_'), true));
|
|
190
190
|
const defn = this._introspection[this._key];
|
|
191
191
|
this.select(select);
|
|
192
192
|
this._ast = createOne({
|
|
@@ -201,7 +201,7 @@ export class QueryBuilder {
|
|
|
201
201
|
this._op = 'mutation';
|
|
202
202
|
this._mutation = 'delete';
|
|
203
203
|
this._key = this._findMutation();
|
|
204
|
-
this.queryName(
|
|
204
|
+
this.queryName(camelize([underscore(this._key), 'mutation'].join('_'), true));
|
|
205
205
|
const defn = this._introspection[this._key];
|
|
206
206
|
this.select(select);
|
|
207
207
|
this._ast = deleteOne({
|
|
@@ -215,7 +215,7 @@ export class QueryBuilder {
|
|
|
215
215
|
this._op = 'mutation';
|
|
216
216
|
this._mutation = 'patch';
|
|
217
217
|
this._key = this._findMutation();
|
|
218
|
-
this.queryName(
|
|
218
|
+
this.queryName(camelize([underscore(this._key), 'mutation'].join('_'), true));
|
|
219
219
|
const defn = this._introspection[this._key];
|
|
220
220
|
this.select(select);
|
|
221
221
|
this._ast = patchOne({
|
|
@@ -375,5 +375,5 @@ function isRelationalField(fieldName, modelMeta) {
|
|
|
375
375
|
// Get getMany op name from model
|
|
376
376
|
// ie. UserSetting => userSettings
|
|
377
377
|
function modelNameToGetMany(model) {
|
|
378
|
-
return
|
|
378
|
+
return camelize(pluralize(underscore(model)), true);
|
|
379
379
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@constructive-io/graphql-query",
|
|
3
|
-
"version": "2.5.
|
|
3
|
+
"version": "2.5.1",
|
|
4
4
|
"description": "Constructive GraphQL Query",
|
|
5
5
|
"author": "Constructive <developers@constructive.io>",
|
|
6
6
|
"main": "index.js",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"ajv": "^7.0.4",
|
|
33
33
|
"gql-ast": "^2.4.6",
|
|
34
34
|
"graphql": "15.10.1",
|
|
35
|
-
"inflection": "
|
|
35
|
+
"inflection": "^3.0.2"
|
|
36
36
|
},
|
|
37
37
|
"keywords": [
|
|
38
38
|
"query",
|
|
@@ -44,5 +44,5 @@
|
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"makage": "^0.1.10"
|
|
46
46
|
},
|
|
47
|
-
"gitHead": "
|
|
47
|
+
"gitHead": "cb086f098f3d82ee9e4eced65383fc3f45253064"
|
|
48
48
|
}
|
package/query-builder.js
CHANGED
|
@@ -32,13 +32,10 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
32
32
|
return result;
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
-
};
|
|
38
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
36
|
exports.QueryBuilder = exports.MetaObject = void 0;
|
|
40
37
|
const graphql_1 = require("graphql");
|
|
41
|
-
const inflection_1 =
|
|
38
|
+
const inflection_1 = require("inflection");
|
|
42
39
|
const ast_1 = require("./ast");
|
|
43
40
|
const meta_object_1 = require("./meta-object");
|
|
44
41
|
exports.MetaObject = __importStar(require("./meta-object"));
|
|
@@ -133,13 +130,13 @@ class QueryBuilder {
|
|
|
133
130
|
const getInputName = (mutationType) => {
|
|
134
131
|
switch (mutationType) {
|
|
135
132
|
case 'delete': {
|
|
136
|
-
return `Delete${inflection_1.
|
|
133
|
+
return `Delete${(0, inflection_1.camelize)(this._model)}Input`;
|
|
137
134
|
}
|
|
138
135
|
case 'create': {
|
|
139
|
-
return `Create${inflection_1.
|
|
136
|
+
return `Create${(0, inflection_1.camelize)(this._model)}Input`;
|
|
140
137
|
}
|
|
141
138
|
case 'patch': {
|
|
142
|
-
return `Update${inflection_1.
|
|
139
|
+
return `Update${(0, inflection_1.camelize)(this._model)}Input`;
|
|
143
140
|
}
|
|
144
141
|
default:
|
|
145
142
|
throw new Error('Unhandled mutation type' + mutationType);
|
|
@@ -168,7 +165,7 @@ class QueryBuilder {
|
|
|
168
165
|
getMany({ select } = {}) {
|
|
169
166
|
this._op = 'getMany';
|
|
170
167
|
this._key = this._findQuery();
|
|
171
|
-
this.queryName(inflection_1.
|
|
168
|
+
this.queryName((0, inflection_1.camelize)(['get', (0, inflection_1.underscore)(this._key), 'query'].join('_'), true));
|
|
172
169
|
const defn = this._introspection[this._key];
|
|
173
170
|
this.select(select);
|
|
174
171
|
this._ast = (0, ast_1.getMany)({
|
|
@@ -183,7 +180,7 @@ class QueryBuilder {
|
|
|
183
180
|
all({ select } = {}) {
|
|
184
181
|
this._op = 'getMany';
|
|
185
182
|
this._key = this._findQuery();
|
|
186
|
-
this.queryName(inflection_1.
|
|
183
|
+
this.queryName((0, inflection_1.camelize)(['get', (0, inflection_1.underscore)(this._key), 'query', 'all'].join('_'), true));
|
|
187
184
|
const defn = this._introspection[this._key];
|
|
188
185
|
this.select(select);
|
|
189
186
|
this._ast = (0, ast_1.getAll)({
|
|
@@ -197,7 +194,7 @@ class QueryBuilder {
|
|
|
197
194
|
count() {
|
|
198
195
|
this._op = 'getMany';
|
|
199
196
|
this._key = this._findQuery();
|
|
200
|
-
this.queryName(inflection_1.
|
|
197
|
+
this.queryName((0, inflection_1.camelize)(['get', (0, inflection_1.underscore)(this._key), 'count', 'query'].join('_'), true));
|
|
201
198
|
const defn = this._introspection[this._key];
|
|
202
199
|
this._ast = (0, ast_1.getCount)({
|
|
203
200
|
queryName: this._queryName,
|
|
@@ -209,7 +206,7 @@ class QueryBuilder {
|
|
|
209
206
|
getOne({ select } = {}) {
|
|
210
207
|
this._op = 'getOne';
|
|
211
208
|
this._key = this._findQuery();
|
|
212
|
-
this.queryName(inflection_1.
|
|
209
|
+
this.queryName((0, inflection_1.camelize)(['get', (0, inflection_1.underscore)(this._key), 'query'].join('_'), true));
|
|
213
210
|
const defn = this._introspection[this._key];
|
|
214
211
|
this.select(select);
|
|
215
212
|
this._ast = (0, ast_1.getOne)({
|
|
@@ -225,7 +222,7 @@ class QueryBuilder {
|
|
|
225
222
|
this._op = 'mutation';
|
|
226
223
|
this._mutation = 'create';
|
|
227
224
|
this._key = this._findMutation();
|
|
228
|
-
this.queryName(inflection_1.
|
|
225
|
+
this.queryName((0, inflection_1.camelize)([(0, inflection_1.underscore)(this._key), 'mutation'].join('_'), true));
|
|
229
226
|
const defn = this._introspection[this._key];
|
|
230
227
|
this.select(select);
|
|
231
228
|
this._ast = (0, ast_1.createOne)({
|
|
@@ -240,7 +237,7 @@ class QueryBuilder {
|
|
|
240
237
|
this._op = 'mutation';
|
|
241
238
|
this._mutation = 'delete';
|
|
242
239
|
this._key = this._findMutation();
|
|
243
|
-
this.queryName(inflection_1.
|
|
240
|
+
this.queryName((0, inflection_1.camelize)([(0, inflection_1.underscore)(this._key), 'mutation'].join('_'), true));
|
|
244
241
|
const defn = this._introspection[this._key];
|
|
245
242
|
this.select(select);
|
|
246
243
|
this._ast = (0, ast_1.deleteOne)({
|
|
@@ -254,7 +251,7 @@ class QueryBuilder {
|
|
|
254
251
|
this._op = 'mutation';
|
|
255
252
|
this._mutation = 'patch';
|
|
256
253
|
this._key = this._findMutation();
|
|
257
|
-
this.queryName(inflection_1.
|
|
254
|
+
this.queryName((0, inflection_1.camelize)([(0, inflection_1.underscore)(this._key), 'mutation'].join('_'), true));
|
|
258
255
|
const defn = this._introspection[this._key];
|
|
259
256
|
this.select(select);
|
|
260
257
|
this._ast = (0, ast_1.patchOne)({
|
|
@@ -415,5 +412,5 @@ function isRelationalField(fieldName, modelMeta) {
|
|
|
415
412
|
// Get getMany op name from model
|
|
416
413
|
// ie. UserSetting => userSettings
|
|
417
414
|
function modelNameToGetMany(model) {
|
|
418
|
-
return inflection_1.
|
|
415
|
+
return (0, inflection_1.camelize)((0, inflection_1.pluralize)((0, inflection_1.underscore)(model)), true);
|
|
419
416
|
}
|