Search in sources :

Example 6 with GraphQLInputObjectField

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

the class ValidationUtil method isValidLiteralValue.

private boolean isValidLiteralValue(Value value, GraphQLInputObjectType type, GraphQLSchema schema) {
    if (!(value instanceof ObjectValue)) {
        handleNotObjectError(value, type);
        return false;
    }
    GraphqlFieldVisibility fieldVisibility = schema.getFieldVisibility();
    ObjectValue objectValue = (ObjectValue) value;
    Map<String, ObjectField> objectFieldMap = fieldMap(objectValue);
    Set<String> missingFields = getMissingFields(type, objectFieldMap, fieldVisibility);
    if (!missingFields.isEmpty()) {
        handleMissingFieldsError(value, type, missingFields);
        return false;
    }
    for (ObjectField objectField : objectValue.getObjectFields()) {
        GraphQLInputObjectField inputObjectField = fieldVisibility.getFieldDefinition(type, objectField.getName());
        if (inputObjectField == null) {
            handleExtraFieldError(value, type, objectField);
            return false;
        }
        if (!isValidLiteralValue(objectField.getValue(), inputObjectField.getType(), schema)) {
            handleFieldNotValidError(objectField, type);
            return false;
        }
    }
    return true;
}
Also used : GraphqlFieldVisibility(graphql.schema.visibility.GraphqlFieldVisibility) ObjectValue(graphql.language.ObjectValue) GraphQLInputObjectField(graphql.schema.GraphQLInputObjectField) GraphQLInputObjectField(graphql.schema.GraphQLInputObjectField) ObjectField(graphql.language.ObjectField)

Example 7 with GraphQLInputObjectField

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

the class SchemaGenerator method buildInputField.

private GraphQLInputObjectField buildInputField(BuildContext buildCtx, InputValueDefinition fieldDef) {
    GraphQLInputObjectField.Builder fieldBuilder = GraphQLInputObjectField.newInputObjectField();
    fieldBuilder.definition(fieldDef);
    fieldBuilder.name(fieldDef.getName());
    fieldBuilder.description(schemaGeneratorHelper.buildDescription(fieldDef, fieldDef.getDescription()));
    // currently the spec doesnt allow deprecations on InputValueDefinitions but it should!
    // fieldBuilder.deprecate(buildDeprecationReason(fieldDef.getDirectives()));
    GraphQLInputType inputType = buildInputType(buildCtx, fieldDef.getType());
    fieldBuilder.type(inputType);
    Value defaultValue = fieldDef.getDefaultValue();
    if (defaultValue != null) {
        fieldBuilder.defaultValue(schemaGeneratorHelper.buildValue(defaultValue, inputType));
    }
    fieldBuilder.withDirectives(buildDirectives(fieldDef.getDirectives(), emptyList(), INPUT_FIELD_DEFINITION));
    return fieldBuilder.build();
}
Also used : GraphQLInputType(graphql.schema.GraphQLInputType) GraphQLInputObjectField(graphql.schema.GraphQLInputObjectField) Value(graphql.language.Value)

Example 8 with GraphQLInputObjectField

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

the class Relay method mutationWithClientMutationId.

public GraphQLFieldDefinition mutationWithClientMutationId(String name, String fieldName, List<GraphQLInputObjectField> inputFields, List<GraphQLFieldDefinition> outputFields, DataFetcher dataFetcher) {
    GraphQLInputObjectField clientMutationIdInputField = newInputObjectField().name("clientMutationId").type(GraphQLString).build();
    GraphQLFieldDefinition clientMutationIdPayloadField = newFieldDefinition().name("clientMutationId").type(GraphQLString).build();
    return mutation(name, fieldName, addElementToList(inputFields, clientMutationIdInputField), addElementToList(outputFields, clientMutationIdPayloadField), dataFetcher);
}
Also used : GraphQLInputObjectField(graphql.schema.GraphQLInputObjectField) GraphQLFieldDefinition(graphql.schema.GraphQLFieldDefinition)

Aggregations

GraphQLInputObjectField (graphql.schema.GraphQLInputObjectField)8 GraphQLInputType (graphql.schema.GraphQLInputType)3 ObjectField (graphql.language.ObjectField)2 ObjectValue (graphql.language.ObjectValue)2 Value (graphql.language.Value)2 GraphQLInputObjectType (graphql.schema.GraphQLInputObjectType)2 LinkedHashMap (java.util.LinkedHashMap)2 ArrayValue (graphql.language.ArrayValue)1 NullValue (graphql.language.NullValue)1 VariableReference (graphql.language.VariableReference)1 GraphQLFieldDefinition (graphql.schema.GraphQLFieldDefinition)1 GraphQLNonNull (graphql.schema.GraphQLNonNull)1 GraphQLType (graphql.schema.GraphQLType)1 GraphQLUnmodifiedType (graphql.schema.GraphQLUnmodifiedType)1 GraphqlFieldVisibility (graphql.schema.visibility.GraphqlFieldVisibility)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1