Skip to content

Commit 7a51d5e

Browse files
authored
Merge pull request #21 from lirown/lirown-tree-iteration-support-old-version
fixes
2 parents fb70995 + a723391 commit 7a51d5e

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "graphql-custom-directives",
3-
"version": "0.2.10",
3+
"version": "0.2.11",
44
"description": "Create custom graphql directives with the ability to hook the execution of graphql",
55
"main": "dist/index.js",
66
"scripts": {

src/custom.js

+10-10
Original file line numberDiff line numberDiff line change
@@ -141,11 +141,10 @@ function resolveMiddlewareWrapper(resolve = defaultResolveFn, directives = {}) {
141141
* Scanning the shema and wrapping the resolve of each field with the support
142142
* of the graphql custom directives resolve execution
143143
*/
144-
function wrapFieldsWithMiddleware(type, deepWrap = true, typeMet = {}) {
144+
function wrapFieldsWithMiddleware(type, deepWrap = true, typeMet = {}, level = 1) {
145145
if (!type) {
146146
return;
147147
}
148-
149148
let fields = type._fields;
150149
typeMet[type.name] = true;
151150
for (let label in fields) {
@@ -157,21 +156,22 @@ function wrapFieldsWithMiddleware(type, deepWrap = true, typeMet = {}) {
157156
field.directives,
158157
);
159158
if (field.type._fields && deepWrap) {
160-
wrapFieldsWithMiddleware(field.type, deepWrap, typeMet);
159+
wrapFieldsWithMiddleware(field.type, deepWrap, typeMet, level);
161160
} else if (field.type.ofType && field.type.ofType._fields && deepWrap) {
162-
let child = field.type;
163-
while (child.ofType) {
164-
child = child.ofType;
165-
}
166-
if (child._fields) {
167-
wrapFieldsWithMiddleware(child._fields);
161+
if (level >= 6) {
162+
continue;
168163
}
164+
wrapFieldsWithMiddleware(
165+
field.type.ofType,
166+
deepWrap,
167+
typeMet,
168+
++level,
169+
);
169170
}
170171
}
171172
}
172173
}
173174
}
174-
175175
/**
176176
* create a new graphql custom directive which contain a resolve
177177
* function for altering the execution of the graphql

0 commit comments

Comments
 (0)