Search in sources :

Example 6 with EnumTypeDefinition

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

the class SchemaGenerator method buildInputType.

private GraphQLInputType buildInputType(BuildContext buildCtx, Type rawType) {
    TypeDefinition typeDefinition = buildCtx.getTypeDefinition(rawType);
    TypeInfo typeInfo = TypeInfo.typeInfo(rawType);
    GraphQLInputType inputType = buildCtx.hasInputType(typeDefinition);
    if (inputType != null) {
        return typeInfo.decorate(inputType);
    }
    if (buildCtx.stackContains(typeInfo)) {
        // we have circled around so put in a type reference and fix it later
        return typeInfo.decorate(typeRef(typeInfo.getName()));
    }
    buildCtx.push(typeInfo);
    if (typeDefinition instanceof InputObjectTypeDefinition) {
        inputType = buildInputObjectType(buildCtx, (InputObjectTypeDefinition) typeDefinition);
    } else if (typeDefinition instanceof EnumTypeDefinition) {
        inputType = buildEnumType(buildCtx, (EnumTypeDefinition) typeDefinition);
    } else if (typeDefinition instanceof ScalarTypeDefinition) {
        inputType = buildScalar(buildCtx, (ScalarTypeDefinition) typeDefinition);
    } else {
        // typeDefinition is not a valid InputType
        throw new NotAnInputTypeError(typeDefinition);
    }
    buildCtx.put(inputType);
    buildCtx.pop();
    return typeInfo.decorate(inputType);
}
Also used : GraphQLInputType(graphql.schema.GraphQLInputType) ScalarTypeDefinition(graphql.language.ScalarTypeDefinition) EnumTypeDefinition(graphql.language.EnumTypeDefinition) NotAnInputTypeError(graphql.schema.idl.errors.NotAnInputTypeError) InputObjectTypeDefinition(graphql.language.InputObjectTypeDefinition) EnumTypeDefinition(graphql.language.EnumTypeDefinition) OperationTypeDefinition(graphql.language.OperationTypeDefinition) ObjectTypeDefinition(graphql.language.ObjectTypeDefinition) TypeDefinition(graphql.language.TypeDefinition) InterfaceTypeDefinition(graphql.language.InterfaceTypeDefinition) InputObjectTypeDefinition(graphql.language.InputObjectTypeDefinition) UnionTypeDefinition(graphql.language.UnionTypeDefinition) ScalarTypeDefinition(graphql.language.ScalarTypeDefinition)

Example 7 with EnumTypeDefinition

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

the class GraphqlAntlrToLanguage method visitEnumTypeDefinition.

@Override
public Void visitEnumTypeDefinition(GraphqlParser.EnumTypeDefinitionContext ctx) {
    EnumTypeDefinition def = new EnumTypeDefinition(ctx.name().getText());
    newNode(def, ctx);
    def.setDescription(newDescription(ctx.description()));
    result.getDefinitions().add(def);
    addContextProperty(ContextProperty.EnumTypeDefinition, def);
    super.visitChildren(ctx);
    popContext();
    return null;
}
Also used : EnumTypeDefinition(graphql.language.EnumTypeDefinition)

Example 8 with EnumTypeDefinition

use of graphql.language.EnumTypeDefinition 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 9 with EnumTypeDefinition

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

the class SchemaDiff method checkType.

