introspectron 2.13.15 → 2.13.17
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/esm/gql.js +65 -8
- package/gql.js +65 -8
- package/package.json +4 -4
package/esm/gql.js
CHANGED
|
@@ -156,7 +156,8 @@ export const parseGraphQuery = (introQuery) => {
|
|
|
156
156
|
return m;
|
|
157
157
|
}, {});
|
|
158
158
|
const queries = queriesRoot.fields.reduce((m, query) => {
|
|
159
|
-
|
|
159
|
+
const model = getObjectType(query.type);
|
|
160
|
+
if (model) {
|
|
160
161
|
if (isConnectionQuery(query)) {
|
|
161
162
|
m[query.name] = parseConnectionQuery(context, query, 1);
|
|
162
163
|
}
|
|
@@ -174,24 +175,59 @@ export const parseGraphQuery = (introQuery) => {
|
|
|
174
175
|
function parseSelectionObject(context, model, nesting) {
|
|
175
176
|
const { HASH } = context;
|
|
176
177
|
throwIfInvalidContext(context);
|
|
177
|
-
const selectionFields = HASH[model].fields
|
|
178
|
-
|
|
179
|
-
|
|
178
|
+
const selectionFields = HASH[model].fields
|
|
179
|
+
.filter((f) => !isPureObjectType(f.type))
|
|
180
|
+
.filter((f) => {
|
|
181
|
+
const objectType = getObjectType(f.type);
|
|
182
|
+
if (objectType && fieldHasRequiredArgs(f))
|
|
183
|
+
return false;
|
|
184
|
+
return true;
|
|
185
|
+
});
|
|
186
|
+
const mapped = selectionFields.map((f) => {
|
|
187
|
+
const objectType = getObjectType(f.type);
|
|
188
|
+
if (objectType) {
|
|
180
189
|
if (isConnectionQuery(f)) {
|
|
181
190
|
return { name: f.name, ...parseConnectionQuery(context, f, nesting - 1) };
|
|
182
191
|
}
|
|
183
|
-
|
|
184
|
-
return { name: f.name,
|
|
192
|
+
if (isListType(f.type)) {
|
|
193
|
+
return { name: f.name, selection: parseSelectionScalar(context, objectType) };
|
|
185
194
|
}
|
|
195
|
+
return { name: f.name, ...parseSingleQuery(context, f, nesting - 1) };
|
|
196
|
+
}
|
|
197
|
+
const baseKind = getBaseKind(f.type);
|
|
198
|
+
if (isListType(f.type)) {
|
|
199
|
+
if (baseKind === 'SCALAR' || baseKind === 'ENUM')
|
|
200
|
+
return f.name;
|
|
201
|
+
return null;
|
|
186
202
|
}
|
|
203
|
+
if (baseKind === 'UNION' || baseKind === 'INTERFACE')
|
|
204
|
+
return null;
|
|
187
205
|
return f.name;
|
|
188
206
|
});
|
|
207
|
+
return mapped.filter((x) => x != null);
|
|
189
208
|
}
|
|
190
209
|
function parseSelectionScalar(context, model) {
|
|
191
210
|
const { HASH } = context;
|
|
192
211
|
throwIfInvalidContext(context);
|
|
193
|
-
const selectionFields = HASH[model].fields.filter((f) =>
|
|
194
|
-
|
|
212
|
+
const selectionFields = HASH[model].fields.filter((f) => {
|
|
213
|
+
if (isPureObjectType(f.type))
|
|
214
|
+
return false;
|
|
215
|
+
if (isConnectionQuery(f))
|
|
216
|
+
return false;
|
|
217
|
+
const objectType = getObjectType(f.type);
|
|
218
|
+
if (objectType)
|
|
219
|
+
return false;
|
|
220
|
+
const baseKind = getBaseKind(f.type);
|
|
221
|
+
if (isListType(f.type) && !(baseKind === 'SCALAR' || baseKind === 'ENUM'))
|
|
222
|
+
return false;
|
|
223
|
+
if (baseKind === 'UNION' || baseKind === 'INTERFACE')
|
|
224
|
+
return false;
|
|
225
|
+
return true;
|
|
226
|
+
});
|
|
227
|
+
const names = selectionFields.map((f) => f.name);
|
|
228
|
+
if (names.length === 0)
|
|
229
|
+
return ['__typename'];
|
|
230
|
+
return names;
|
|
195
231
|
}
|
|
196
232
|
function isConnectionQuery(query) {
|
|
197
233
|
const objectType = getObjectType(query.type);
|
|
@@ -210,6 +246,27 @@ function getObjectType(type) {
|
|
|
210
246
|
return getObjectType(type.ofType);
|
|
211
247
|
return undefined;
|
|
212
248
|
}
|
|
249
|
+
function isListType(type) {
|
|
250
|
+
if (type.kind === 'LIST')
|
|
251
|
+
return true;
|
|
252
|
+
if (type.ofType)
|
|
253
|
+
return isListType(type.ofType);
|
|
254
|
+
return false;
|
|
255
|
+
}
|
|
256
|
+
function fieldHasRequiredArgs(field) {
|
|
257
|
+
for (const a of field.args) {
|
|
258
|
+
if (a.type && a.type.kind === 'NON_NULL' && (a.defaultValue === undefined || a.defaultValue === null)) {
|
|
259
|
+
return true;
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
return false;
|
|
263
|
+
}
|
|
264
|
+
function getBaseKind(type) {
|
|
265
|
+
let t = type;
|
|
266
|
+
while (t && t.ofType)
|
|
267
|
+
t = t.ofType;
|
|
268
|
+
return (t?.kind || type.kind);
|
|
269
|
+
}
|
|
213
270
|
function throwIfInvalidContext(context) {
|
|
214
271
|
const { HASH, getInputForQueries } = context;
|
|
215
272
|
if (!HASH || !getInputForQueries) {
|
package/gql.js
CHANGED
|
@@ -161,7 +161,8 @@ const parseGraphQuery = (introQuery) => {
|
|
|
161
161
|
return m;
|
|
162
162
|
}, {});
|
|
163
163
|
const queries = queriesRoot.fields.reduce((m, query) => {
|
|
164
|
-
|
|
164
|
+
const model = getObjectType(query.type);
|
|
165
|
+
if (model) {
|
|
165
166
|
if (isConnectionQuery(query)) {
|
|
166
167
|
m[query.name] = (0, exports.parseConnectionQuery)(context, query, 1);
|
|
167
168
|
}
|
|
@@ -180,24 +181,59 @@ exports.parseGraphQuery = parseGraphQuery;
|
|
|
180
181
|
function parseSelectionObject(context, model, nesting) {
|
|
181
182
|
const { HASH } = context;
|
|
182
183
|
throwIfInvalidContext(context);
|
|
183
|
-
const selectionFields = HASH[model].fields
|
|
184
|
-
|
|
185
|
-
|
|
184
|
+
const selectionFields = HASH[model].fields
|
|
185
|
+
.filter((f) => !isPureObjectType(f.type))
|
|
186
|
+
.filter((f) => {
|
|
187
|
+
const objectType = getObjectType(f.type);
|
|
188
|
+
if (objectType && fieldHasRequiredArgs(f))
|
|
189
|
+
return false;
|
|
190
|
+
return true;
|
|
191
|
+
});
|
|
192
|
+
const mapped = selectionFields.map((f) => {
|
|
193
|
+
const objectType = getObjectType(f.type);
|
|
194
|
+
if (objectType) {
|
|
186
195
|
if (isConnectionQuery(f)) {
|
|
187
196
|
return { name: f.name, ...(0, exports.parseConnectionQuery)(context, f, nesting - 1) };
|
|
188
197
|
}
|
|
189
|
-
|
|
190
|
-
return { name: f.name,
|
|
198
|
+
if (isListType(f.type)) {
|
|
199
|
+
return { name: f.name, selection: parseSelectionScalar(context, objectType) };
|
|
191
200
|
}
|
|
201
|
+
return { name: f.name, ...(0, exports.parseSingleQuery)(context, f, nesting - 1) };
|
|
202
|
+
}
|
|
203
|
+
const baseKind = getBaseKind(f.type);
|
|
204
|
+
if (isListType(f.type)) {
|
|
205
|
+
if (baseKind === 'SCALAR' || baseKind === 'ENUM')
|
|
206
|
+
return f.name;
|
|
207
|
+
return null;
|
|
192
208
|
}
|
|
209
|
+
if (baseKind === 'UNION' || baseKind === 'INTERFACE')
|
|
210
|
+
return null;
|
|
193
211
|
return f.name;
|
|
194
212
|
});
|
|
213
|
+
return mapped.filter((x) => x != null);
|
|
195
214
|
}
|
|
196
215
|
function parseSelectionScalar(context, model) {
|
|
197
216
|
const { HASH } = context;
|
|
198
217
|
throwIfInvalidContext(context);
|
|
199
|
-
const selectionFields = HASH[model].fields.filter((f) =>
|
|
200
|
-
|
|
218
|
+
const selectionFields = HASH[model].fields.filter((f) => {
|
|
219
|
+
if (isPureObjectType(f.type))
|
|
220
|
+
return false;
|
|
221
|
+
if (isConnectionQuery(f))
|
|
222
|
+
return false;
|
|
223
|
+
const objectType = getObjectType(f.type);
|
|
224
|
+
if (objectType)
|
|
225
|
+
return false;
|
|
226
|
+
const baseKind = getBaseKind(f.type);
|
|
227
|
+
if (isListType(f.type) && !(baseKind === 'SCALAR' || baseKind === 'ENUM'))
|
|
228
|
+
return false;
|
|
229
|
+
if (baseKind === 'UNION' || baseKind === 'INTERFACE')
|
|
230
|
+
return false;
|
|
231
|
+
return true;
|
|
232
|
+
});
|
|
233
|
+
const names = selectionFields.map((f) => f.name);
|
|
234
|
+
if (names.length === 0)
|
|
235
|
+
return ['__typename'];
|
|
236
|
+
return names;
|
|
201
237
|
}
|
|
202
238
|
function isConnectionQuery(query) {
|
|
203
239
|
const objectType = getObjectType(query.type);
|
|
@@ -216,6 +252,27 @@ function getObjectType(type) {
|
|
|
216
252
|
return getObjectType(type.ofType);
|
|
217
253
|
return undefined;
|
|
218
254
|
}
|
|
255
|
+
function isListType(type) {
|
|
256
|
+
if (type.kind === 'LIST')
|
|
257
|
+
return true;
|
|
258
|
+
if (type.ofType)
|
|
259
|
+
return isListType(type.ofType);
|
|
260
|
+
return false;
|
|
261
|
+
}
|
|
262
|
+
function fieldHasRequiredArgs(field) {
|
|
263
|
+
for (const a of field.args) {
|
|
264
|
+
if (a.type && a.type.kind === 'NON_NULL' && (a.defaultValue === undefined || a.defaultValue === null)) {
|
|
265
|
+
return true;
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
return false;
|
|
269
|
+
}
|
|
270
|
+
function getBaseKind(type) {
|
|
271
|
+
let t = type;
|
|
272
|
+
while (t && t.ofType)
|
|
273
|
+
t = t.ofType;
|
|
274
|
+
return (t?.kind || type.kind);
|
|
275
|
+
}
|
|
219
276
|
function throwIfInvalidContext(context) {
|
|
220
277
|
const { HASH, getInputForQueries } = context;
|
|
221
278
|
if (!HASH || !getInputForQueries) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "introspectron",
|
|
3
|
-
"version": "2.13.
|
|
3
|
+
"version": "2.13.17",
|
|
4
4
|
"description": "introspect your Postgres database and generate an SDK",
|
|
5
5
|
"author": "Dan Lynch <pyramation@gmail.com>",
|
|
6
6
|
"main": "index.js",
|
|
@@ -31,9 +31,9 @@
|
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"@jest/test-sequencer": "^30.2.0",
|
|
33
33
|
"@types/pg": "^8.15.2",
|
|
34
|
-
"launchql-test": "^2.8.
|
|
34
|
+
"launchql-test": "^2.8.14",
|
|
35
35
|
"makage": "^0.1.8",
|
|
36
|
-
"pgsql-test": "^2.14.
|
|
36
|
+
"pgsql-test": "^2.14.14"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
39
|
"graphql": "15.10.1",
|
|
@@ -48,5 +48,5 @@
|
|
|
48
48
|
"graphile",
|
|
49
49
|
"launchql"
|
|
50
50
|
],
|
|
51
|
-
"gitHead": "
|
|
51
|
+
"gitHead": "ea3f6b8d86ba521ee629411efb4cf4133cc6e302"
|
|
52
52
|
}
|