Search in sources :

Example 1 with InputValueDefinition

use of graphql.language.InputValueDefinition in project graphql-java by graphql-java.

the class GraphqlAntlrToLanguage method visitNonNullType.

@Override
public Void visitNonNullType(GraphqlParser.NonNullTypeContext ctx) {
    NonNullType nonNullType = new NonNullType();
    newNode(nonNullType, ctx);
    for (ContextEntry contextEntry : contextStack) {
        if (contextEntry.value instanceof ListType) {
            ((ListType) contextEntry.value).setType(nonNullType);
            break;
        }
        if (contextEntry.value instanceof VariableDefinition) {
            ((VariableDefinition) contextEntry.value).setType(nonNullType);
            break;
        }
        if (contextEntry.value instanceof FieldDefinition) {
            ((FieldDefinition) contextEntry.value).setType(nonNullType);
            break;
        }
        if (contextEntry.value instanceof InputValueDefinition) {
            ((InputValueDefinition) contextEntry.value).setType(nonNullType);
            break;
        }
    }
    addContextProperty(ContextProperty.NonNullType, nonNullType);
    super.visitNonNullType(ctx);
    popContext();
    return null;
}
Also used : VariableDefinition(graphql.language.VariableDefinition) NonNullType(graphql.language.NonNullType) ListType(graphql.language.ListType) FieldDefinition(graphql.language.FieldDefinition) InputValueDefinition(graphql.language.InputValueDefinition)

Example 2 with InputValueDefinition

use of graphql.language.InputValueDefinition in project graphql-java by graphql-java.

the class IntrospectionResultToSchema method createFields.

private List<FieldDefinition> createFields(List<Map<String, Object>> fields) {
    List<FieldDefinition> result = new ArrayList<>();
    for (Map<String, Object> field : fields) {
        FieldDefinition fieldDefinition = new FieldDefinition((String) field.get("name"));
        fieldDefinition.setComments(toComment((String) field.get("description")));
        fieldDefinition.setType(createTypeIndirection((Map<String, Object>) field.get("type")));
        createDeprecatedDirective(field, fieldDefinition.getDirectives());
        List<Map<String, Object>> args = (List<Map<String, Object>>) field.get("args");
        List<InputValueDefinition> inputValueDefinitions = createInputValueDefinitions(args);
        fieldDefinition.getInputValueDefinitions().addAll(inputValueDefinitions);
        result.add(fieldDefinition);
    }
    return result;
}
Also used : FieldDefinition(graphql.language.FieldDefinition) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) InputValueDefinition(graphql.language.InputValueDefinition) Map(java.util.Map)

Example 3 with InputValueDefinition

use of graphql.language.InputValueDefinition in project graphql-java by graphql-java.

the class IntrospectionResultToSchema method createInputObject.

@SuppressWarnings("unchecked")
InputObjectTypeDefinition createInputObject(Map<String, Object> input) {
    assertTrue(input.get("kind").equals("INPUT_OBJECT"), "wrong input");
    InputObjectTypeDefinition inputObjectTypeDefinition = new InputObjectTypeDefinition((String) input.get("name"));
    inputObjectTypeDefinition.setComments(toComment((String) input.get("description")));
    List<Map<String, Object>> fields = (List<Map<String, Object>>) input.get("inputFields");
    List<InputValueDefinition> inputValueDefinitions = createInputValueDefinitions(fields);
    inputObjectTypeDefinition.getInputValueDefinitions().addAll(inputValueDefinitions);
    return inputObjectTypeDefinition;
}
Also used : InputObjectTypeDefinition(graphql.language.InputObjectTypeDefinition) ArrayList(java.util.ArrayList) List(java.util.List) InputValueDefinition(graphql.language.InputValueDefinition) Map(java.util.Map)

Example 4 with InputValueDefinition

use of graphql.language.InputValueDefinition in project graphql-java by graphql-java.

the class SchemaTypeChecker method checkInterfaceFields.

