@envelop/fragment-arguments 3.4.0-alpha-e9434aa.0 → 3.4.0-alpha-731c100.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/esm/extended-parser.js +13 -17
- package/esm/index.js +6 -11
- package/esm/utils.js +5 -9
- package/package.json +2 -2
package/esm/extended-parser.js
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.FragmentArgumentCompatibleParser = void 0;
|
|
4
1
|
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
class FragmentArgumentCompatibleParser extends
|
|
2
|
+
import { Parser } from 'graphql/language/parser.js';
|
|
3
|
+
import { TokenKind, Kind, Location } from 'graphql';
|
|
4
|
+
export class FragmentArgumentCompatibleParser extends Parser {
|
|
8
5
|
// see https://github.com/graphql/graphql-js/pull/3248
|
|
9
6
|
getLexer() {
|
|
10
7
|
return this._lexer;
|
|
@@ -18,19 +15,19 @@ class FragmentArgumentCompatibleParser extends parser_js_1.Parser {
|
|
|
18
15
|
var _a;
|
|
19
16
|
if (((_a = this.getOptions()) === null || _a === void 0 ? void 0 : _a.noLocation) !== true) {
|
|
20
17
|
const lexer = this.getLexer();
|
|
21
|
-
return new
|
|
18
|
+
return new Location(startToken, lexer.lastToken, lexer.source);
|
|
22
19
|
}
|
|
23
20
|
return undefined;
|
|
24
21
|
}
|
|
25
22
|
parseFragment() {
|
|
26
23
|
const start = this.getLexer().token;
|
|
27
|
-
this.expectToken(
|
|
24
|
+
this.expectToken(TokenKind.SPREAD);
|
|
28
25
|
const hasTypeCondition = this.expectOptionalKeyword('on');
|
|
29
|
-
if (!hasTypeCondition && this.peek(
|
|
26
|
+
if (!hasTypeCondition && this.peek(TokenKind.NAME)) {
|
|
30
27
|
const name = this.parseFragmentName();
|
|
31
|
-
if (this.peek(
|
|
28
|
+
if (this.peek(TokenKind.PAREN_L)) {
|
|
32
29
|
return {
|
|
33
|
-
kind:
|
|
30
|
+
kind: Kind.FRAGMENT_SPREAD,
|
|
34
31
|
name,
|
|
35
32
|
arguments: this.parseArguments(),
|
|
36
33
|
directives: this.parseDirectives(),
|
|
@@ -38,14 +35,14 @@ class FragmentArgumentCompatibleParser extends parser_js_1.Parser {
|
|
|
38
35
|
};
|
|
39
36
|
}
|
|
40
37
|
return {
|
|
41
|
-
kind:
|
|
38
|
+
kind: Kind.FRAGMENT_SPREAD,
|
|
42
39
|
name: this.parseFragmentName(),
|
|
43
40
|
directives: this.parseDirectives(),
|
|
44
41
|
loc: this.loc(start),
|
|
45
42
|
};
|
|
46
43
|
}
|
|
47
44
|
return {
|
|
48
|
-
kind:
|
|
45
|
+
kind: Kind.INLINE_FRAGMENT,
|
|
49
46
|
typeCondition: hasTypeCondition ? this.parseNamedType() : undefined,
|
|
50
47
|
directives: this.parseDirectives(),
|
|
51
48
|
selectionSet: this.parseSelectionSet(),
|
|
@@ -56,9 +53,9 @@ class FragmentArgumentCompatibleParser extends parser_js_1.Parser {
|
|
|
56
53
|
const start = this.getLexer().token;
|
|
57
54
|
this.expectKeyword('fragment');
|
|
58
55
|
const name = this.parseFragmentName();
|
|
59
|
-
if (this.peek(
|
|
56
|
+
if (this.peek(TokenKind.PAREN_L)) {
|
|
60
57
|
const fragmentDefinition = {
|
|
61
|
-
kind:
|
|
58
|
+
kind: Kind.FRAGMENT_DEFINITION,
|
|
62
59
|
name,
|
|
63
60
|
variableDefinitions: this.parseVariableDefinitions(),
|
|
64
61
|
typeCondition: (this.expectKeyword('on'), this.parseNamedType()),
|
|
@@ -69,7 +66,7 @@ class FragmentArgumentCompatibleParser extends parser_js_1.Parser {
|
|
|
69
66
|
return fragmentDefinition;
|
|
70
67
|
}
|
|
71
68
|
const fragmentDefinition = {
|
|
72
|
-
kind:
|
|
69
|
+
kind: Kind.FRAGMENT_DEFINITION,
|
|
73
70
|
name,
|
|
74
71
|
typeCondition: (this.expectKeyword('on'), this.parseNamedType()),
|
|
75
72
|
directives: this.parseDirectives(),
|
|
@@ -79,4 +76,3 @@ class FragmentArgumentCompatibleParser extends parser_js_1.Parser {
|
|
|
79
76
|
return fragmentDefinition;
|
|
80
77
|
}
|
|
81
78
|
}
|
|
82
|
-
exports.FragmentArgumentCompatibleParser = FragmentArgumentCompatibleParser;
|
package/esm/index.js
CHANGED
|
@@ -1,23 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
const utils_js_1 = require("./utils.js");
|
|
6
|
-
function parseWithFragmentArguments(source, options) {
|
|
7
|
-
const parser = new extended_parser_js_1.FragmentArgumentCompatibleParser(source, options);
|
|
1
|
+
import { FragmentArgumentCompatibleParser } from './extended-parser.js';
|
|
2
|
+
import { applySelectionSetFragmentArguments } from './utils.js';
|
|
3
|
+
export function parseWithFragmentArguments(source, options) {
|
|
4
|
+
const parser = new FragmentArgumentCompatibleParser(source, options);
|
|
8
5
|
return parser.parseDocument();
|
|
9
6
|
}
|
|
10
|
-
|
|
11
|
-
const useFragmentArguments = () => {
|
|
7
|
+
export const useFragmentArguments = () => {
|
|
12
8
|
return {
|
|
13
9
|
onParse({ setParseFn }) {
|
|
14
10
|
setParseFn(parseWithFragmentArguments);
|
|
15
11
|
return ({ result, replaceParseResult }) => {
|
|
16
12
|
if (result && 'kind' in result) {
|
|
17
|
-
replaceParseResult(
|
|
13
|
+
replaceParseResult(applySelectionSetFragmentArguments(result));
|
|
18
14
|
}
|
|
19
15
|
};
|
|
20
16
|
},
|
|
21
17
|
};
|
|
22
18
|
};
|
|
23
|
-
exports.useFragmentArguments = useFragmentArguments;
|
package/esm/utils.js
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.applySelectionSetFragmentArguments = void 0;
|
|
4
|
-
const graphql_1 = require("graphql");
|
|
5
|
-
function applySelectionSetFragmentArguments(document) {
|
|
1
|
+
import { visit, Kind } from 'graphql';
|
|
2
|
+
export function applySelectionSetFragmentArguments(document) {
|
|
6
3
|
const fragmentList = new Map();
|
|
7
4
|
for (const def of document.definitions) {
|
|
8
5
|
if (def.kind !== 'FragmentDefinition') {
|
|
@@ -10,7 +7,7 @@ function applySelectionSetFragmentArguments(document) {
|
|
|
10
7
|
}
|
|
11
8
|
fragmentList.set(def.name.value, def);
|
|
12
9
|
}
|
|
13
|
-
return
|
|
10
|
+
return visit(document, {
|
|
14
11
|
FragmentSpread(fragmentNode) {
|
|
15
12
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
16
13
|
// @ts-ignore
|
|
@@ -25,7 +22,7 @@ function applySelectionSetFragmentArguments(document) {
|
|
|
25
22
|
for (const arg of fragmentNode.arguments) {
|
|
26
23
|
fragmentArguments.set(arg.name.value, arg);
|
|
27
24
|
}
|
|
28
|
-
const selectionSet =
|
|
25
|
+
const selectionSet = visit(fragmentDef.selectionSet, {
|
|
29
26
|
Variable(variableNode) {
|
|
30
27
|
const fragArg = fragmentArguments.get(variableNode.name.value);
|
|
31
28
|
if (fragArg) {
|
|
@@ -35,7 +32,7 @@ function applySelectionSetFragmentArguments(document) {
|
|
|
35
32
|
},
|
|
36
33
|
});
|
|
37
34
|
const inlineFragment = {
|
|
38
|
-
kind:
|
|
35
|
+
kind: Kind.INLINE_FRAGMENT,
|
|
39
36
|
typeCondition: fragmentDef.typeCondition,
|
|
40
37
|
selectionSet,
|
|
41
38
|
};
|
|
@@ -45,4 +42,3 @@ function applySelectionSetFragmentArguments(document) {
|
|
|
45
42
|
},
|
|
46
43
|
});
|
|
47
44
|
}
|
|
48
|
-
exports.applySelectionSetFragmentArguments = applySelectionSetFragmentArguments;
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@envelop/fragment-arguments",
|
|
3
|
-
"version": "3.4.0-alpha-
|
|
3
|
+
"version": "3.4.0-alpha-731c100.0",
|
|
4
4
|
"peerDependencies": {
|
|
5
|
-
"@envelop/core": "2.4.0-alpha-
|
|
5
|
+
"@envelop/core": "2.4.0-alpha-731c100.0",
|
|
6
6
|
"graphql": "^14.0.0 || ^15.0.0 || ^16.0.0"
|
|
7
7
|
},
|
|
8
8
|
"dependencies": {},
|