Search in sources :

Example 6 with TypeName

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

the class SchemaTypeExtensionsChecker method checkUnionTypeExtensions.

/*
     * Union type extensions have the potential to be invalid if incorrectly defined.
     *
     * The named type must already be defined and must be a Union type.
     * The member types of a Union type extension must all be Object base types; Scalar, Interface and Union types must not be member types of a Union. Similarly, wrapping types must not be member types of a Union.
     * All member types of a Union type extension must be unique.
     * All member types of a Union type extension must not already be a member of the original Union type.
     * Any directives provided must not already apply to the original Union type.
     */
private void checkUnionTypeExtensions(List<GraphQLError> errors, TypeDefinitionRegistry typeRegistry) {
    typeRegistry.unionTypeExtensions().forEach((name, extensions) -> {
        checkTypeExtensionHasCorrespondingType(errors, typeRegistry, name, extensions, UnionTypeDefinition.class);
        checkTypeExtensionDirectiveRedefinition(errors, typeRegistry, name, extensions, UnionTypeDefinition.class);
        extensions.forEach(extension -> {
            List<TypeName> memberTypes = extension.getMemberTypes().stream().map(t -> TypeInfo.typeInfo(t).getTypeName()).collect(Collectors.toList());
            checkNamedUniqueness(errors, memberTypes, TypeName::getName, (namedMember, memberType) -> new NonUniqueNameError(extension, namedMember));
            memberTypes.forEach(memberType -> {
                Optional<ObjectTypeDefinition> unionTypeDefinition = typeRegistry.getType(memberType, ObjectTypeDefinition.class);
                if (!unionTypeDefinition.isPresent()) {
                    errors.add(new MissingTypeError("union member", extension, memberType));
                }
            });
        });
    });
}
Also used : NonUniqueDirectiveError(graphql.schema.idl.errors.NonUniqueDirectiveError) Internal(graphql.Internal) InputObjectTypeDefinition(graphql.language.InputObjectTypeDefinition) InputValueDefinition(graphql.language.InputValueDefinition) EnumTypeDefinition(graphql.language.EnumTypeDefinition) TypeExtensionFieldRedefinitionError(graphql.schema.idl.errors.TypeExtensionFieldRedefinitionError) Type(graphql.language.Type) UnionTypeDefinition(graphql.language.UnionTypeDefinition) EnumValueDefinition(graphql.language.EnumValueDefinition) GraphQLError(graphql.GraphQLError) TypeExtensionDirectiveRedefinitionError(graphql.schema.idl.errors.TypeExtensionDirectiveRedefinitionError) Map(java.util.Map) InputObjectTypeExtensionDefinition(graphql.language.InputObjectTypeExtensionDefinition) TypeExtensionEnumValueRedefinitionError(graphql.schema.idl.errors.TypeExtensionEnumValueRedefinitionError) TypeExtensionMissingBaseTypeError(graphql.schema.idl.errors.TypeExtensionMissingBaseTypeError) TypeName(graphql.language.TypeName) SchemaTypeChecker.checkNamedUniqueness(graphql.schema.idl.SchemaTypeChecker.checkNamedUniqueness) FpKit.mergeFirst(graphql.util.FpKit.mergeFirst) ScalarTypeDefinition(graphql.language.ScalarTypeDefinition) ObjectTypeDefinition(graphql.language.ObjectTypeDefinition) NonUniqueNameError(graphql.schema.idl.errors.NonUniqueNameError) FieldDefinition(graphql.language.FieldDefinition) InvalidDeprecationDirectiveError(graphql.schema.idl.errors.InvalidDeprecationDirectiveError) SchemaTypeChecker.checkDeprecatedDirective(graphql.schema.idl.SchemaTypeChecker.checkDeprecatedDirective) TypeDefinition(graphql.language.TypeDefinition) Collectors(java.util.stream.Collectors) Directive(graphql.language.Directive) Consumer(java.util.function.Consumer) Argument(graphql.language.Argument) AstPrinter(graphql.language.AstPrinter) MissingTypeError(graphql.schema.idl.errors.MissingTypeError) List(java.util.List) FpKit(graphql.util.FpKit) InterfaceTypeDefinition(graphql.language.InterfaceTypeDefinition) Optional(java.util.Optional) NonUniqueArgumentError(graphql.schema.idl.errors.NonUniqueArgumentError) InputObjectTypeDefinition(graphql.language.InputObjectTypeDefinition) ObjectTypeDefinition(graphql.language.ObjectTypeDefinition) TypeName(graphql.language.TypeName) MissingTypeError(graphql.schema.idl.errors.MissingTypeError) NonUniqueNameError(graphql.schema.idl.errors.NonUniqueNameError)

Example 7 with TypeName

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

the class TraversalContext method enterImpl.

private void enterImpl(InlineFragment inlineFragment) {
    TypeName typeCondition = inlineFragment.getTypeCondition();
    GraphQLOutputType type;
    if (typeCondition != null) {
        type = (GraphQLOutputType) schema.getType(typeCondition.getName());
    } else {
        type = (GraphQLOutputType) getParentType();
    }
    addOutputType(type);
}
Also used : TypeName(graphql.language.TypeName) GraphQLOutputType(graphql.schema.GraphQLOutputType)

Example 8 with TypeName

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

the class SchemaGenerator method buildAdditionalTypes.