private void checkInterfaceFields(List<GraphQLError> errors, InterfaceTypeDefinition interfaceType, List<FieldDefinition> fieldDefinitions) {
    // field unique ness
    checkNamedUniqueness(errors, fieldDefinitions, FieldDefinition::getName, (name, fieldDef) -> new NonUniqueNameError(interfaceType, fieldDef));
    // field arg unique ness
    fieldDefinitions.forEach(fld -> checkNamedUniqueness(errors, fld.getInputValueDefinitions(), InputValueDefinition::getName, (name, inputValueDefinition) -> new NonUniqueArgumentError(interfaceType, fld, name)));
    // directive checks
    fieldDefinitions.forEach(fld -> checkNamedUniqueness(errors, fld.getDirectives(), Directive::getName, (directiveName, directive) -> new NonUniqueDirectiveError(interfaceType, fld, directiveName)));
    fieldDefinitions.forEach(fld -> fld.getDirectives().forEach(directive -> {
        checkDeprecatedDirective(errors, directive, () -> new InvalidDeprecationDirectiveError(interfaceType, fld));
        checkNamedUniqueness(errors, directive.getArguments(), Argument::getName, (argumentName, argument) -> new NonUniqueArgumentError(interfaceType, fld, argumentName));
    }));
}
Also used : MissingInterfaceTypeError(graphql.schema.idl.errors.MissingInterfaceTypeError) BiFunction(java.util.function.BiFunction) InputValueDefinition(graphql.language.InputValueDefinition) SchemaDefinition(graphql.language.SchemaDefinition) MissingInterfaceFieldError(graphql.schema.idl.errors.MissingInterfaceFieldError) EnumTypeDefinition(graphql.language.EnumTypeDefinition) Type(graphql.language.Type) MissingScalarImplementationError(graphql.schema.idl.errors.MissingScalarImplementationError) EnumValueDefinition(graphql.language.EnumValueDefinition) ObjectTypeExtensionDefinition(graphql.language.ObjectTypeExtensionDefinition) GraphQLError(graphql.GraphQLError) Map(java.util.Map) TypeName(graphql.language.TypeName) QueryOperationMissingError(graphql.schema.idl.errors.QueryOperationMissingError) OperationTypeDefinition(graphql.language.OperationTypeDefinition) ObjectTypeDefinition(graphql.language.ObjectTypeDefinition) InterfaceFieldRedefinitionError(graphql.schema.idl.errors.InterfaceFieldRedefinitionError) Predicate(java.util.function.Predicate) Collection(java.util.Collection) FieldDefinition(graphql.language.FieldDefinition) Set(java.util.Set) TypeDefinition(graphql.language.TypeDefinition) Collectors(java.util.stream.Collectors) BinaryOperator(java.util.function.BinaryOperator) AstPrinter(graphql.language.AstPrinter) MissingTypeError(graphql.schema.idl.errors.MissingTypeError) List(java.util.List) InterfaceTypeDefinition(graphql.language.InterfaceTypeDefinition) Optional(java.util.Optional) NonUniqueArgumentError(graphql.schema.idl.errors.NonUniqueArgumentError) InterfaceFieldArgumentRedefinitionError(graphql.schema.idl.errors.InterfaceFieldArgumentRedefinitionError) SchemaMissingError(graphql.schema.idl.errors.SchemaMissingError) NonUniqueDirectiveError(graphql.schema.idl.errors.NonUniqueDirectiveError) Internal(graphql.Internal) InputObjectTypeDefinition(graphql.language.InputObjectTypeDefinition) SchemaProblem(graphql.schema.idl.errors.SchemaProblem) MissingTypeResolverError(graphql.schema.idl.errors.MissingTypeResolverError) Function(java.util.function.Function) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) UnionTypeDefinition(graphql.language.UnionTypeDefinition) NonUniqueNameError(graphql.schema.idl.errors.NonUniqueNameError) OperationTypesMustBeObjects(graphql.schema.idl.errors.OperationTypesMustBeObjects) InvalidDeprecationDirectiveError(graphql.schema.idl.errors.InvalidDeprecationDirectiveError) MissingInterfaceFieldArgumentsError(graphql.schema.idl.errors.MissingInterfaceFieldArgumentsError) Directive(graphql.language.Directive) Consumer(java.util.function.Consumer) Argument(graphql.language.Argument) StringValue(graphql.language.StringValue) Collections(java.util.Collections) InvalidDeprecationDirectiveError(graphql.schema.idl.errors.InvalidDeprecationDirectiveError) FieldDefinition(graphql.language.FieldDefinition) NonUniqueArgumentError(graphql.schema.idl.errors.NonUniqueArgumentError) NonUniqueDirectiveError(graphql.schema.idl.errors.NonUniqueDirectiveError) NonUniqueNameError(graphql.schema.idl.errors.NonUniqueNameError)

Example 5 with InputValueDefinition

use of graphql.language.InputValueDefinition in project graphql-java by graphql-java.

the class SchemaTypeChecker method checkObjTypeFields.

