Search in sources :

Example 1 with GraphQLInputObjectType

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

the class TraversalContext method enterImpl.

private void enterImpl(ObjectField objectField) {
    GraphQLUnmodifiedType objectType = schemaUtil.getUnmodifiedType(getInputType());
    GraphQLInputType inputType = null;
    if (objectType instanceof GraphQLInputObjectType) {
        GraphQLInputObjectType inputObjectType = (GraphQLInputObjectType) objectType;
        GraphQLInputObjectField inputField = schema.getFieldVisibility().getFieldDefinition(inputObjectType, objectField.getName());
        if (inputField != null)
            inputType = inputField.getType();
    }
    addInputType(inputType);
}
Also used : GraphQLInputType(graphql.schema.GraphQLInputType) GraphQLUnmodifiedType(graphql.schema.GraphQLUnmodifiedType) GraphQLInputObjectField(graphql.schema.GraphQLInputObjectField) GraphQLInputObjectType(graphql.schema.GraphQLInputObjectType)

Example 2 with GraphQLInputObjectType

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

the class NoUnbrokenInputCycles method check.

private void check(GraphQLInputObjectType type, Set<GraphQLType> seen, List<String> path, SchemaValidationErrorCollector validationErrorCollector) {
    if (seen.contains(type)) {
        validationErrorCollector.addError(new SchemaValidationError(SchemaValidationErrorType.UnbrokenInputCycle, getErrorMessage(path)));
        return;
    }
    seen.add(type);
    for (GraphQLInputObjectField field : type.getFieldDefinitions()) {
        if (field.getType() instanceof GraphQLNonNull) {
            GraphQLType unwrapped = unwrapNonNull((GraphQLNonNull) field.getType());
            if (unwrapped instanceof GraphQLInputObjectType) {
                path = new ArrayList<>(path);
                path.add(field.getName() + "!");
                check((GraphQLInputObjectType) unwrapped, new HashSet<>(seen), path, validationErrorCollector);
            }
        }
    }
}
Also used : GraphQLInputObjectField(graphql.schema.GraphQLInputObjectField) GraphQLInputObjectType(graphql.schema.GraphQLInputObjectType) GraphQLNonNull(graphql.schema.GraphQLNonNull) GraphQLType(graphql.schema.GraphQLType)

Example 3 with GraphQLInputObjectType

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

the class NoUnbrokenInputCycles method check.

@Override
public void check(GraphQLFieldDefinition fieldDef, SchemaValidationErrorCollector validationErrorCollector) {
    for (GraphQLArgument argument : fieldDef.getArguments()) {
        GraphQLInputType argumentType = argument.getType();
        if (argumentType instanceof GraphQLInputObjectType) {
            List<String> path = new ArrayList<>();
            path.add(argumentType.getName());
            check((GraphQLInputObjectType) argumentType, new HashSet<>(), path, validationErrorCollector);
        }
    }
}
Also used : GraphQLInputType(graphql.schema.GraphQLInputType) GraphQLInputObjectType(graphql.schema.GraphQLInputObjectType) ArrayList(java.util.ArrayList) GraphQLArgument(graphql.schema.GraphQLArgument)

Example 4 with GraphQLInputObjectType

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

the class ReadmeExamples method mutationExample.

void mutationExample() {
    GraphQLInputObjectType episodeType = GraphQLInputObjectType.newInputObject().name("Episode").field(newInputObjectField().name("episodeNumber").type(Scalars.GraphQLInt)).build();
    GraphQLInputObjectType reviewInputType = GraphQLInputObjectType.newInputObject().name("ReviewInput").field(newInputObjectField().name("stars").type(Scalars.GraphQLString).name("commentary").type(Scalars.GraphQLString)).build();
    GraphQLObjectType reviewType = newObject().name("Review").field(newFieldDefinition().name("stars").type(GraphQLString)).field(newFieldDefinition().name("commentary").type(GraphQLString)).build();
    GraphQLObjectType createReviewForEpisodeMutation = newObject().name("CreateReviewForEpisodeMutation").field(newFieldDefinition().name("createReview").type(reviewType).argument(newArgument().name("episode").type(episodeType)).argument(newArgument().name("review").type(reviewInputType)).dataFetcher(mutationDataFetcher())).build();
    GraphQLSchema schema = GraphQLSchema.newSchema().query(queryType).mutation(createReviewForEpisodeMutation).build();
}
Also used : GraphQLInputObjectType(graphql.schema.GraphQLInputObjectType) GraphQLObjectType(graphql.schema.GraphQLObjectType) GraphQLSchema(graphql.schema.GraphQLSchema)

Example 5 with GraphQLInputObjectType

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

GraphQLInputObjectType (graphql.schema.GraphQLInputObjectType)7 GraphQLNonNull (graphql.schema.GraphQLNonNull)4 GraphQLEnumType (graphql.schema.GraphQLEnumType)2 GraphQLInputObjectField (graphql.schema.GraphQLInputObjectField)2 GraphQLInputType (graphql.schema.GraphQLInputType)2 GraphQLList (graphql.schema.GraphQLList)2 GraphQLObjectType (graphql.schema.GraphQLObjectType)2 GraphQLScalarType (graphql.schema.GraphQLScalarType)2 GraphQLType (graphql.schema.GraphQLType)2 AssertException (graphql.AssertException)1 ArrayValue (graphql.language.ArrayValue)1 EnumValue (graphql.language.EnumValue)1 NullValue (graphql.language.NullValue)1 ObjectValue (graphql.language.ObjectValue)1 GraphQLArgument (graphql.schema.GraphQLArgument)1 GraphQLSchema (graphql.schema.GraphQLSchema)1 GraphQLUnmodifiedType (graphql.schema.GraphQLUnmodifiedType)1 BigInteger (java.math.BigInteger)1 ArrayList (java.util.ArrayList)1