@constructive-io/graphql-query 3.11.0 → 3.12.0

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 CHANGED
@@ -321,7 +321,7 @@ const createOne = ({ 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 = (0, inflekt_1.camelize)([(0, inflekt_1.singularize)(mutation.model)].join('_'), true);
324
+ const modelName = (0, inflekt_1.toCamelCase)((0, inflekt_1.singularize)(mutation.model));
325
325
  const inputProperties = mutation.properties.input
326
326
  .properties;
327
327
  const modelProperties = inputProperties[modelName];
@@ -367,7 +367,7 @@ const patchOne = ({ mutationName, operationName, mutation, selection, }) => {
367
367
  if (!mutation.properties?.input?.properties) {
368
368
  throw new Error(`No input field for mutation: ${mutationName}`);
369
369
  }
370
- const modelName = (0, inflekt_1.camelize)([(0, inflekt_1.singularize)(mutation.model)].join('_'), true);
370
+ const modelName = (0, inflekt_1.toCamelCase)((0, inflekt_1.singularize)(mutation.model));
371
371
  const inputProperties = mutation.properties.input
372
372
  .properties;
373
373
  const patchProperties = inputProperties['patch'];
@@ -420,7 +420,7 @@ const deleteOne = ({ mutationName, operationName, mutation, }) => {
420
420
  if (!mutation.properties?.input?.properties) {
421
421
  throw new Error(`No input field for mutation: ${mutationName}`);
422
422
  }
423
- const modelName = (0, inflekt_1.camelize)([(0, inflekt_1.singularize)(mutation.model)].join('_'), true);
423
+ const modelName = (0, inflekt_1.toCamelCase)((0, inflekt_1.singularize)(mutation.model));
424
424
  const inputProperties = mutation.properties.input
425
425
  .properties;
426
426
  const deleteAttrs = objectToArray(inputProperties);
package/esm/ast.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as t from 'gql-ast';
2
2
  import { OperationTypeNode } from 'graphql';
3
- import { camelize, singularize } from 'inflekt';
3
+ import { toCamelCase, singularize } from 'inflekt';
4
4
  import { getCustomAst } from './custom-ast';
5
5
  const NON_MUTABLE_PROPS = ['createdAt', 'createdBy', 'updatedAt', 'updatedBy'];
6
6
  const objectToArray = (obj) => Object.keys(obj).map((k) => ({
@@ -280,7 +280,7 @@ export const createOne = ({ mutationName, operationName, mutation, selection, })
280
280
  if (!mutation.properties?.input?.properties) {
281
281
  throw new Error(`No input field for mutation: ${mutationName}`);
282
282
  }
283
- const modelName = camelize([singularize(mutation.model)].join('_'), true);
283
+ const modelName = toCamelCase(singularize(mutation.model));
284
284
  const inputProperties = mutation.properties.input
285
285
  .properties;
286
286
  const modelProperties = inputProperties[modelName];
@@ -325,7 +325,7 @@ export const patchOne = ({ mutationName, operationName, mutation, selection, })
325
325
  if (!mutation.properties?.input?.properties) {
326
326
  throw new Error(`No input field for mutation: ${mutationName}`);
327
327
  }
328
- const modelName = camelize([singularize(mutation.model)].join('_'), true);
328
+ const modelName = toCamelCase(singularize(mutation.model));
329
329
  const inputProperties = mutation.properties.input
330
330
  .properties;
331
331
  const patchProperties = inputProperties['patch'];
@@ -377,7 +377,7 @@ export const deleteOne = ({ mutationName, operationName, mutation, }) => {
377
377
  if (!mutation.properties?.input?.properties) {
378
378
  throw new Error(`No input field for mutation: ${mutationName}`);
379
379
  }
380
- const modelName = camelize([singularize(mutation.model)].join('_'), true);
380
+ const modelName = toCamelCase(singularize(mutation.model));
381
381
  const inputProperties = mutation.properties.input
382
382
  .properties;
383
383
  const deleteAttrs = objectToArray(inputProperties);
@@ -7,7 +7,7 @@
7
7
  *
8
8
  * Back-ported from Dashboard's `packages/data/src/query-generator.ts`.
9
9
  */
10
- import { camelize, pluralize } from 'inflekt';
10
+ import { toCamelCase, toScreamingSnake, pluralize } from 'inflekt';
11
11
  // ---------------------------------------------------------------------------
12
12
  // Internal helpers
13
13
  // ---------------------------------------------------------------------------
@@ -33,7 +33,7 @@ export function normalizeInflectionValue(value) {
33
33
  * Example: "ActionGoal" -> "actionGoals", "User" -> "users", "Person" -> "people"
34
34
  */
35
35
  export function toCamelCasePlural(tableName, table) {
36
- const singular = camelize(tableName, true);
36
+ const singular = toCamelCase(tableName);
37
37
  const inflectedPlural = pluralize(singular);
38
38
  const serverPluralCandidates = [
39
39
  table?.query?.all,
@@ -60,7 +60,7 @@ export function toCamelCasePlural(tableName, table) {
60
60
  * Prefers server-provided names when available.
61
61
  */
62
62
  export function toCamelCaseSingular(tableName, table) {
63
- const localSingular = camelize(tableName, true);
63
+ const localSingular = toCamelCase(tableName);
64
64
  for (const candidateRaw of [
65
65
  table?.query?.one,
66
66
  table?.inflection?.tableFieldName,
@@ -137,9 +137,7 @@ export function toPatchFieldName(tableName, table) {
137
137
  * "id" -> "ID_ASC"
138
138
  */
139
139
  export function toOrderByEnumValue(fieldName, direction) {
140
- const screaming = fieldName
141
- .replace(/([a-z0-9])([A-Z])/g, '$1_$2')
142
- .toUpperCase();
140
+ const screaming = toScreamingSnake(fieldName);
143
141
  return `${screaming}_${direction.toUpperCase()}`;
144
142
  }
145
143
  /**
@@ -1,5 +1,5 @@
1
1
  import { print as gqlPrint } from 'graphql';
2
- import { camelize, pluralize, underscore } from 'inflekt';
2
+ import { toCamelCase, toPascalCase, pluralize, underscore } from 'inflekt';
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';
@@ -88,13 +88,13 @@ export class QueryBuilder {
88
88
  const getInputName = (mutationType) => {
89
89
  switch (mutationType) {
90
90
  case 'delete': {
91
- return `Delete${camelize(this._model)}Input`;
91
+ return `Delete${toPascalCase(this._model)}Input`;
92
92
  }
93
93
  case 'create': {
94
- return `Create${camelize(this._model)}Input`;
94
+ return `Create${toPascalCase(this._model)}Input`;
95
95
  }
96
96
  case 'patch': {
97
- return `Update${camelize(this._model)}Input`;
97
+ return `Update${toPascalCase(this._model)}Input`;
98
98
  }
99
99
  default:
100
100
  throw new Error('Unhandled mutation type' + mutationType);
@@ -123,7 +123,7 @@ export class QueryBuilder {
123
123
  getMany({ select } = {}) {
124
124
  this._op = 'getMany';
125
125
  this._key = this._findQuery();
126
- this.queryName(camelize(['get', underscore(this._key), 'query'].join('_'), true));
126
+ this.queryName(toCamelCase(['get', underscore(this._key), 'query'].join('_')));
127
127
  const defn = this._introspection[this._key];
128
128
  this.select(select);
129
129
  this._ast = getMany({
@@ -138,7 +138,7 @@ export class QueryBuilder {
138
138
  all({ select } = {}) {
139
139
  this._op = 'getMany';
140
140
  this._key = this._findQuery();
141
- this.queryName(camelize(['get', underscore(this._key), 'query', 'all'].join('_'), true));
141
+ this.queryName(toCamelCase(['get', underscore(this._key), 'query', 'all'].join('_')));
142
142
  const defn = this._introspection[this._key];
143
143
  this.select(select);
144
144
  this._ast = getAll({
@@ -152,7 +152,7 @@ export class QueryBuilder {
152
152
  count() {
153
153
  this._op = 'getMany';
154
154
  this._key = this._findQuery();
155
- this.queryName(camelize(['get', underscore(this._key), 'count', 'query'].join('_'), true));
155
+ this.queryName(toCamelCase(['get', underscore(this._key), 'count', 'query'].join('_')));
156
156
  const defn = this._introspection[this._key];
157
157
  this._ast = getCount({
158
158
  queryName: this._queryName,
@@ -164,7 +164,7 @@ export class QueryBuilder {
164
164
  getOne({ select } = {}) {
165
165
  this._op = 'getOne';
166
166
  this._key = this._findQuery();
167
- this.queryName(camelize(['get', underscore(this._key), 'query'].join('_'), true));
167
+ this.queryName(toCamelCase(['get', underscore(this._key), 'query'].join('_')));
168
168
  const defn = this._introspection[this._key];
169
169
  this.select(select);
170
170
  this._ast = getOne({
@@ -180,7 +180,7 @@ export class QueryBuilder {
180
180
  this._op = 'mutation';
181
181
  this._mutation = 'create';
182
182
  this._key = this._findMutation();
183
- this.queryName(camelize([underscore(this._key), 'mutation'].join('_'), true));
183
+ this.queryName(toCamelCase([underscore(this._key), 'mutation'].join('_')));
184
184
  const defn = this._introspection[this._key];
185
185
  this.select(select);
186
186
  this._ast = createOne({
@@ -195,7 +195,7 @@ export class QueryBuilder {
195
195
  this._op = 'mutation';
196
196
  this._mutation = 'delete';
197
197
  this._key = this._findMutation();
198
- this.queryName(camelize([underscore(this._key), 'mutation'].join('_'), true));
198
+ this.queryName(toCamelCase([underscore(this._key), 'mutation'].join('_')));
199
199
  const defn = this._introspection[this._key];
200
200
  this.select(select);
201
201
  this._ast = deleteOne({
@@ -209,7 +209,7 @@ export class QueryBuilder {
209
209
  this._op = 'mutation';
210
210
  this._mutation = 'patch';
211
211
  this._key = this._findMutation();
212
- this.queryName(camelize([underscore(this._key), 'mutation'].join('_'), true));
212
+ this.queryName(toCamelCase([underscore(this._key), 'mutation'].join('_')));
213
213
  const defn = this._introspection[this._key];
214
214
  this.select(select);
215
215
  this._ast = patchOne({
@@ -371,5 +371,5 @@ function isRelationalField(fieldName, modelMeta) {
371
371
  // Get getMany op name from model
372
372
  // ie. UserSetting => userSettings
373
373
  function modelNameToGetMany(model) {
374
- return camelize(pluralize(underscore(model)), true);
374
+ return toCamelCase(pluralize(underscore(model)));
375
375
  }
@@ -48,7 +48,7 @@ function normalizeInflectionValue(value) {
48
48
  * Example: "ActionGoal" -> "actionGoals", "User" -> "users", "Person" -> "people"
49
49
  */
50
50
  function toCamelCasePlural(tableName, table) {
51
- const singular = (0, inflekt_1.camelize)(tableName, true);
51
+ const singular = (0, inflekt_1.toCamelCase)(tableName);
52
52
  const inflectedPlural = (0, inflekt_1.pluralize)(singular);
53
53
  const serverPluralCandidates = [
54
54
  table?.query?.all,
@@ -75,7 +75,7 @@ function toCamelCasePlural(tableName, table) {
75
75
  * Prefers server-provided names when available.
76
76
  */
77
77
  function toCamelCaseSingular(tableName, table) {
78
- const localSingular = (0, inflekt_1.camelize)(tableName, true);
78
+ const localSingular = (0, inflekt_1.toCamelCase)(tableName);
79
79
  for (const candidateRaw of [
80
80
  table?.query?.one,
81
81
  table?.inflection?.tableFieldName,
@@ -152,9 +152,7 @@ function toPatchFieldName(tableName, table) {
152
152
  * "id" -> "ID_ASC"
153
153
  */
154
154
  function toOrderByEnumValue(fieldName, direction) {
155
- const screaming = fieldName
156
- .replace(/([a-z0-9])([A-Z])/g, '$1_$2')
157
- .toUpperCase();
155
+ const screaming = (0, inflekt_1.toScreamingSnake)(fieldName);
158
156
  return `${screaming}_${direction.toUpperCase()}`;
159
157
  }
160
158
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@constructive-io/graphql-query",
3
- "version": "3.11.0",
3
+ "version": "3.12.0",
4
4
  "description": "Constructive GraphQL Query",
5
5
  "author": "Constructive <developers@constructive.io>",
6
6
  "main": "index.js",
@@ -30,14 +30,14 @@
30
30
  },
31
31
  "dependencies": {
32
32
  "ajv": "^8.18.0",
33
- "gql-ast": "^3.3.3",
33
+ "gql-ast": "^3.4.0",
34
34
  "grafast": "1.0.0-rc.9",
35
35
  "graphile-build-pg": "5.0.0-rc.8",
36
36
  "graphile-config": "1.0.0-rc.6",
37
- "graphile-settings": "^4.15.0",
37
+ "graphile-settings": "^4.16.0",
38
38
  "graphql": "16.13.0",
39
39
  "inflection": "^3.0.0",
40
- "inflekt": "^0.5.0",
40
+ "inflekt": "^0.5.1",
41
41
  "lru-cache": "^11.2.7",
42
42
  "postgraphile": "5.0.0-rc.10"
43
43
  },
@@ -51,5 +51,5 @@
51
51
  "devDependencies": {
52
52
  "makage": "^0.1.10"
53
53
  },
54
- "gitHead": "2660dbd64e96cdb785ace8b28fbf9275cb3812aa"
54
+ "gitHead": "b8ed57a447cd71b93094edf362e72b94801e5f3a"
55
55
  }
package/query-builder.js CHANGED
@@ -124,13 +124,13 @@ class QueryBuilder {
124
124
  const getInputName = (mutationType) => {
125
125
  switch (mutationType) {
126
126
  case 'delete': {
127
- return `Delete${(0, inflekt_1.camelize)(this._model)}Input`;
127
+ return `Delete${(0, inflekt_1.toPascalCase)(this._model)}Input`;
128
128
  }
129
129
  case 'create': {
130
- return `Create${(0, inflekt_1.camelize)(this._model)}Input`;
130
+ return `Create${(0, inflekt_1.toPascalCase)(this._model)}Input`;
131
131
  }
132
132
  case 'patch': {
133
- return `Update${(0, inflekt_1.camelize)(this._model)}Input`;
133
+ return `Update${(0, inflekt_1.toPascalCase)(this._model)}Input`;
134
134
  }
135
135
  default:
136
136
  throw new Error('Unhandled mutation type' + mutationType);
@@ -159,7 +159,7 @@ class QueryBuilder {
159
159
  getMany({ select } = {}) {
160
160
  this._op = 'getMany';
161
161
  this._key = this._findQuery();
162
- this.queryName((0, inflekt_1.camelize)(['get', (0, inflekt_1.underscore)(this._key), 'query'].join('_'), true));
162
+ this.queryName((0, inflekt_1.toCamelCase)(['get', (0, inflekt_1.underscore)(this._key), 'query'].join('_')));
163
163
  const defn = this._introspection[this._key];
164
164
  this.select(select);
165
165
  this._ast = (0, ast_1.getMany)({
@@ -174,7 +174,7 @@ class QueryBuilder {
174
174
  all({ select } = {}) {
175
175
  this._op = 'getMany';
176
176
  this._key = this._findQuery();
177
- this.queryName((0, inflekt_1.camelize)(['get', (0, inflekt_1.underscore)(this._key), 'query', 'all'].join('_'), true));
177
+ this.queryName((0, inflekt_1.toCamelCase)(['get', (0, inflekt_1.underscore)(this._key), 'query', 'all'].join('_')));
178
178
  const defn = this._introspection[this._key];
179
179
  this.select(select);
180
180
  this._ast = (0, ast_1.getAll)({
@@ -188,7 +188,7 @@ class QueryBuilder {
188
188
  count() {
189
189
  this._op = 'getMany';
190
190
  this._key = this._findQuery();
191
- this.queryName((0, inflekt_1.camelize)(['get', (0, inflekt_1.underscore)(this._key), 'count', 'query'].join('_'), true));
191
+ this.queryName((0, inflekt_1.toCamelCase)(['get', (0, inflekt_1.underscore)(this._key), 'count', 'query'].join('_')));
192
192
  const defn = this._introspection[this._key];
193
193
  this._ast = (0, ast_1.getCount)({
194
194
  queryName: this._queryName,
@@ -200,7 +200,7 @@ class QueryBuilder {
200
200
  getOne({ select } = {}) {
201
201
  this._op = 'getOne';
202
202
  this._key = this._findQuery();
203
- this.queryName((0, inflekt_1.camelize)(['get', (0, inflekt_1.underscore)(this._key), 'query'].join('_'), true));
203
+ this.queryName((0, inflekt_1.toCamelCase)(['get', (0, inflekt_1.underscore)(this._key), 'query'].join('_')));
204
204
  const defn = this._introspection[this._key];
205
205
  this.select(select);
206
206
  this._ast = (0, ast_1.getOne)({
@@ -216,7 +216,7 @@ class QueryBuilder {
216
216
  this._op = 'mutation';
217
217
  this._mutation = 'create';
218
218
  this._key = this._findMutation();
219
- this.queryName((0, inflekt_1.camelize)([(0, inflekt_1.underscore)(this._key), 'mutation'].join('_'), true));
219
+ this.queryName((0, inflekt_1.toCamelCase)([(0, inflekt_1.underscore)(this._key), 'mutation'].join('_')));
220
220
  const defn = this._introspection[this._key];
221
221
  this.select(select);
222
222
  this._ast = (0, ast_1.createOne)({
@@ -231,7 +231,7 @@ class QueryBuilder {
231
231
  this._op = 'mutation';
232
232
  this._mutation = 'delete';
233
233
  this._key = this._findMutation();
234
- this.queryName((0, inflekt_1.camelize)([(0, inflekt_1.underscore)(this._key), 'mutation'].join('_'), true));
234
+ this.queryName((0, inflekt_1.toCamelCase)([(0, inflekt_1.underscore)(this._key), 'mutation'].join('_')));
235
235
  const defn = this._introspection[this._key];
236
236
  this.select(select);
237
237
  this._ast = (0, ast_1.deleteOne)({
@@ -245,7 +245,7 @@ class QueryBuilder {
245
245
  this._op = 'mutation';
246
246
  this._mutation = 'patch';
247
247
  this._key = this._findMutation();
248
- this.queryName((0, inflekt_1.camelize)([(0, inflekt_1.underscore)(this._key), 'mutation'].join('_'), true));
248
+ this.queryName((0, inflekt_1.toCamelCase)([(0, inflekt_1.underscore)(this._key), 'mutation'].join('_')));
249
249
  const defn = this._introspection[this._key];
250
250
  this.select(select);
251
251
  this._ast = (0, ast_1.patchOne)({
@@ -408,5 +408,5 @@ function isRelationalField(fieldName, modelMeta) {
408
408
  // Get getMany op name from model
409
409
  // ie. UserSetting => userSettings
410
410
  function modelNameToGetMany(model) {
411
- return (0, inflekt_1.camelize)((0, inflekt_1.pluralize)((0, inflekt_1.underscore)(model)), true);
411
+ return (0, inflekt_1.toCamelCase)((0, inflekt_1.pluralize)((0, inflekt_1.underscore)(model)));
412
412
  }