Search in sources :

Example 1 with FragmentDefinition

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);
}
Also used : GraphQLOutputType(graphql.schema.GraphQLOutputType) FragmentDefinition(graphql.language.FragmentDefinition)

Example 2 with FragmentDefinition

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);
    }
}
Also used : FragmentDefinition(graphql.language.FragmentDefinition) GraphQLCompositeType(graphql.schema.GraphQLCompositeType) GraphQLType(graphql.schema.GraphQLType)

Example 3 with FragmentDefinition

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);
    }
}
Also used : FragmentDefinition(graphql.language.FragmentDefinition)

Example 4 with FragmentDefinition

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));
        }
    }
}
Also used : FragmentDefinition(graphql.language.FragmentDefinition) Definition(graphql.language.Definition) FragmentDefinition(graphql.language.FragmentDefinition)

Example 5 with 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);
        }
    }
}
Also used : FragmentDefinition(graphql.language.FragmentDefinition) ArrayList(java.util.ArrayList)

Aggregations

FragmentDefinition (graphql.language.FragmentDefinition)10 Definition (graphql.language.Definition)2 ExecutionResultImpl (graphql.ExecutionResultImpl)1 GraphQLError (graphql.GraphQLError)1 InstrumentationExecutionParameters (graphql.execution.instrumentation.parameters.InstrumentationExecutionParameters)1 Directive (graphql.language.Directive)1 EnumTypeDefinition (graphql.language.EnumTypeDefinition)1 EnumValueDefinition (graphql.language.EnumValueDefinition)1 InlineFragment (graphql.language.InlineFragment)1 InputObjectTypeDefinition (graphql.language.InputObjectTypeDefinition)1 InputValueDefinition (graphql.language.InputValueDefinition)1 NodeUtil (graphql.language.NodeUtil)1 OperationDefinition (graphql.language.OperationDefinition)1 ScalarTypeDefinition (graphql.language.ScalarTypeDefinition)1 TypeName (graphql.language.TypeName)1 VariableDefinition (graphql.language.VariableDefinition)1 GraphQLCompositeType (graphql.schema.GraphQLCompositeType)1 GraphQLFieldDefinition (graphql.schema.GraphQLFieldDefinition)1 GraphQLOutputType (graphql.schema.GraphQLOutputType)1 GraphQLType (graphql.schema.GraphQLType)1