Search in sources :

Example 21 with GraphQLType

use of graphql.schema.GraphQLType 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 22 with GraphQLType

use of graphql.schema.GraphQLType 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)

Example 23 with GraphQLType

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

the class SchemaGenerator method buildAdditionalTypes.

/**
 * We build the query / mutation / subscription path as a tree of referenced types
 * but then we build the rest of the types specified and put them in as additional types
 *
 * @param buildCtx the context we need to work out what we are doing
 *
 * @return the additional types not referenced from the top level operations
 */
private Set<GraphQLType> buildAdditionalTypes(BuildContext buildCtx) {
    Set<GraphQLType> additionalTypes = new HashSet<>();
    TypeDefinitionRegistry typeRegistry = buildCtx.getTypeRegistry();
    typeRegistry.types().values().forEach(typeDefinition -> {
        TypeName typeName = new TypeName(typeDefinition.getName());
        if (typeDefinition instanceof InputObjectTypeDefinition) {
            if (buildCtx.hasInputType(typeDefinition) == null) {
                additionalTypes.add(buildInputType(buildCtx, typeName));
            }
        } else {
            if (buildCtx.hasOutputType(typeDefinition) == null) {
                additionalTypes.add(buildOutputType(buildCtx, typeName));
            }
        }
    });
    return additionalTypes;
}
Also used : TypeName(graphql.language.TypeName) GraphQLType(graphql.schema.GraphQLType) InputObjectTypeDefinition(graphql.language.InputObjectTypeDefinition) HashSet(java.util.HashSet)

Example 24 with GraphQLType

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

the class SchemaGeneratorHelper method buildValue.

public Object buildValue(Value value, GraphQLType requiredType) {
    Object result = null;
    if (requiredType instanceof GraphQLNonNull) {
        requiredType = ((GraphQLNonNull) requiredType).getWrappedType();
    }
    if (requiredType instanceof GraphQLScalarType) {
        result = parseLiteral(value, (GraphQLScalarType) requiredType);
    } else if (value instanceof EnumValue && requiredType instanceof GraphQLEnumType) {
        result = ((EnumValue) value).getName();
    } else if (value instanceof ArrayValue && requiredType instanceof GraphQLList) {
        ArrayValue arrayValue = (ArrayValue) value;
        GraphQLType wrappedType = ((GraphQLList) requiredType).getWrappedType();
        result = arrayValue.getValues().stream().map(item -> this.buildValue(item, wrappedType)).collect(Collectors.toList());
    } else if (value instanceof ObjectValue && requiredType instanceof GraphQLInputObjectType) {
        result = buildObjectValue((ObjectValue) value, (GraphQLInputObjectType) requiredType);
    } else if (value != null && !(value instanceof NullValue)) {
        Assert.assertShouldNeverHappen("cannot build value of %s from %s", requiredType.getName(), String.valueOf(value));
    }
    return result;
}
Also used : GraphQLList(graphql.schema.GraphQLList) ObjectValue(graphql.language.ObjectValue) NullValue(graphql.language.NullValue) GraphQLEnumType(graphql.schema.GraphQLEnumType) EnumValue(graphql.language.EnumValue) GraphQLInputObjectType(graphql.schema.GraphQLInputObjectType) GraphQLNonNull(graphql.schema.GraphQLNonNull) GraphQLType(graphql.schema.GraphQLType) ArrayValue(graphql.language.ArrayValue) GraphQLScalarType(graphql.schema.GraphQLScalarType)

Aggregations

GraphQLType (graphql.schema.GraphQLType)24 GraphQLList (graphql.schema.GraphQLList)6 GraphQLNonNull (graphql.schema.GraphQLNonNull)5 GraphQLObjectType (graphql.schema.GraphQLObjectType)5 GraphQLInputObjectType (graphql.schema.GraphQLInputObjectType)4 GraphQLInputType (graphql.schema.GraphQLInputType)4 LinkedHashMap (java.util.LinkedHashMap)4 TypeName (graphql.language.TypeName)3 GraphQLEnumType (graphql.schema.GraphQLEnumType)3 GraphQLInputObjectField (graphql.schema.GraphQLInputObjectField)3 GraphQLScalarType (graphql.schema.GraphQLScalarType)3 GraphqlFieldVisibility (graphql.schema.visibility.GraphqlFieldVisibility)3 ArrayList (java.util.ArrayList)3 Stack (java.util.Stack)3 PublicApi (graphql.PublicApi)2 ArrayValue (graphql.language.ArrayValue)2 InputObjectTypeDefinition (graphql.language.InputObjectTypeDefinition)2 Value (graphql.language.Value)2 GraphQLCompositeType (graphql.schema.GraphQLCompositeType)2 HashMap (java.util.HashMap)2