Search in sources :

Example 1 with GraphQLCompositeType

use of graphql.schema.GraphQLCompositeType 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 2 with GraphQLCompositeType

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

the class PossibleFragmentSpreads method checkInlineFragment.

@Override
public void checkInlineFragment(InlineFragment inlineFragment) {
    GraphQLOutputType fragType = getValidationContext().getOutputType();
    GraphQLCompositeType parentType = getValidationContext().getParentType();
    if (fragType == null || parentType == null)
        return;
    if (!doTypesOverlap(fragType, parentType)) {
        String message = String.format("Fragment cannot be spread here as objects of " + "type %s can never be of type %s", parentType, fragType);
        addError(ValidationErrorType.InvalidFragmentType, inlineFragment.getSourceLocation(), message);
    }
}
Also used : GraphQLOutputType(graphql.schema.GraphQLOutputType) GraphQLCompositeType(graphql.schema.GraphQLCompositeType)

Example 3 with GraphQLCompositeType

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

the class TraversalContext method enterImpl.

private void enterImpl(Field field) {
    enterName(field.getName());
    GraphQLCompositeType parentType = getParentType();
    GraphQLFieldDefinition fieldDefinition = null;
    if (parentType != null) {
        fieldDefinition = getFieldDef(schema, parentType, field);
    }
    addFieldDef(fieldDefinition);
    addOutputType(fieldDefinition != null ? fieldDefinition.getType() : null);
}
Also used : GraphQLCompositeType(graphql.schema.GraphQLCompositeType) GraphQLFieldDefinition(graphql.schema.GraphQLFieldDefinition)

Example 4 with GraphQLCompositeType

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

the class TraversalContext method enterImpl.

private void enterImpl(SelectionSet selectionSet) {
    GraphQLUnmodifiedType rawType = new SchemaUtil().getUnmodifiedType(getOutputType());
    GraphQLCompositeType parentType = null;
    if (rawType instanceof GraphQLCompositeType) {
        parentType = (GraphQLCompositeType) rawType;
    }
    addParentType(parentType);
}
Also used : GraphQLUnmodifiedType(graphql.schema.GraphQLUnmodifiedType) SchemaUtil(graphql.schema.SchemaUtil) GraphQLCompositeType(graphql.schema.GraphQLCompositeType)

Example 5 with GraphQLCompositeType

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

the class FieldsOnCorrectType method checkField.

@Override
public void checkField(Field field) {
    GraphQLCompositeType parentType = getValidationContext().getParentType();
    // this means the parent type is not a CompositeType, which is an error handled elsewhere
    if (parentType == null)
        return;
    GraphQLFieldDefinition fieldDef = getValidationContext().getFieldDef();
    if (fieldDef == null) {
        String message = String.format("Field '%s' in type '%s' is undefined", field.getName(), parentType.getName());
        addError(ValidationErrorType.FieldUndefined, field.getSourceLocation(), message);
    }
}
Also used : GraphQLCompositeType(graphql.schema.GraphQLCompositeType) GraphQLFieldDefinition(graphql.schema.GraphQLFieldDefinition)

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