Search in sources :

Example 1 with FieldDefinition

use of graphql.language.FieldDefinition 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 FieldDefinition

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

the class GraphqlAntlrToLanguage method visitFieldDefinition.

@Override
public Void visitFieldDefinition(GraphqlParser.FieldDefinitionContext ctx) {
    FieldDefinition def = new FieldDefinition(ctx.name().getText());
    newNode(def, ctx);
    def.setDescription(newDescription(ctx.description()));
    for (ContextEntry contextEntry : contextStack) {
        if (contextEntry.contextProperty == ContextProperty.InterfaceTypeDefinition) {
            ((InterfaceTypeDefinition) contextEntry.value).getFieldDefinitions().add(def);
            break;
        }
        if (contextEntry.contextProperty == ContextProperty.ObjectTypeDefinition) {
            ((ObjectTypeDefinition) contextEntry.value).getFieldDefinitions().add(def);
            break;
        }
    }
    addContextProperty(ContextProperty.FieldDefinition, def);
    super.visitChildren(ctx);
    popContext();
    return null;
}
Also used : FieldDefinition(graphql.language.FieldDefinition)

Example 3 with FieldDefinition

use of graphql.language.FieldDefinition 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 4 with FieldDefinition

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

the class SchemaDiff method checkFieldRemovals.

private void checkFieldRemovals(DiffCtx ctx, TypeDefinition oldDef, Map<String, FieldDefinition> oldFields, Map<String, FieldDefinition> newFields) {
    for (Map.Entry<String, FieldDefinition> entry : oldFields.entrySet()) {
        String fieldName = entry.getKey();
        ctx.report(DiffEvent.apiInfo().typeName(oldDef.getName()).typeKind(getTypeKind(oldDef)).fieldName(fieldName).reasonMsg("\tExamining field '%s' ...", mkDotName(oldDef.getName(), fieldName)).build());
        FieldDefinition newField = newFields.get(fieldName);
        if (newField == null) {
            ctx.report(DiffEvent.apiBreakage().category(DiffCategory.MISSING).typeName(oldDef.getName()).typeKind(getTypeKind(oldDef)).fieldName(fieldName).reasonMsg("The new API is missing the field '%s'", mkDotName(oldDef.getName(), fieldName)).build());
        } else {
            checkField(ctx, oldDef, entry.getValue(), newField);
        }
    }
}
Also used : FieldDefinition(graphql.language.FieldDefinition) Map(java.util.Map) TreeMap(java.util.TreeMap)

Example 5 with FieldDefinition

use of graphql.language.FieldDefinition 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)

Aggregations

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