Search in sources :

Example 16 with InputValueDefinition

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

the class GraphqlAntlrToLanguage method visitInputValueDefinition.

@Override
public Void visitInputValueDefinition(GraphqlParser.InputValueDefinitionContext ctx) {
    InputValueDefinition def = new InputValueDefinition(ctx.name().getText());
    newNode(def, ctx);
    def.setDescription(newDescription(ctx.description()));
    if (ctx.defaultValue() != null) {
        def.setDefaultValue(getValue(ctx.defaultValue().value()));
    }
    for (ContextEntry contextEntry : contextStack) {
        if (contextEntry.contextProperty == ContextProperty.FieldDefinition) {
            ((FieldDefinition) contextEntry.value).getInputValueDefinitions().add(def);
            break;
        }
        if (contextEntry.contextProperty == ContextProperty.InputObjectTypeDefinition) {
            ((InputObjectTypeDefinition) contextEntry.value).getInputValueDefinitions().add(def);
            break;
        }
        if (contextEntry.contextProperty == ContextProperty.DirectiveDefinition) {
            ((DirectiveDefinition) contextEntry.value).getInputValueDefinitions().add(def);
            break;
        }
    }
    addContextProperty(ContextProperty.InputValueDefinition, def);
    super.visitChildren(ctx);
    popContext();
    return null;
}
Also used : InputValueDefinition(graphql.language.InputValueDefinition)

Example 17 with InputValueDefinition

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

the class GraphqlAntlrToLanguage method visitDirective.

@Override
public Void visitDirective(GraphqlParser.DirectiveContext ctx) {
    Directive directive = new Directive(ctx.name().getText());
    newNode(directive, ctx);
    for (ContextEntry contextEntry : contextStack) {
        if (contextEntry.contextProperty == ContextProperty.Field) {
            ((Field) contextEntry.value).getDirectives().add(directive);
            break;
        } else if (contextEntry.contextProperty == ContextProperty.FragmentDefinition) {
            ((FragmentDefinition) contextEntry.value).getDirectives().add(directive);
            break;
        } else if (contextEntry.contextProperty == ContextProperty.FragmentSpread) {
            ((FragmentSpread) contextEntry.value).getDirectives().add(directive);
            break;
        } else if (contextEntry.contextProperty == ContextProperty.InlineFragment) {
            ((InlineFragment) contextEntry.value).getDirectives().add(directive);
            break;
        } else if (contextEntry.contextProperty == ContextProperty.OperationDefinition) {
            ((OperationDefinition) contextEntry.value).getDirectives().add(directive);
            break;
        } else if (contextEntry.contextProperty == ContextProperty.EnumValueDefinition) {
            ((EnumValueDefinition) contextEntry.value).getDirectives().add(directive);
            break;
        } else if (contextEntry.contextProperty == ContextProperty.FieldDefinition) {
            ((FieldDefinition) contextEntry.value).getDirectives().add(directive);
            break;
        } else if (contextEntry.contextProperty == ContextProperty.InputValueDefinition) {
            ((InputValueDefinition) contextEntry.value).getDirectives().add(directive);
            break;
        } else if (contextEntry.contextProperty == ContextProperty.InterfaceTypeDefinition) {
            ((InterfaceTypeDefinition) contextEntry.value).getDirectives().add(directive);
            break;
        } else if (contextEntry.contextProperty == ContextProperty.EnumTypeDefinition) {
            ((EnumTypeDefinition) contextEntry.value).getDirectives().add(directive);
            break;
        } else if (contextEntry.contextProperty == ContextProperty.ObjectTypeDefinition) {
            ((ObjectTypeDefinition) contextEntry.value).getDirectives().add(directive);
            break;
        } else if (contextEntry.contextProperty == ContextProperty.ScalarTypeDefinition) {
            ((ScalarTypeDefinition) contextEntry.value).getDirectives().add(directive);
            break;
        } else if (contextEntry.contextProperty == ContextProperty.UnionTypeDefinition) {
            ((UnionTypeDefinition) contextEntry.value).getDirectives().add(directive);
            break;
        } else if (contextEntry.contextProperty == ContextProperty.InputObjectTypeDefinition) {
            ((InputObjectTypeDefinition) contextEntry.value).getDirectives().add(directive);
            break;
        } else if (contextEntry.contextProperty == ContextProperty.SchemaDefinition) {
            ((SchemaDefinition) contextEntry.value).getDirectives().add(directive);
            break;
        }
    }
    addContextProperty(ContextProperty.Directive, directive);
    super.visitDirective(ctx);
    popContext();
    return null;
}
Also used : ScalarTypeDefinition(graphql.language.ScalarTypeDefinition) FragmentDefinition(graphql.language.FragmentDefinition) EnumValueDefinition(graphql.language.EnumValueDefinition) EnumTypeDefinition(graphql.language.EnumTypeDefinition) InputObjectTypeDefinition(graphql.language.InputObjectTypeDefinition) InputValueDefinition(graphql.language.InputValueDefinition) Directive(graphql.language.Directive) InlineFragment(graphql.language.InlineFragment)