/**
 * We build the query / mutation / subscription path as a tree of referenced types
 * but then we build the rest of the types specified and put them in as additional types
 *
 * @param buildCtx the context we need to work out what we are doing
 *
 * @return the additional types not referenced from the top level operations
 */
private Set<GraphQLType> buildAdditionalTypes(BuildContext buildCtx) {
    Set<GraphQLType> additionalTypes = new HashSet<>();
    TypeDefinitionRegistry typeRegistry = buildCtx.getTypeRegistry();
    typeRegistry.types().values().forEach(typeDefinition -> {
        TypeName typeName = new TypeName(typeDefinition.getName());
        if (typeDefinition instanceof InputObjectTypeDefinition) {
            if (buildCtx.hasInputType(typeDefinition) == null) {
                additionalTypes.add(buildInputType(buildCtx, typeName));
            }
        } else {
            if (buildCtx.hasOutputType(typeDefinition) == null) {
                additionalTypes.add(buildOutputType(buildCtx, typeName));
            }
        }
    });
    return additionalTypes;
}
Also used : TypeName(graphql.language.TypeName) GraphQLType(graphql.schema.GraphQLType) InputObjectTypeDefinition(graphql.language.InputObjectTypeDefinition) HashSet(java.util.HashSet)

Example 9 with TypeName

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

the class GraphqlAntlrToLanguage method visitTypeName.

// MARKER END: Here GraphqlOperation.g4 specific methods end
@Override
public Void visitTypeName(GraphqlParser.TypeNameContext ctx) {
    TypeName typeName = new TypeName(ctx.name().getText());
    newNode(typeName, ctx);
    for (ContextEntry contextEntry : contextStack) {
        if (contextEntry.value instanceof ListType) {
            ((ListType) contextEntry.value).setType(typeName);
            break;
        }
        if (contextEntry.value instanceof NonNullType) {
            ((NonNullType) contextEntry.value).setType(typeName);
            break;
        }
        if (contextEntry.value instanceof VariableDefinition) {
            ((VariableDefinition) contextEntry.value).setType(typeName);
            break;
        }
        if (contextEntry.value instanceof FieldDefinition) {
            ((FieldDefinition) contextEntry.value).setType(typeName);
            break;
        }
        if (contextEntry.value instanceof InputValueDefinition) {
            ((InputValueDefinition) contextEntry.value).setType(typeName);
            break;
        }
        if (contextEntry.contextProperty == ContextProperty.ObjectTypeDefinition) {
            ((ObjectTypeDefinition) contextEntry.value).getImplements().add(typeName);
            break;
        }
        if (contextEntry.contextProperty == ContextProperty.UnionTypeDefinition) {
            ((UnionTypeDefinition) contextEntry.value).getMemberTypes().add(typeName);
            break;
        }
        if (contextEntry.contextProperty == ContextProperty.OperationTypeDefinition) {
            ((OperationTypeDefinition) contextEntry.value).setType(typeName);
            break;
        }
    }
    return super.visitTypeName(ctx);
}
Also used : TypeName(graphql.language.TypeName) VariableDefinition(graphql.language.VariableDefinition) NonNullType(graphql.language.NonNullType) ListType(graphql.language.ListType) FieldDefinition(graphql.language.FieldDefinition) InputValueDefinition(graphql.language.InputValueDefinition) OperationTypeDefinition(graphql.language.OperationTypeDefinition)

Example 10 with TypeName

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

the class GraphqlAntlrToLanguage method visitFragmentDefinition.

@Override
public Void visitFragmentDefinition(GraphqlParser.FragmentDefinitionContext ctx) {
    FragmentDefinition fragmentDefinition = new FragmentDefinition();
    newNode(fragmentDefinition, ctx);
    fragmentDefinition.setName(ctx.fragmentName().getText());
    fragmentDefinition.setTypeCondition(new TypeName(ctx.typeCondition().typeName().getText()));
    addContextProperty(ContextProperty.FragmentDefinition, fragmentDefinition);
    result.getDefinitions().add(fragmentDefinition);
    super.visitFragmentDefinition(ctx);
    popContext();
    return null;
}
Also used : TypeName(graphql.language.TypeName) FragmentDefinition(graphql.language.FragmentDefinition)

Aggregations

TypeName (graphql.language.TypeName)13 InputObjectTypeDefinition (graphql.language.InputObjectTypeDefinition)6 ObjectTypeDefinition (graphql.language.ObjectTypeDefinition)5 UnionTypeDefinition (graphql.language.UnionTypeDefinition)5 EnumTypeDefinition (graphql.language.EnumTypeDefinition)4 InterfaceTypeDefinition (graphql.language.InterfaceTypeDefinition)4 OperationTypeDefinition (graphql.language.OperationTypeDefinition)4 ScalarTypeDefinition (graphql.language.ScalarTypeDefinition)4 TypeDefinition (graphql.language.TypeDefinition)4 List (java.util.List)4 Map (java.util.Map)4 Directive (graphql.language.Directive)3 FieldDefinition (graphql.language.FieldDefinition)3 InputValueDefinition (graphql.language.InputValueDefinition)3 GraphQLType (graphql.schema.GraphQLType)3 GraphQLError (graphql.GraphQLError)2 EnumValueDefinition (graphql.language.EnumValueDefinition)2 InputObjectTypeExtensionDefinition (graphql.language.InputObjectTypeExtensionDefinition)2 SchemaDefinition (graphql.language.SchemaDefinition)2 Type (graphql.language.Type)2