private void checkObjTypeFields(List<GraphQLError> errors, ObjectTypeDefinition typeDefinition, List<FieldDefinition> fieldDefinitions) {
    // field unique ness
    checkNamedUniqueness(errors, fieldDefinitions, FieldDefinition::getName, (name, fieldDef) -> new NonUniqueNameError(typeDefinition, fieldDef));
    // field arg unique ness
    fieldDefinitions.forEach(fld -> checkNamedUniqueness(errors, fld.getInputValueDefinitions(), InputValueDefinition::getName, (name, inputValueDefinition) -> new NonUniqueArgumentError(typeDefinition, fld, name)));
    // directive checks
    fieldDefinitions.forEach(fld -> checkNamedUniqueness(errors, fld.getDirectives(), Directive::getName, (directiveName, directive) -> new NonUniqueDirectiveError(typeDefinition, fld, directiveName)));
    fieldDefinitions.forEach(fld -> fld.getDirectives().forEach(directive -> {
        checkDeprecatedDirective(errors, directive, () -> new InvalidDeprecationDirectiveError(typeDefinition, fld));
        checkNamedUniqueness(errors, directive.getArguments(), Argument::getName, (argumentName, argument) -> new NonUniqueArgumentError(typeDefinition, fld, argumentName));
    }));
}
Also used : MissingInterfaceTypeError(graphql.schema.idl.errors.MissingInterfaceTypeError) BiFunction(java.util.function.BiFunction) InputValueDefinition(graphql.language.InputValueDefinition) SchemaDefinition(graphql.language.SchemaDefinition) MissingInterfaceFieldError(graphql.schema.idl.errors.MissingInterfaceFieldError) EnumTypeDefinition(graphql.language.EnumTypeDefinition) Type(graphql.language.Type) MissingScalarImplementationError(graphql.schema.idl.errors.MissingScalarImplementationError) EnumValueDefinition(graphql.language.EnumValueDefinition) ObjectTypeExtensionDefinition(graphql.language.ObjectTypeExtensionDefinition) GraphQLError(graphql.GraphQLError) Map(java.util.Map) TypeName(graphql.language.TypeName) QueryOperationMissingError(graphql.schema.idl.errors.QueryOperationMissingError) OperationTypeDefinition(graphql.language.OperationTypeDefinition) ObjectTypeDefinition(graphql.language.ObjectTypeDefinition) InterfaceFieldRedefinitionError(graphql.schema.idl.errors.InterfaceFieldRedefinitionError) Predicate(java.util.function.Predicate) Collection(java.util.Collection) FieldDefinition(graphql.language.FieldDefinition) Set(java.util.Set) TypeDefinition(graphql.language.TypeDefinition) Collectors(java.util.stream.Collectors) BinaryOperator(java.util.function.BinaryOperator) AstPrinter(graphql.language.AstPrinter) MissingTypeError(graphql.schema.idl.errors.MissingTypeError) List(java.util.List) InterfaceTypeDefinition(graphql.language.InterfaceTypeDefinition) Optional(java.util.Optional) NonUniqueArgumentError(graphql.schema.idl.errors.NonUniqueArgumentError) InterfaceFieldArgumentRedefinitionError(graphql.schema.idl.errors.InterfaceFieldArgumentRedefinitionError) SchemaMissingError(graphql.schema.idl.errors.SchemaMissingError) NonUniqueDirectiveError(graphql.schema.idl.errors.NonUniqueDirectiveError) Internal(graphql.Internal) InputObjectTypeDefinition(graphql.language.InputObjectTypeDefinition) SchemaProblem(graphql.schema.idl.errors.SchemaProblem) MissingTypeResolverError(graphql.schema.idl.errors.MissingTypeResolverError) Function(java.util.function.Function) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) UnionTypeDefinition(graphql.language.UnionTypeDefinition) NonUniqueNameError(graphql.schema.idl.errors.NonUniqueNameError) OperationTypesMustBeObjects(graphql.schema.idl.errors.OperationTypesMustBeObjects) InvalidDeprecationDirectiveError(graphql.schema.idl.errors.InvalidDeprecationDirectiveError) MissingInterfaceFieldArgumentsError(graphql.schema.idl.errors.MissingInterfaceFieldArgumentsError) Directive(graphql.language.Directive) Consumer(java.util.function.Consumer) Argument(graphql.language.Argument) StringValue(graphql.language.StringValue) Collections(java.util.Collections) InvalidDeprecationDirectiveError(graphql.schema.idl.errors.InvalidDeprecationDirectiveError) FieldDefinition(graphql.language.FieldDefinition) NonUniqueArgumentError(graphql.schema.idl.errors.NonUniqueArgumentError) NonUniqueDirectiveError(graphql.schema.idl.errors.NonUniqueDirectiveError) NonUniqueNameError(graphql.schema.idl.errors.NonUniqueNameError)

Aggregations

InputValueDefinition (graphql.language.InputValueDefinition)19 FieldDefinition (graphql.language.FieldDefinition)11 Map (java.util.Map)10 InputObjectTypeDefinition (graphql.language.InputObjectTypeDefinition)9 List (java.util.List)9 Directive (graphql.language.Directive)8 EnumTypeDefinition (graphql.language.EnumTypeDefinition)8 EnumValueDefinition (graphql.language.EnumValueDefinition)8 Type (graphql.language.Type)8 TypeName (graphql.language.TypeName)8 GraphQLError (graphql.GraphQLError)7 Internal (graphql.Internal)7 Argument (graphql.language.Argument)7 AstPrinter (graphql.language.AstPrinter)7 InterfaceTypeDefinition (graphql.language.InterfaceTypeDefinition)7 ObjectTypeDefinition (graphql.language.ObjectTypeDefinition)7 TypeDefinition (graphql.language.TypeDefinition)7 UnionTypeDefinition (graphql.language.UnionTypeDefinition)7 InvalidDeprecationDirectiveError (graphql.schema.idl.errors.InvalidDeprecationDirectiveError)7 MissingTypeError (graphql.schema.idl.errors.MissingTypeError)7