private void checkType(DiffCtx ctx, Type oldType, Type newType) {
    String typeName = getTypeName(oldType);
    // prevent circular references
    if (ctx.examiningType(typeName)) {
        return;
    }
    if (isSystemScalar(typeName)) {
        return;
    }
    if (isReservedType(typeName)) {
        return;
    }
    Optional<TypeDefinition> oldTD = ctx.getOldTypeDef(oldType, TypeDefinition.class);
    Optional<TypeDefinition> newTD = ctx.getNewTypeDef(newType, TypeDefinition.class);
    if (!oldTD.isPresent()) {
        ctx.report(DiffEvent.apiInfo().typeName(typeName).reasonMsg("Type '%s' is missing", typeName).build());
        return;
    }
    TypeDefinition oldDef = oldTD.get();
    ctx.report(DiffEvent.apiInfo().typeName(typeName).typeKind(getTypeKind(oldDef)).reasonMsg("Examining type '%s' ...", typeName).build());
    if (!newTD.isPresent()) {
        ctx.report(DiffEvent.apiBreakage().category(DiffCategory.MISSING).typeName(typeName).typeKind(getTypeKind(oldDef)).reasonMsg("The new API does not have a type called '%s'", typeName).build());
        ctx.exitType();
        return;
    }
    TypeDefinition newDef = newTD.get();
    if (!oldDef.getClass().equals(newDef.getClass())) {
        ctx.report(DiffEvent.apiBreakage().category(DiffCategory.INVALID).typeName(typeName).typeKind(getTypeKind(oldDef)).components(getTypeKind(oldDef), getTypeKind(newDef)).reasonMsg("The new API has changed '%s' from a '%s' to a '%s'", typeName, getTypeKind(oldDef), getTypeKind(newDef)).build());
        ctx.exitType();
        return;
    }
    if (oldDef instanceof ObjectTypeDefinition) {
        checkObjectType(ctx, (ObjectTypeDefinition) oldDef, (ObjectTypeDefinition) newDef);
    }
    if (oldDef instanceof InterfaceTypeDefinition) {
        checkInterfaceType(ctx, (InterfaceTypeDefinition) oldDef, (InterfaceTypeDefinition) newDef);
    }
    if (oldDef instanceof UnionTypeDefinition) {
        checkUnionType(ctx, (UnionTypeDefinition) oldDef, (UnionTypeDefinition) newDef);
    }
    if (oldDef instanceof InputObjectTypeDefinition) {
        checkInputObjectType(ctx, (InputObjectTypeDefinition) oldDef, (InputObjectTypeDefinition) newDef);
    }
    if (oldDef instanceof EnumTypeDefinition) {
        checkEnumType(ctx, (EnumTypeDefinition) oldDef, (EnumTypeDefinition) newDef);
    }
    if (oldDef instanceof ScalarTypeDefinition) {
        checkScalarType(ctx, (ScalarTypeDefinition) oldDef, (ScalarTypeDefinition) newDef);
    }
    ctx.exitType();
}
Also used : ScalarTypeDefinition(graphql.language.ScalarTypeDefinition) InputObjectTypeDefinition(graphql.language.InputObjectTypeDefinition) ObjectTypeDefinition(graphql.language.ObjectTypeDefinition) EnumTypeDefinition(graphql.language.EnumTypeDefinition) InputObjectTypeDefinition(graphql.language.InputObjectTypeDefinition) InterfaceTypeDefinition(graphql.language.InterfaceTypeDefinition) UnionTypeDefinition(graphql.language.UnionTypeDefinition) InputObjectTypeDefinition(graphql.language.InputObjectTypeDefinition) EnumTypeDefinition(graphql.language.EnumTypeDefinition) UnionTypeDefinition(graphql.language.UnionTypeDefinition) OperationTypeDefinition(graphql.language.OperationTypeDefinition) ScalarTypeDefinition(graphql.language.ScalarTypeDefinition) ObjectTypeDefinition(graphql.language.ObjectTypeDefinition) TypeDefinition(graphql.language.TypeDefinition) InterfaceTypeDefinition(graphql.language.InterfaceTypeDefinition)

Aggregations

EnumTypeDefinition (graphql.language.EnumTypeDefinition)9 InputObjectTypeDefinition (graphql.language.InputObjectTypeDefinition)6 EnumValueDefinition (graphql.language.EnumValueDefinition)5 InterfaceTypeDefinition (graphql.language.InterfaceTypeDefinition)5 ObjectTypeDefinition (graphql.language.ObjectTypeDefinition)5 OperationTypeDefinition (graphql.language.OperationTypeDefinition)5 ScalarTypeDefinition (graphql.language.ScalarTypeDefinition)5 TypeDefinition (graphql.language.TypeDefinition)5 UnionTypeDefinition (graphql.language.UnionTypeDefinition)5 Directive (graphql.language.Directive)3 InputValueDefinition (graphql.language.InputValueDefinition)3 GraphQLError (graphql.GraphQLError)2 INPUT_OBJECT (graphql.introspection.Introspection.DirectiveLocation.INPUT_OBJECT)2 OBJECT (graphql.introspection.Introspection.DirectiveLocation.OBJECT)2 FieldDefinition (graphql.language.FieldDefinition)2 ObjectTypeExtensionDefinition (graphql.language.ObjectTypeExtensionDefinition)2 SchemaDefinition (graphql.language.SchemaDefinition)2 Type (graphql.language.Type)2 TypeName (graphql.language.TypeName)2 GraphQLOutputType (graphql.schema.GraphQLOutputType)2