Skip to content

Commit

Permalink
Integrate into validateTypes main type cycle
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanGoncharov committed Jun 11, 2018
1 parent 09f212a commit 7b1b918
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions src/type/validate.js
Expand Up @@ -232,7 +232,11 @@ function validateName(
}

function validateTypes(context: SchemaValidationContext): void {
const validateInputObjectCircularRefs = createInputObjectCircularRefsValidator(
context,
);
const typeMap = context.schema.getTypeMap();

objectValues(typeMap).forEach(type => {
// Ensure all provided types are in fact GraphQL type.
if (!isNamedType(type)) {
Expand Down Expand Up @@ -266,11 +270,11 @@ function validateTypes(context: SchemaValidationContext): void {
} else if (isInputObjectType(type)) {
// Ensure Input Object fields are valid.
validateInputFields(context, type);

// Ensure Input Objects do not contain non-nullable circular references
validateInputObjectCircularRefs(type);
}
});

// Ensure Input Objects do not contain non-nullable circular references
validateInputObjectCircularReferences(context);
}

function validateFields(
Expand Down Expand Up @@ -563,9 +567,9 @@ function validateInputFields(
});
}

function validateInputObjectCircularReferences(
function createInputObjectCircularRefsValidator(
context: SchemaValidationContext,
): void {
) {
// Modified copy of algorithm from 'src/validation/rules/NoFragmentCycles.js'.
// Tracks already visited types to maintain O(N) and to ensure that cycles
// are not redundantly reported.
Expand All @@ -577,12 +581,7 @@ function validateInputObjectCircularReferences(
// Position in the type path
const fieldPathIndexByTypeName = Object.create(null);

const typeMap = context.schema.getTypeMap();
for (const type of objectValues(typeMap)) {
if (isInputObjectType(type)) {
detectCycleRecursive(type);
}
}
return detectCycleRecursive;

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

0 comments on commit 7b1b918

Please sign in to comment.