@luvio/graphql-parser 0.128.0 → 0.130.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/dist/luvioGraphqlParser.js +60 -39
- package/dist/luvioGraphqlParser.mjs +60 -39
- package/package.json +1 -1
|
@@ -12788,7 +12788,7 @@ function gql(literals, ...subs) {
|
|
|
12788
12788
|
return updateReferenceMapAndGetKey(insertFragments(document, inputSubstitutionFragments));
|
|
12789
12789
|
}
|
|
12790
12790
|
|
|
12791
|
-
const
|
|
12791
|
+
const DIRECTIVE_RECORD_QUERY_CATEGORY = {
|
|
12792
12792
|
kind: 'Directive',
|
|
12793
12793
|
name: {
|
|
12794
12794
|
kind: 'Name',
|
|
@@ -12809,6 +12809,27 @@ const DIRECTIVE_RECORD_CATEGORY = {
|
|
|
12809
12809
|
},
|
|
12810
12810
|
],
|
|
12811
12811
|
};
|
|
12812
|
+
const DIRECTIVE_CHILD_RELATIONSHIP_CATEGORY = {
|
|
12813
|
+
kind: 'Directive',
|
|
12814
|
+
name: {
|
|
12815
|
+
kind: 'Name',
|
|
12816
|
+
value: 'category',
|
|
12817
|
+
},
|
|
12818
|
+
arguments: [
|
|
12819
|
+
{
|
|
12820
|
+
kind: 'Argument',
|
|
12821
|
+
name: {
|
|
12822
|
+
kind: 'Name',
|
|
12823
|
+
value: 'name',
|
|
12824
|
+
},
|
|
12825
|
+
value: {
|
|
12826
|
+
kind: 'StringValue',
|
|
12827
|
+
value: 'childRelationship',
|
|
12828
|
+
block: false,
|
|
12829
|
+
},
|
|
12830
|
+
},
|
|
12831
|
+
],
|
|
12832
|
+
};
|
|
12812
12833
|
const DIRECTIVE_PARENT_CATEGORY = {
|
|
12813
12834
|
kind: 'Directive',
|
|
12814
12835
|
name: {
|
|
@@ -12830,15 +12851,22 @@ const DIRECTIVE_PARENT_CATEGORY = {
|
|
|
12830
12851
|
},
|
|
12831
12852
|
],
|
|
12832
12853
|
};
|
|
12833
|
-
function substituteDirectives(directives, index,
|
|
12854
|
+
function substituteDirectives(directives, index, selection, parentNode) {
|
|
12834
12855
|
if (directives[index].name.value === CUSTOM_DIRECTIVE_CONNECTION) {
|
|
12835
|
-
|
|
12836
|
-
|
|
12837
|
-
|
|
12856
|
+
if (parentNode !== undefined &&
|
|
12857
|
+
parentNode.kind === 'Field' &&
|
|
12858
|
+
parentNode.name.value === 'uiapi') {
|
|
12859
|
+
// @ts-ignore - Document is read only
|
|
12860
|
+
directives[index] = DIRECTIVE_RECORD_QUERY_CATEGORY;
|
|
12861
|
+
}
|
|
12862
|
+
else {
|
|
12863
|
+
// @ts-ignore - Document is read only
|
|
12864
|
+
directives[index] = DIRECTIVE_CHILD_RELATIONSHIP_CATEGORY;
|
|
12865
|
+
}
|
|
12838
12866
|
}
|
|
12839
12867
|
else if (directives[index].name.value === CUSTOM_DIRECTIVE_RESOURCE) {
|
|
12840
|
-
// node gets its type from @category recordQuery
|
|
12841
|
-
if (
|
|
12868
|
+
// node gets its type from @category recordQuery or @category childRelationship
|
|
12869
|
+
if (selection.kind === 'Field' && selection.name.value === 'node') {
|
|
12842
12870
|
// @ts-ignore - Document is read only
|
|
12843
12871
|
directives.splice(index, 1);
|
|
12844
12872
|
}
|
|
@@ -12858,34 +12886,31 @@ function isCustomDirective(node) {
|
|
|
12858
12886
|
node.name.value === CUSTOM_DIRECTIVE_RESOURCE);
|
|
12859
12887
|
}
|
|
12860
12888
|
/**
|
|
12861
|
-
* Traverses a selection
|
|
12889
|
+
* Traverses a selection and it's nested selections,
|
|
12862
12890
|
* to find any legacy custom directives and substitute them with metaschema directives
|
|
12863
|
-
* @param node -
|
|
12864
|
-
* @returns
|
|
12891
|
+
* @param node - SelectionNode
|
|
12892
|
+
* @returns void
|
|
12865
12893
|
*/
|
|
12866
|
-
function
|
|
12867
|
-
if (node === undefined) {
|
|
12894
|
+
function traverseSelection(node, parentNode) {
|
|
12895
|
+
if (node === undefined || node.kind === 'FragmentSpread' || node.selectionSet === undefined) {
|
|
12868
12896
|
return;
|
|
12869
12897
|
}
|
|
12870
|
-
|
|
12871
|
-
|
|
12872
|
-
|
|
12873
|
-
|
|
12874
|
-
|
|
12875
|
-
|
|
12876
|
-
|
|
12877
|
-
|
|
12878
|
-
|
|
12879
|
-
|
|
12880
|
-
|
|
12881
|
-
|
|
12882
|
-
|
|
12883
|
-
|
|
12884
|
-
}
|
|
12898
|
+
const { selectionSet } = node;
|
|
12899
|
+
for (const selection of selectionSet.selections) {
|
|
12900
|
+
replaceCustomDirectives(selection, parentNode);
|
|
12901
|
+
traverseSelection(selection, node);
|
|
12902
|
+
}
|
|
12903
|
+
}
|
|
12904
|
+
function replaceCustomDirectives(selection, parentNode) {
|
|
12905
|
+
const { directives } = selection;
|
|
12906
|
+
if (directives !== undefined && directives.length > 0) {
|
|
12907
|
+
// we follow this pattern instead of map to preserve the order of directives
|
|
12908
|
+
// order of directives may be significant as per graphql spec
|
|
12909
|
+
const index = directives.findIndex(isCustomDirective);
|
|
12910
|
+
if (index !== -1) {
|
|
12911
|
+
substituteDirectives(directives, index, selection, parentNode);
|
|
12885
12912
|
}
|
|
12886
|
-
traverseSelectionSet(selectionSet);
|
|
12887
12913
|
}
|
|
12888
|
-
return node;
|
|
12889
12914
|
}
|
|
12890
12915
|
/**
|
|
12891
12916
|
* Accepts a document node and replaces the legacy custom directives with metaschema directives "in-place"
|
|
@@ -12897,16 +12922,12 @@ function metaschemaMapper(doc) {
|
|
|
12897
12922
|
// so we have to explicitly cast the definitions for ts
|
|
12898
12923
|
const { definitions } = doc;
|
|
12899
12924
|
for (const def of definitions) {
|
|
12900
|
-
const {
|
|
12901
|
-
|
|
12902
|
-
|
|
12903
|
-
|
|
12904
|
-
|
|
12905
|
-
|
|
12906
|
-
substituteDirectives(directives, index, undefined);
|
|
12907
|
-
}
|
|
12908
|
-
}
|
|
12909
|
-
traverseSelectionSet(selectionSet);
|
|
12925
|
+
const { selectionSet } = def;
|
|
12926
|
+
// This is just iterating through the top level 'Query' operations. There should never be any custom
|
|
12927
|
+
// directives at this level, as RecordQuery is actually a field lower in the schema. So we can skip looking for them.
|
|
12928
|
+
selectionSet.selections.forEach((selection) => {
|
|
12929
|
+
traverseSelection(selection);
|
|
12930
|
+
});
|
|
12910
12931
|
}
|
|
12911
12932
|
}
|
|
12912
12933
|
|
|
@@ -12784,7 +12784,7 @@ function gql(literals, ...subs) {
|
|
|
12784
12784
|
return updateReferenceMapAndGetKey(insertFragments(document, inputSubstitutionFragments));
|
|
12785
12785
|
}
|
|
12786
12786
|
|
|
12787
|
-
const
|
|
12787
|
+
const DIRECTIVE_RECORD_QUERY_CATEGORY = {
|
|
12788
12788
|
kind: 'Directive',
|
|
12789
12789
|
name: {
|
|
12790
12790
|
kind: 'Name',
|
|
@@ -12805,6 +12805,27 @@ const DIRECTIVE_RECORD_CATEGORY = {
|
|
|
12805
12805
|
},
|
|
12806
12806
|
],
|
|
12807
12807
|
};
|
|
12808
|
+
const DIRECTIVE_CHILD_RELATIONSHIP_CATEGORY = {
|
|
12809
|
+
kind: 'Directive',
|
|
12810
|
+
name: {
|
|
12811
|
+
kind: 'Name',
|
|
12812
|
+
value: 'category',
|
|
12813
|
+
},
|
|
12814
|
+
arguments: [
|
|
12815
|
+
{
|
|
12816
|
+
kind: 'Argument',
|
|
12817
|
+
name: {
|
|
12818
|
+
kind: 'Name',
|
|
12819
|
+
value: 'name',
|
|
12820
|
+
},
|
|
12821
|
+
value: {
|
|
12822
|
+
kind: 'StringValue',
|
|
12823
|
+
value: 'childRelationship',
|
|
12824
|
+
block: false,
|
|
12825
|
+
},
|
|
12826
|
+
},
|
|
12827
|
+
],
|
|
12828
|
+
};
|
|
12808
12829
|
const DIRECTIVE_PARENT_CATEGORY = {
|
|
12809
12830
|
kind: 'Directive',
|
|
12810
12831
|
name: {
|
|
@@ -12826,15 +12847,22 @@ const DIRECTIVE_PARENT_CATEGORY = {
|
|
|
12826
12847
|
},
|
|
12827
12848
|
],
|
|
12828
12849
|
};
|
|
12829
|
-
function substituteDirectives(directives, index,
|
|
12850
|
+
function substituteDirectives(directives, index, selection, parentNode) {
|
|
12830
12851
|
if (directives[index].name.value === CUSTOM_DIRECTIVE_CONNECTION) {
|
|
12831
|
-
|
|
12832
|
-
|
|
12833
|
-
|
|
12852
|
+
if (parentNode !== undefined &&
|
|
12853
|
+
parentNode.kind === 'Field' &&
|
|
12854
|
+
parentNode.name.value === 'uiapi') {
|
|
12855
|
+
// @ts-ignore - Document is read only
|
|
12856
|
+
directives[index] = DIRECTIVE_RECORD_QUERY_CATEGORY;
|
|
12857
|
+
}
|
|
12858
|
+
else {
|
|
12859
|
+
// @ts-ignore - Document is read only
|
|
12860
|
+
directives[index] = DIRECTIVE_CHILD_RELATIONSHIP_CATEGORY;
|
|
12861
|
+
}
|
|
12834
12862
|
}
|
|
12835
12863
|
else if (directives[index].name.value === CUSTOM_DIRECTIVE_RESOURCE) {
|
|
12836
|
-
// node gets its type from @category recordQuery
|
|
12837
|
-
if (
|
|
12864
|
+
// node gets its type from @category recordQuery or @category childRelationship
|
|
12865
|
+
if (selection.kind === 'Field' && selection.name.value === 'node') {
|
|
12838
12866
|
// @ts-ignore - Document is read only
|
|
12839
12867
|
directives.splice(index, 1);
|
|
12840
12868
|
}
|
|
@@ -12854,34 +12882,31 @@ function isCustomDirective(node) {
|
|
|
12854
12882
|
node.name.value === CUSTOM_DIRECTIVE_RESOURCE);
|
|
12855
12883
|
}
|
|
12856
12884
|
/**
|
|
12857
|
-
* Traverses a selection
|
|
12885
|
+
* Traverses a selection and it's nested selections,
|
|
12858
12886
|
* to find any legacy custom directives and substitute them with metaschema directives
|
|
12859
|
-
* @param node -
|
|
12860
|
-
* @returns
|
|
12887
|
+
* @param node - SelectionNode
|
|
12888
|
+
* @returns void
|
|
12861
12889
|
*/
|
|
12862
|
-
function
|
|
12863
|
-
if (node === undefined) {
|
|
12890
|
+
function traverseSelection(node, parentNode) {
|
|
12891
|
+
if (node === undefined || node.kind === 'FragmentSpread' || node.selectionSet === undefined) {
|
|
12864
12892
|
return;
|
|
12865
12893
|
}
|
|
12866
|
-
|
|
12867
|
-
|
|
12868
|
-
|
|
12869
|
-
|
|
12870
|
-
|
|
12871
|
-
|
|
12872
|
-
|
|
12873
|
-
|
|
12874
|
-
|
|
12875
|
-
|
|
12876
|
-
|
|
12877
|
-
|
|
12878
|
-
|
|
12879
|
-
|
|
12880
|
-
}
|
|
12894
|
+
const { selectionSet } = node;
|
|
12895
|
+
for (const selection of selectionSet.selections) {
|
|
12896
|
+
replaceCustomDirectives(selection, parentNode);
|
|
12897
|
+
traverseSelection(selection, node);
|
|
12898
|
+
}
|
|
12899
|
+
}
|
|
12900
|
+
function replaceCustomDirectives(selection, parentNode) {
|
|
12901
|
+
const { directives } = selection;
|
|
12902
|
+
if (directives !== undefined && directives.length > 0) {
|
|
12903
|
+
// we follow this pattern instead of map to preserve the order of directives
|
|
12904
|
+
// order of directives may be significant as per graphql spec
|
|
12905
|
+
const index = directives.findIndex(isCustomDirective);
|
|
12906
|
+
if (index !== -1) {
|
|
12907
|
+
substituteDirectives(directives, index, selection, parentNode);
|
|
12881
12908
|
}
|
|
12882
|
-
traverseSelectionSet(selectionSet);
|
|
12883
12909
|
}
|
|
12884
|
-
return node;
|
|
12885
12910
|
}
|
|
12886
12911
|
/**
|
|
12887
12912
|
* Accepts a document node and replaces the legacy custom directives with metaschema directives "in-place"
|
|
@@ -12893,16 +12918,12 @@ function metaschemaMapper(doc) {
|
|
|
12893
12918
|
// so we have to explicitly cast the definitions for ts
|
|
12894
12919
|
const { definitions } = doc;
|
|
12895
12920
|
for (const def of definitions) {
|
|
12896
|
-
const {
|
|
12897
|
-
|
|
12898
|
-
|
|
12899
|
-
|
|
12900
|
-
|
|
12901
|
-
|
|
12902
|
-
substituteDirectives(directives, index, undefined);
|
|
12903
|
-
}
|
|
12904
|
-
}
|
|
12905
|
-
traverseSelectionSet(selectionSet);
|
|
12921
|
+
const { selectionSet } = def;
|
|
12922
|
+
// This is just iterating through the top level 'Query' operations. There should never be any custom
|
|
12923
|
+
// directives at this level, as RecordQuery is actually a field lower in the schema. So we can skip looking for them.
|
|
12924
|
+
selectionSet.selections.forEach((selection) => {
|
|
12925
|
+
traverseSelection(selection);
|
|
12926
|
+
});
|
|
12906
12927
|
}
|
|
12907
12928
|
}
|
|
12908
12929
|
|