Skip to content

Commit fda0774

Browse files
committed
Integrate into validateTypes main type cycle
1 parent d4a3f70 commit fda0774

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

src/type/validate.js

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,11 @@ function validateName(
232232
}
233233

234234
function validateTypes(context: SchemaValidationContext): void {
235+
const validateInputObjectCircularRefs = createInputObjectCircularRefsValidator(
236+
context,
237+
);
235238
const typeMap = context.schema.getTypeMap();
239+
236240
objectValues(typeMap).forEach(type => {
237241
// Ensure all provided types are in fact GraphQL type.
238242
if (!isNamedType(type)) {
@@ -269,11 +273,11 @@ function validateTypes(context: SchemaValidationContext): void {
269273
} else if (isInputObjectType(type)) {
270274
// Ensure Input Object fields are valid.
271275
validateInputFields(context, type);
276+
277+
// Ensure Input Objects do not contain non-nullable circular references
278+
validateInputObjectCircularRefs(type);
272279
}
273280
});
274-
275-
// Ensure Input Objects do not contain non-nullable circular references
276-
validateInputObjectCircularReferences(context);
277281
}
278282

279283
function validateFields(
@@ -581,9 +585,9 @@ function validateInputFields(
581585
});
582586
}
583587

584-
function validateInputObjectCircularReferences(
588+
function createInputObjectCircularRefsValidator(
585589
context: SchemaValidationContext,
586-
): void {
590+
) {
587591
// Modified copy of algorithm from 'src/validation/rules/NoFragmentCycles.js'.
588592
// Tracks already visited types to maintain O(N) and to ensure that cycles
589593
// are not redundantly reported.
@@ -595,12 +599,7 @@ function validateInputObjectCircularReferences(
595599
// Position in the type path
596600
const fieldPathIndexByTypeName = Object.create(null);
597601

598-
const typeMap = context.schema.getTypeMap();
599-
for (const type of objectValues(typeMap)) {
600-
if (isInputObjectType(type)) {
601-
detectCycleRecursive(type);
602-
}
603-
}
602+
return detectCycleRecursive;
604603

605604
// This does a straight-forward DFS to find cycles.
606605
// It does not terminate when a cycle was found but continues to explore

0 commit comments

Comments
 (0)