use of graphql.language.FragmentDefinition in project graphql-java by graphql-java.
the class OverlappingFieldsCanBeMerged method collectFieldsForFragmentSpread.
private void collectFieldsForFragmentSpread(Map<String, List<FieldAndType>> fieldMap, Set<String> visitedFragmentSpreads, FragmentSpread fragmentSpread) {
FragmentDefinition fragment = getValidationContext().getFragment(fragmentSpread.getName());
if (fragment == null)
return;
if (visitedFragmentSpreads.contains(fragment.getName())) {
return;
}
visitedFragmentSpreads.add(fragment.getName());
GraphQLOutputType graphQLType = (GraphQLOutputType) TypeFromAST.getTypeFromAST(getValidationContext().getSchema(), fragment.getTypeCondition());
collectFields(fieldMap, fragment.getSelectionSet(), graphQLType, visitedFragmentSpreads);
}
use of graphql.language.FragmentDefinition in project graphql-java by graphql-java.
the class PossibleFragmentSpreads method checkFragmentSpread.
@Override
public void checkFragmentSpread(FragmentSpread fragmentSpread) {
FragmentDefinition fragment = getValidationContext().getFragment(fragmentSpread.getName());
if (fragment == null)
return;
GraphQLType typeCondition = TypeFromAST.getTypeFromAST(getValidationContext().getSchema(), fragment.getTypeCondition());
GraphQLCompositeType parentType = getValidationContext().getParentType();
if (typeCondition == null || parentType == null)
return;
if (!doTypesOverlap(typeCondition, parentType)) {
String message = String.format("Fragment %s cannot be spread here as objects of " + "type %s can never be of type %s", fragmentSpread.getName(), parentType, typeCondition);
addError(ValidationErrorType.InvalidFragmentType, fragmentSpread.getSourceLocation(), message);
}
}
use of graphql.language.FragmentDefinition in project graphql-java by graphql-java.
the class KnownFragmentNames method checkFragmentSpread.
@Override
public void checkFragmentSpread(FragmentSpread fragmentSpread) {
FragmentDefinition fragmentDefinition = getValidationContext().getFragment(fragmentSpread.getName());
if (fragmentDefinition == null) {
String message = String.format("Undefined fragment %s", fragmentSpread.getName());
addError(ValidationErrorType.UndefinedFragment, fragmentSpread.getSourceLocation(), message);
}
}
use of graphql.language.FragmentDefinition in project graphql-java by graphql-java.
the class NoFragmentCycles method prepareFragmentMap.
private void prepareFragmentMap() {
List<Definition> definitions = getValidationContext().getDocument().getDefinitions();
for (Definition definition : definitions) {
if (definition instanceof FragmentDefinition) {
FragmentDefinition fragmentDefinition = (FragmentDefinition) definition;
fragmentSpreads.put(fragmentDefinition.getName(), gatherSpreads(fragmentDefinition));
}
}
}
use of graphql.language.FragmentDefinition in project graphql-java by graphql-java.
the class NoUnusedFragments method documentFinished.
@Override
public void documentFinished(Document document) {
List<String> allUsedFragments = new ArrayList<>();
for (List<String> fragmentsInOneOperation : fragmentsUsedDirectlyInOperation) {
for (String fragment : fragmentsInOneOperation) {
collectUsedFragmentsInDefinition(allUsedFragments, fragment);
}
}
for (FragmentDefinition fragmentDefinition : allDeclaredFragments) {
if (!allUsedFragments.contains(fragmentDefinition.getName())) {
String message = String.format("Unused fragment %s", fragmentDefinition.getName());
addError(ValidationErrorType.UnusedFragment, fragmentDefinition.getSourceLocation(), message);
}
}
}
Aggregations