@graphql-yoga/plugin-defer-stream 2.0.3 → 2.0.4-alpha-20230810153432-d9f7d423
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/cjs/index.js +1 -1
- package/cjs/validations/defer-stream-directive-label.js +4 -2
- package/cjs/validations/overlapping-fields-can-be-merged.js +10 -28
- package/esm/index.js +2 -2
- package/esm/validations/defer-stream-directive-label.js +4 -2
- package/esm/validations/overlapping-fields-can-be-merged.js +10 -28
- package/esm/validations/stream-directive-on-list-field.js +2 -2
- package/package.json +2 -2
package/cjs/index.js
CHANGED
|
@@ -29,7 +29,7 @@ function useDeferStream() {
|
|
|
29
29
|
onValidate: ({ params, addValidationRule, }) => {
|
|
30
30
|
// Just to make TS happy because rules are always defined by useEngine.
|
|
31
31
|
params.rules ||= [];
|
|
32
|
-
params.rules = params.rules.filter(
|
|
32
|
+
params.rules = params.rules.filter(rule => rule.name !== 'OverlappingFieldsCanBeMergedRule');
|
|
33
33
|
addValidationRule(overlapping_fields_can_be_merged_js_1.OverlappingFieldsCanBeMergedRule);
|
|
34
34
|
addValidationRule(defer_stream_directive_label_js_1.DeferStreamDirectiveLabelRule);
|
|
35
35
|
addValidationRule(defer_stream_directive_on_root_field_js_1.DeferStreamDirectiveOnRootFieldRule);
|
|
@@ -14,7 +14,7 @@ function DeferStreamDirectiveLabelRule(context) {
|
|
|
14
14
|
Directive(node) {
|
|
15
15
|
if (node.name.value === utils_1.GraphQLDeferDirective.name ||
|
|
16
16
|
node.name.value === utils_1.GraphQLStreamDirective.name) {
|
|
17
|
-
const labelArgument = node.arguments?.find(
|
|
17
|
+
const labelArgument = node.arguments?.find(arg => arg.name.value === 'label');
|
|
18
18
|
const labelValue = labelArgument?.value;
|
|
19
19
|
if (!labelValue) {
|
|
20
20
|
return;
|
|
@@ -23,7 +23,9 @@ function DeferStreamDirectiveLabelRule(context) {
|
|
|
23
23
|
context.reportError((0, utils_1.createGraphQLError)(`Directive "${node.name.value}"'s label argument must be a static string.`, { nodes: node }));
|
|
24
24
|
}
|
|
25
25
|
else if (knownLabels[labelValue.value]) {
|
|
26
|
-
context.reportError((0, utils_1.createGraphQLError)('Defer/Stream directive label argument must be unique.', {
|
|
26
|
+
context.reportError((0, utils_1.createGraphQLError)('Defer/Stream directive label argument must be unique.', {
|
|
27
|
+
nodes: [knownLabels[labelValue.value], node],
|
|
28
|
+
}));
|
|
27
29
|
}
|
|
28
30
|
else {
|
|
29
31
|
knownLabels[labelValue.value] = node;
|
|
@@ -79,7 +79,7 @@ function sortValueNode(valueNode) {
|
|
|
79
79
|
}
|
|
80
80
|
function sortFields(fields) {
|
|
81
81
|
return fields
|
|
82
|
-
.map(
|
|
82
|
+
.map(fieldNode => ({
|
|
83
83
|
...fieldNode,
|
|
84
84
|
value: sortValueNode(fieldNode.value),
|
|
85
85
|
}))
|
|
@@ -88,8 +88,7 @@ function sortFields(fields) {
|
|
|
88
88
|
function reasonMessage(reason) {
|
|
89
89
|
if (Array.isArray(reason)) {
|
|
90
90
|
return reason
|
|
91
|
-
.map(([responseName, subReason]) => `subfields "${responseName}" conflict because ` +
|
|
92
|
-
reasonMessage(subReason))
|
|
91
|
+
.map(([responseName, subReason]) => `subfields "${responseName}" conflict because ` + reasonMessage(subReason))
|
|
93
92
|
.join(' and ');
|
|
94
93
|
}
|
|
95
94
|
return reason;
|
|
@@ -352,19 +351,13 @@ function findConflict(context, cachedFieldsAndFragmentNames, comparedFragmentPai
|
|
|
352
351
|
// in the current state of the schema, then perhaps in some future version,
|
|
353
352
|
// thus may not safely diverge.
|
|
354
353
|
const areMutuallyExclusive = parentFieldsAreMutuallyExclusive ||
|
|
355
|
-
(parentType1 !== parentType2 &&
|
|
356
|
-
(0, graphql_1.isObjectType)(parentType1) &&
|
|
357
|
-
(0, graphql_1.isObjectType)(parentType2));
|
|
354
|
+
(parentType1 !== parentType2 && (0, graphql_1.isObjectType)(parentType1) && (0, graphql_1.isObjectType)(parentType2));
|
|
358
355
|
if (!areMutuallyExclusive) {
|
|
359
356
|
// Two aliases must refer to the same field.
|
|
360
357
|
const name1 = node1.name.value;
|
|
361
358
|
const name2 = node2.name.value;
|
|
362
359
|
if (name1 !== name2) {
|
|
363
|
-
return [
|
|
364
|
-
[responseName, `"${name1}" and "${name2}" are different fields`],
|
|
365
|
-
[node1],
|
|
366
|
-
[node2],
|
|
367
|
-
];
|
|
360
|
+
return [[responseName, `"${name1}" and "${name2}" are different fields`], [node1], [node2]];
|
|
368
361
|
}
|
|
369
362
|
// Two field calls must have the same arguments.
|
|
370
363
|
if (stringifyArguments(node1) !== stringifyArguments(node2)) {
|
|
@@ -375,21 +368,14 @@ function findConflict(context, cachedFieldsAndFragmentNames, comparedFragmentPai
|
|
|
375
368
|
const directives1 = /* c8 ignore next */ node1.directives ?? [];
|
|
376
369
|
const directives2 = /* c8 ignore next */ node2.directives ?? [];
|
|
377
370
|
if (!sameStreams(directives1, directives2)) {
|
|
378
|
-
return [
|
|
379
|
-
[responseName, 'they have differing stream directives'],
|
|
380
|
-
[node1],
|
|
381
|
-
[node2],
|
|
382
|
-
];
|
|
371
|
+
return [[responseName, 'they have differing stream directives'], [node1], [node2]];
|
|
383
372
|
}
|
|
384
373
|
// The return type for each field.
|
|
385
374
|
const type1 = def1?.type;
|
|
386
375
|
const type2 = def2?.type;
|
|
387
376
|
if (type1 && type2 && doTypesConflict(type1, type2)) {
|
|
388
377
|
return [
|
|
389
|
-
[
|
|
390
|
-
responseName,
|
|
391
|
-
`they return conflicting types "${(0, utils_1.inspect)(type1)}" and "${(0, utils_1.inspect)(type2)}"`,
|
|
392
|
-
],
|
|
378
|
+
[responseName, `they return conflicting types "${(0, utils_1.inspect)(type1)}" and "${(0, utils_1.inspect)(type2)}"`],
|
|
393
379
|
[node1],
|
|
394
380
|
[node2],
|
|
395
381
|
];
|
|
@@ -410,7 +396,7 @@ function stringifyArguments(fieldNode) {
|
|
|
410
396
|
const args = /* c8 ignore next */ fieldNode.arguments ?? [];
|
|
411
397
|
const inputObjectWithArgs = {
|
|
412
398
|
kind: graphql_1.Kind.OBJECT,
|
|
413
|
-
fields: args.map(
|
|
399
|
+
fields: args.map(argNode => ({
|
|
414
400
|
kind: graphql_1.Kind.OBJECT_FIELD,
|
|
415
401
|
name: argNode.name,
|
|
416
402
|
value: argNode.value,
|
|
@@ -419,7 +405,7 @@ function stringifyArguments(fieldNode) {
|
|
|
419
405
|
return (0, graphql_1.print)(sortValueNode(inputObjectWithArgs));
|
|
420
406
|
}
|
|
421
407
|
function getStreamDirective(directives) {
|
|
422
|
-
return directives.find(
|
|
408
|
+
return directives.find(directive => directive.name.value === 'stream');
|
|
423
409
|
}
|
|
424
410
|
function sameStreams(directives1, directives2) {
|
|
425
411
|
const stream1 = getStreamDirective(directives1);
|
|
@@ -440,17 +426,13 @@ function sameStreams(directives1, directives2) {
|
|
|
440
426
|
// later recursively. However List and Non-Null types must match.
|
|
441
427
|
function doTypesConflict(type1, type2) {
|
|
442
428
|
if ((0, graphql_1.isListType)(type1)) {
|
|
443
|
-
return (0, graphql_1.isListType)(type2)
|
|
444
|
-
? doTypesConflict(type1.ofType, type2.ofType)
|
|
445
|
-
: true;
|
|
429
|
+
return (0, graphql_1.isListType)(type2) ? doTypesConflict(type1.ofType, type2.ofType) : true;
|
|
446
430
|
}
|
|
447
431
|
if ((0, graphql_1.isListType)(type2)) {
|
|
448
432
|
return true;
|
|
449
433
|
}
|
|
450
434
|
if ((0, graphql_1.isNonNullType)(type1)) {
|
|
451
|
-
return (0, graphql_1.isNonNullType)(type2)
|
|
452
|
-
? doTypesConflict(type1.ofType, type2.ofType)
|
|
453
|
-
: true;
|
|
435
|
+
return (0, graphql_1.isNonNullType)(type2) ? doTypesConflict(type1.ofType, type2.ofType) : true;
|
|
454
436
|
}
|
|
455
437
|
if ((0, graphql_1.isNonNullType)(type2)) {
|
|
456
438
|
return true;
|
package/esm/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { GraphQLSchema } from 'graphql';
|
|
2
|
-
import { GraphQLDeferDirective, GraphQLStreamDirective
|
|
2
|
+
import { GraphQLDeferDirective, GraphQLStreamDirective } from '@graphql-tools/utils';
|
|
3
3
|
import { DeferStreamDirectiveLabelRule } from './validations/defer-stream-directive-label.js';
|
|
4
4
|
import { DeferStreamDirectiveOnRootFieldRule } from './validations/defer-stream-directive-on-root-field.js';
|
|
5
5
|
import { OverlappingFieldsCanBeMergedRule } from './validations/overlapping-fields-can-be-merged.js';
|
|
@@ -26,7 +26,7 @@ export function useDeferStream() {
|
|
|
26
26
|
onValidate: ({ params, addValidationRule, }) => {
|
|
27
27
|
// Just to make TS happy because rules are always defined by useEngine.
|
|
28
28
|
params.rules ||= [];
|
|
29
|
-
params.rules = params.rules.filter(
|
|
29
|
+
params.rules = params.rules.filter(rule => rule.name !== 'OverlappingFieldsCanBeMergedRule');
|
|
30
30
|
addValidationRule(OverlappingFieldsCanBeMergedRule);
|
|
31
31
|
addValidationRule(DeferStreamDirectiveLabelRule);
|
|
32
32
|
addValidationRule(DeferStreamDirectiveOnRootFieldRule);
|
|
@@ -11,7 +11,7 @@ export function DeferStreamDirectiveLabelRule(context) {
|
|
|
11
11
|
Directive(node) {
|
|
12
12
|
if (node.name.value === GraphQLDeferDirective.name ||
|
|
13
13
|
node.name.value === GraphQLStreamDirective.name) {
|
|
14
|
-
const labelArgument = node.arguments?.find(
|
|
14
|
+
const labelArgument = node.arguments?.find(arg => arg.name.value === 'label');
|
|
15
15
|
const labelValue = labelArgument?.value;
|
|
16
16
|
if (!labelValue) {
|
|
17
17
|
return;
|
|
@@ -20,7 +20,9 @@ export function DeferStreamDirectiveLabelRule(context) {
|
|
|
20
20
|
context.reportError(createGraphQLError(`Directive "${node.name.value}"'s label argument must be a static string.`, { nodes: node }));
|
|
21
21
|
}
|
|
22
22
|
else if (knownLabels[labelValue.value]) {
|
|
23
|
-
context.reportError(createGraphQLError('Defer/Stream directive label argument must be unique.', {
|
|
23
|
+
context.reportError(createGraphQLError('Defer/Stream directive label argument must be unique.', {
|
|
24
|
+
nodes: [knownLabels[labelValue.value], node],
|
|
25
|
+
}));
|
|
24
26
|
}
|
|
25
27
|
else {
|
|
26
28
|
knownLabels[labelValue.value] = node;
|
|
@@ -75,7 +75,7 @@ function sortValueNode(valueNode) {
|
|
|
75
75
|
}
|
|
76
76
|
function sortFields(fields) {
|
|
77
77
|
return fields
|
|
78
|
-
.map(
|
|
78
|
+
.map(fieldNode => ({
|
|
79
79
|
...fieldNode,
|
|
80
80
|
value: sortValueNode(fieldNode.value),
|
|
81
81
|
}))
|
|
@@ -84,8 +84,7 @@ function sortFields(fields) {
|
|
|
84
84
|
function reasonMessage(reason) {
|
|
85
85
|
if (Array.isArray(reason)) {
|
|
86
86
|
return reason
|
|
87
|
-
.map(([responseName, subReason]) => `subfields "${responseName}" conflict because ` +
|
|
88
|
-
reasonMessage(subReason))
|
|
87
|
+
.map(([responseName, subReason]) => `subfields "${responseName}" conflict because ` + reasonMessage(subReason))
|
|
89
88
|
.join(' and ');
|
|
90
89
|
}
|
|
91
90
|
return reason;
|
|
@@ -347,19 +346,13 @@ function findConflict(context, cachedFieldsAndFragmentNames, comparedFragmentPai
|
|
|
347
346
|
// in the current state of the schema, then perhaps in some future version,
|
|
348
347
|
// thus may not safely diverge.
|
|
349
348
|
const areMutuallyExclusive = parentFieldsAreMutuallyExclusive ||
|
|
350
|
-
(parentType1 !== parentType2 &&
|
|
351
|
-
isObjectType(parentType1) &&
|
|
352
|
-
isObjectType(parentType2));
|
|
349
|
+
(parentType1 !== parentType2 && isObjectType(parentType1) && isObjectType(parentType2));
|
|
353
350
|
if (!areMutuallyExclusive) {
|
|
354
351
|
// Two aliases must refer to the same field.
|
|
355
352
|
const name1 = node1.name.value;
|
|
356
353
|
const name2 = node2.name.value;
|
|
357
354
|
if (name1 !== name2) {
|
|
358
|
-
return [
|
|
359
|
-
[responseName, `"${name1}" and "${name2}" are different fields`],
|
|
360
|
-
[node1],
|
|
361
|
-
[node2],
|
|
362
|
-
];
|
|
355
|
+
return [[responseName, `"${name1}" and "${name2}" are different fields`], [node1], [node2]];
|
|
363
356
|
}
|
|
364
357
|
// Two field calls must have the same arguments.
|
|
365
358
|
if (stringifyArguments(node1) !== stringifyArguments(node2)) {
|
|
@@ -370,21 +363,14 @@ function findConflict(context, cachedFieldsAndFragmentNames, comparedFragmentPai
|
|
|
370
363
|
const directives1 = /* c8 ignore next */ node1.directives ?? [];
|
|
371
364
|
const directives2 = /* c8 ignore next */ node2.directives ?? [];
|
|
372
365
|
if (!sameStreams(directives1, directives2)) {
|
|
373
|
-
return [
|
|
374
|
-
[responseName, 'they have differing stream directives'],
|
|
375
|
-
[node1],
|
|
376
|
-
[node2],
|
|
377
|
-
];
|
|
366
|
+
return [[responseName, 'they have differing stream directives'], [node1], [node2]];
|
|
378
367
|
}
|
|
379
368
|
// The return type for each field.
|
|
380
369
|
const type1 = def1?.type;
|
|
381
370
|
const type2 = def2?.type;
|
|
382
371
|
if (type1 && type2 && doTypesConflict(type1, type2)) {
|
|
383
372
|
return [
|
|
384
|
-
[
|
|
385
|
-
responseName,
|
|
386
|
-
`they return conflicting types "${inspect(type1)}" and "${inspect(type2)}"`,
|
|
387
|
-
],
|
|
373
|
+
[responseName, `they return conflicting types "${inspect(type1)}" and "${inspect(type2)}"`],
|
|
388
374
|
[node1],
|
|
389
375
|
[node2],
|
|
390
376
|
];
|
|
@@ -405,7 +391,7 @@ function stringifyArguments(fieldNode) {
|
|
|
405
391
|
const args = /* c8 ignore next */ fieldNode.arguments ?? [];
|
|
406
392
|
const inputObjectWithArgs = {
|
|
407
393
|
kind: Kind.OBJECT,
|
|
408
|
-
fields: args.map(
|
|
394
|
+
fields: args.map(argNode => ({
|
|
409
395
|
kind: Kind.OBJECT_FIELD,
|
|
410
396
|
name: argNode.name,
|
|
411
397
|
value: argNode.value,
|
|
@@ -414,7 +400,7 @@ function stringifyArguments(fieldNode) {
|
|
|
414
400
|
return print(sortValueNode(inputObjectWithArgs));
|
|
415
401
|
}
|
|
416
402
|
function getStreamDirective(directives) {
|
|
417
|
-
return directives.find(
|
|
403
|
+
return directives.find(directive => directive.name.value === 'stream');
|
|
418
404
|
}
|
|
419
405
|
function sameStreams(directives1, directives2) {
|
|
420
406
|
const stream1 = getStreamDirective(directives1);
|
|
@@ -435,17 +421,13 @@ function sameStreams(directives1, directives2) {
|
|
|
435
421
|
// later recursively. However List and Non-Null types must match.
|
|
436
422
|
function doTypesConflict(type1, type2) {
|
|
437
423
|
if (isListType(type1)) {
|
|
438
|
-
return isListType(type2)
|
|
439
|
-
? doTypesConflict(type1.ofType, type2.ofType)
|
|
440
|
-
: true;
|
|
424
|
+
return isListType(type2) ? doTypesConflict(type1.ofType, type2.ofType) : true;
|
|
441
425
|
}
|
|
442
426
|
if (isListType(type2)) {
|
|
443
427
|
return true;
|
|
444
428
|
}
|
|
445
429
|
if (isNonNullType(type1)) {
|
|
446
|
-
return isNonNullType(type2)
|
|
447
|
-
? doTypesConflict(type1.ofType, type2.ofType)
|
|
448
|
-
: true;
|
|
430
|
+
return isNonNullType(type2) ? doTypesConflict(type1.ofType, type2.ofType) : true;
|
|
449
431
|
}
|
|
450
432
|
if (isNonNullType(type2)) {
|
|
451
433
|
return true;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { isListType, isWrappingType
|
|
2
|
-
import { createGraphQLError, GraphQLStreamDirective
|
|
1
|
+
import { isListType, isWrappingType } from 'graphql';
|
|
2
|
+
import { createGraphQLError, GraphQLStreamDirective } from '@graphql-tools/utils';
|
|
3
3
|
/**
|
|
4
4
|
* Stream directive on list field
|
|
5
5
|
*
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphql-yoga/plugin-defer-stream",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.4-alpha-20230810153432-d9f7d423",
|
|
4
4
|
"description": "Defer/Stream plugin for GraphQL Yoga.",
|
|
5
5
|
"peerDependencies": {
|
|
6
6
|
"graphql": "^15.2.0 || ^16.0.0",
|
|
7
|
-
"graphql-yoga": "
|
|
7
|
+
"graphql-yoga": "4.0.4-alpha-20230810153432-d9f7d423"
|
|
8
8
|
},
|
|
9
9
|
"dependencies": {
|
|
10
10
|
"@graphql-tools/utils": "^10.0.0"
|