@graphql-tools/wrap 10.0.4 → 10.0.5
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.
|
@@ -13,26 +13,35 @@ class TransformQuery {
|
|
|
13
13
|
transformRequest(originalRequest, delegationContext, transformationContext) {
|
|
14
14
|
const pathLength = this.path.length;
|
|
15
15
|
let index = 0;
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
16
|
+
const operationAst = (0, utils_1.getOperationASTFromRequest)(originalRequest);
|
|
17
|
+
const document = {
|
|
18
|
+
kind: graphql_1.Kind.DOCUMENT,
|
|
19
|
+
definitions: originalRequest.document.definitions.map(def => {
|
|
20
|
+
if (def === operationAst) {
|
|
21
|
+
return (0, graphql_1.visit)(def, {
|
|
22
|
+
[graphql_1.Kind.FIELD]: {
|
|
23
|
+
enter: node => {
|
|
24
|
+
if (index === pathLength || node.name.value !== this.path[index]) {
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
index++;
|
|
28
|
+
if (index === pathLength) {
|
|
29
|
+
const selectionSet = this.queryTransformer(node.selectionSet, this.fragments, delegationContext, transformationContext);
|
|
30
|
+
return {
|
|
31
|
+
...node,
|
|
32
|
+
selectionSet,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
leave: () => {
|
|
37
|
+
index--;
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
return def;
|
|
43
|
+
}),
|
|
44
|
+
};
|
|
36
45
|
return {
|
|
37
46
|
...originalRequest,
|
|
38
47
|
document,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Kind, visit } from 'graphql';
|
|
2
|
-
import { relocatedError } from '@graphql-tools/utils';
|
|
1
|
+
import { Kind, visit, } from 'graphql';
|
|
2
|
+
import { getOperationASTFromRequest, relocatedError, } from '@graphql-tools/utils';
|
|
3
3
|
export default class TransformQuery {
|
|
4
4
|
constructor({ path, queryTransformer, resultTransformer = result => result, errorPathTransformer = errorPath => [...errorPath], fragments = {}, }) {
|
|
5
5
|
this.path = path;
|
|
@@ -11,26 +11,35 @@ export default class TransformQuery {
|
|
|
11
11
|
transformRequest(originalRequest, delegationContext, transformationContext) {
|
|
12
12
|
const pathLength = this.path.length;
|
|
13
13
|
let index = 0;
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
14
|
+
const operationAst = getOperationASTFromRequest(originalRequest);
|
|
15
|
+
const document = {
|
|
16
|
+
kind: Kind.DOCUMENT,
|
|
17
|
+
definitions: originalRequest.document.definitions.map(def => {
|
|
18
|
+
if (def === operationAst) {
|
|
19
|
+
return visit(def, {
|
|
20
|
+
[Kind.FIELD]: {
|
|
21
|
+
enter: node => {
|
|
22
|
+
if (index === pathLength || node.name.value !== this.path[index]) {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
index++;
|
|
26
|
+
if (index === pathLength) {
|
|
27
|
+
const selectionSet = this.queryTransformer(node.selectionSet, this.fragments, delegationContext, transformationContext);
|
|
28
|
+
return {
|
|
29
|
+
...node,
|
|
30
|
+
selectionSet,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
leave: () => {
|
|
35
|
+
index--;
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
return def;
|
|
41
|
+
}),
|
|
42
|
+
};
|
|
34
43
|
return {
|
|
35
44
|
...originalRequest,
|
|
36
45
|
document,
|