Search in sources :

Example 6 with GraphQLCompositeType

use of graphql.schema.GraphQLCompositeType in project graphql-java by graphql-java.

the class QueryTraversal method visitImpl.

private void visitImpl(FieldVisitor visitFieldCallback, SelectionSet selectionSet, GraphQLCompositeType type, boolean preOrder) {
    Map<Class<?>, Object> rootVars = new LinkedHashMap<>();
    rootVars.put(QueryTraversalContext.class, new QueryTraversalContext(type, null));
    FieldVisitor noOp = notUsed -> {
    };
    FieldVisitor preOrderCallback = preOrder ? visitFieldCallback : noOp;
    FieldVisitor postOrderCallback = !preOrder ? visitFieldCallback : noOp;
    NodeTraverser nodeTraverser = new NodeTraverser(rootVars, this::childrenOf);
    nodeTraverser.depthFirst(new NodeVisitorImpl(preOrderCallback, postOrderCallback), selectionSet.getSelections());
}
Also used : OperationDefinition(graphql.language.OperationDefinition) Internal(graphql.Internal) Node(graphql.language.Node) NodeUtil(graphql.language.NodeUtil) TraversalControl(graphql.util.TraversalControl) ValuesResolver(graphql.execution.ValuesResolver) GraphQLFieldDefinition(graphql.schema.GraphQLFieldDefinition) FragmentSpread(graphql.language.FragmentSpread) LeaveOrEnter(graphql.language.NodeTraverser.LeaveOrEnter) TraverserContext(graphql.util.TraverserContext) Introspection(graphql.introspection.Introspection) LinkedHashMap(java.util.LinkedHashMap) Selection(graphql.language.Selection) Assert.assertShouldNeverHappen(graphql.Assert.assertShouldNeverHappen) NodeTraverser(graphql.language.NodeTraverser) Map(java.util.Map) GraphQLCompositeType(graphql.schema.GraphQLCompositeType) GraphQLSchema(graphql.schema.GraphQLSchema) TypeName(graphql.language.TypeName) SelectionSet(graphql.language.SelectionSet) GraphQLObjectType(graphql.schema.GraphQLObjectType) NodeVisitorStub(graphql.language.NodeVisitorStub) GraphQLUnmodifiedType(graphql.schema.GraphQLUnmodifiedType) Field(graphql.language.Field) SchemaUtil(graphql.schema.SchemaUtil) Document(graphql.language.Document) List(java.util.List) LEAVE(graphql.language.NodeTraverser.LeaveOrEnter.LEAVE) Assert.assertNotNull(graphql.Assert.assertNotNull) ConditionalNodes(graphql.execution.ConditionalNodes) FragmentDefinition(graphql.language.FragmentDefinition) InlineFragment(graphql.language.InlineFragment) NodeTraverser(graphql.language.NodeTraverser) LinkedHashMap(java.util.LinkedHashMap)

Example 7 with GraphQLCompositeType

use of graphql.schema.GraphQLCompositeType in project graphql-java by graphql-java.

the class FragmentsOnCompositeType method checkFragmentDefinition.

@Override
public void checkFragmentDefinition(FragmentDefinition fragmentDefinition) {
    GraphQLType type = getValidationContext().getSchema().getType(fragmentDefinition.getTypeCondition().getName());
    if (type == null)
        return;
    if (!(type instanceof GraphQLCompositeType)) {
        String message = "Fragment type condition is invalid, must be on Object/Interface/Union";
        addError(ValidationErrorType.InlineFragmentTypeConditionInvalid, fragmentDefinition.getSourceLocation(), message);
    }
}
Also used : GraphQLCompositeType(graphql.schema.GraphQLCompositeType) GraphQLType(graphql.schema.GraphQLType)

Example 8 with GraphQLCompositeType

use of graphql.schema.GraphQLCompositeType in project graphql-java by graphql-java.

the class FragmentsOnCompositeType method checkInlineFragment.

@Override
public void checkInlineFragment(InlineFragment inlineFragment) {
    if (inlineFragment.getTypeCondition() == null) {
        return;
    }
    GraphQLType type = getValidationContext().getSchema().getType(inlineFragment.getTypeCondition().getName());
    if (type == null)
        return;
    if (!(type instanceof GraphQLCompositeType)) {
        String message = "Inline fragment type condition is invalid, must be on Object/Interface/Union";
        addError(ValidationErrorType.InlineFragmentTypeConditionInvalid, inlineFragment.getSourceLocation(), message);
    }
}
Also used : GraphQLCompositeType(graphql.schema.GraphQLCompositeType) GraphQLType(graphql.schema.GraphQLType)

Aggregations

GraphQLCompositeType (graphql.schema.GraphQLCompositeType)8 GraphQLFieldDefinition (graphql.schema.GraphQLFieldDefinition)3 GraphQLType (graphql.schema.GraphQLType)3 FragmentDefinition (graphql.language.FragmentDefinition)2 GraphQLUnmodifiedType (graphql.schema.GraphQLUnmodifiedType)2 SchemaUtil (graphql.schema.SchemaUtil)2 Assert.assertNotNull (graphql.Assert.assertNotNull)1 Assert.assertShouldNeverHappen (graphql.Assert.assertShouldNeverHappen)1 Internal (graphql.Internal)1 ConditionalNodes (graphql.execution.ConditionalNodes)1 ValuesResolver (graphql.execution.ValuesResolver)1 Introspection (graphql.introspection.Introspection)1 Document (graphql.language.Document)1 Field (graphql.language.Field)1 FragmentSpread (graphql.language.FragmentSpread)1 InlineFragment (graphql.language.InlineFragment)1 Node (graphql.language.Node)1 NodeTraverser (graphql.language.NodeTraverser)1 LeaveOrEnter (graphql.language.NodeTraverser.LeaveOrEnter)1 LEAVE (graphql.language.NodeTraverser.LeaveOrEnter.LEAVE)1