Example 18 with InputValueDefinition

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

the class IntrospectionResultToSchema method createInputValueDefinitions.

@SuppressWarnings("unchecked")
private List<InputValueDefinition> createInputValueDefinitions(List<Map<String, Object>> args) {
    List<InputValueDefinition> result = new ArrayList<>();
    for (Map<String, Object> arg : args) {
        Type argType = createTypeIndirection((Map<String, Object>) arg.get("type"));
        InputValueDefinition inputValueDefinition = new InputValueDefinition((String) arg.get("name"), argType);
        inputValueDefinition.setComments(toComment((String) arg.get("description")));
        String valueLiteral = (String) arg.get("defaultValue");
        if (valueLiteral != null) {
            Value defaultValue = AstValueHelper.valueFromAst(valueLiteral);
            inputValueDefinition.setDefaultValue(defaultValue);
        }
        result.add(inputValueDefinition);
    }
    return result;
}
Also used : Type(graphql.language.Type) NonNullType(graphql.language.NonNullType) ListType(graphql.language.ListType) ArrayList(java.util.ArrayList) Value(graphql.language.Value) StringValue(graphql.language.StringValue) InputValueDefinition(graphql.language.InputValueDefinition)

Example 19 with InputValueDefinition

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

the class SchemaDiff method checkInputFields.

private void checkInputFields(DiffCtx ctx, TypeDefinition old, List<InputValueDefinition> oldIVD, List<InputValueDefinition> newIVD) {
    Map<String, InputValueDefinition> oldDefinitionMap = sortedMap(oldIVD, InputValueDefinition::getName);
    Map<String, InputValueDefinition> newDefinitionMap = sortedMap(newIVD, InputValueDefinition::getName);
    for (String inputFieldName : oldDefinitionMap.keySet()) {
        InputValueDefinition oldField = oldDefinitionMap.get(inputFieldName);
        Optional<InputValueDefinition> newField = Optional.ofNullable(newDefinitionMap.get(inputFieldName));
        ctx.report(DiffEvent.apiInfo().typeName(old.getName()).typeKind(getTypeKind(old)).fieldName(oldField.getName()).reasonMsg("\tExamining input field '%s' ...", mkDotName(old.getName(), oldField.getName())).build());
        if (!newField.isPresent()) {
            ctx.report(DiffEvent.apiBreakage().category(DiffCategory.MISSING).typeName(old.getName()).typeKind(getTypeKind(old)).fieldName(oldField.getName()).reasonMsg("The new API is missing an input field '%s'", mkDotName(old.getName(), oldField.getName())).build());
        } else {
            DiffCategory category = checkTypeWithNonNullAndList(oldField.getType(), newField.get().getType());
            if (category != null) {
                ctx.report(DiffEvent.apiBreakage().category(category).typeName(old.getName()).typeKind(getTypeKind(old)).fieldName(oldField.getName()).components(getAstDesc(oldField.getType()), getAstDesc(newField.get().getType())).reasonMsg("The new API has changed input field '%s' from type '%s' to '%s'", oldField.getName(), getAstDesc(oldField.getType()), getAstDesc(newField.get().getType())).build());
            }
        }
    }
    // check new fields are not mandatory
    for (String inputFieldName : newDefinitionMap.keySet()) {
        InputValueDefinition newField = newDefinitionMap.get(inputFieldName);
        Optional<InputValueDefinition> oldField = Optional.ofNullable(oldDefinitionMap.get(inputFieldName));
        if (!oldField.isPresent()) {
            // new fields MUST not be mandatory
            if (typeInfo(newField.getType()).isNonNull()) {
                ctx.report(DiffEvent.apiBreakage().category(DiffCategory.STRICTER).typeName(old.getName()).typeKind(getTypeKind(old)).fieldName(newField.getName()).reasonMsg("The new API has made the new input field '%s' non null and hence more strict for old consumers", newField.getName()).build());
            }
        }
    }
}
Also used : InputValueDefinition(graphql.language.InputValueDefinition)

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