Search in sources :

Example 11 with GraphQLAppliedDirective

use of graphql.schema.GraphQLAppliedDirective in project graphql-java by graphql-java.

the class SchemaGeneratorHelper method buildInterfaceType.

GraphQLInterfaceType buildInterfaceType(BuildContext buildCtx, InterfaceTypeDefinition typeDefinition) {
    GraphQLInterfaceType.Builder builder = GraphQLInterfaceType.newInterface();
    builder.definition(buildCtx.isCaptureAstDefinitions() ? typeDefinition : null);
    builder.name(typeDefinition.getName());
    builder.description(buildDescription(buildCtx, typeDefinition, typeDefinition.getDescription()));
    builder.comparatorRegistry(buildCtx.getComparatorRegistry());
    List<InterfaceTypeExtensionDefinition> extensions = interfaceTypeExtensions(typeDefinition, buildCtx);
    builder.extensionDefinitions(buildCtx.isCaptureAstDefinitions() ? extensions : emptyList());
    Pair<List<GraphQLDirective>, List<GraphQLAppliedDirective>> appliedDirectives = buildAppliedDirectives(buildCtx, inputTypeFactory(buildCtx), typeDefinition.getDirectives(), directivesOf(extensions), OBJECT, buildCtx.getDirectives(), buildCtx.getComparatorRegistry());
    buildAppliedDirectives(buildCtx, builder, appliedDirectives);
    typeDefinition.getFieldDefinitions().forEach(fieldDef -> {
        GraphQLFieldDefinition fieldDefinition = buildField(buildCtx, typeDefinition, fieldDef);
        builder.field(fieldDefinition);
    });
    extensions.forEach(extension -> extension.getFieldDefinitions().forEach(fieldDef -> {
        GraphQLFieldDefinition fieldDefinition = buildField(buildCtx, typeDefinition, fieldDef);
        if (!builder.hasField(fieldDefinition.getName())) {
            builder.field(fieldDefinition);
        }
    }));
    buildInterfaceTypeInterfaces(buildCtx, typeDefinition, builder, extensions);
    GraphQLInterfaceType interfaceType = builder.build();
    if (!buildCtx.getCodeRegistry().hasTypeResolver(interfaceType.getName())) {
        TypeResolver typeResolver = getTypeResolverForInterface(buildCtx, typeDefinition);
        buildCtx.getCodeRegistry().typeResolver(interfaceType, typeResolver);
    }
    return directivesObserve(buildCtx, interfaceType);
}
Also used : Value(graphql.language.Value) INPUT_FIELD_DEFINITION(graphql.introspection.Introspection.DirectiveLocation.INPUT_FIELD_DEFINITION) FIELD_DEFINITION(graphql.introspection.Introspection.DirectiveLocation.FIELD_DEFINITION) GraphQLInputObjectType(graphql.schema.GraphQLInputObjectType) GraphQLInterfaceType(graphql.schema.GraphQLInterfaceType) GraphQLUnionType(graphql.schema.GraphQLUnionType) DirectiveDefinition(graphql.language.DirectiveDefinition) GraphQLEnumValueDefinition(graphql.schema.GraphQLEnumValueDefinition) GraphQLAppliedDirective(graphql.schema.GraphQLAppliedDirective) INPUT_OBJECT(graphql.introspection.Introspection.DirectiveLocation.INPUT_OBJECT) TypeResolverProxy(graphql.schema.TypeResolverProxy) DataFetcherFactory(graphql.schema.DataFetcherFactory) Description(graphql.language.Description) EnumValueDefinition(graphql.language.EnumValueDefinition) ObjectTypeExtensionDefinition(graphql.language.ObjectTypeExtensionDefinition) OBJECT(graphql.introspection.Introspection.DirectiveLocation.OBJECT) Map(java.util.Map) SchemaGeneratorAppliedDirectiveHelper.buildDirectiveDefinitionFromAst(graphql.schema.idl.SchemaGeneratorAppliedDirectiveHelper.buildDirectiveDefinitionFromAst) SCALAR(graphql.introspection.Introspection.DirectiveLocation.SCALAR) Pair(graphql.util.Pair) SpecifiedByDirective(graphql.Directives.SpecifiedByDirective) GraphQLDirective(graphql.schema.GraphQLDirective) GraphQLNamedOutputType(graphql.schema.GraphQLNamedOutputType) SPECIFIED_BY_DIRECTIVE_DEFINITION(graphql.Directives.SPECIFIED_BY_DIRECTIVE_DEFINITION) FieldDefinition(graphql.language.FieldDefinition) GraphQLInputType(graphql.schema.GraphQLInputType) Set(java.util.Set) TypeDefinition(graphql.language.TypeDefinition) ENUM_VALUE(graphql.introspection.Introspection.DirectiveLocation.ENUM_VALUE) InterfaceTypeExtensionDefinition(graphql.language.InterfaceTypeExtensionDefinition) FieldCoordinates(graphql.schema.FieldCoordinates) GraphQLCodeRegistry(graphql.schema.GraphQLCodeRegistry) GraphqlDirectivesContainerTypeBuilder(graphql.schema.GraphqlDirectivesContainerTypeBuilder) Internal(graphql.Internal) DirectiveLocation(graphql.introspection.Introspection.DirectiveLocation) GraphQLScalarType(graphql.schema.GraphQLScalarType) GraphQLNamedInputType(graphql.schema.GraphQLNamedInputType) GraphQLType(graphql.schema.GraphQLType) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) InputObjectTypeExtensionDefinition(graphql.language.InputObjectTypeExtensionDefinition) ScalarTypeExtensionDefinition(graphql.language.ScalarTypeExtensionDefinition) LinkedHashSet(java.util.LinkedHashSet) AssertException(graphql.AssertException) StringValue(graphql.language.StringValue) Assert.assertNotNull(graphql.Assert.assertNotNull) ArrayDeque(java.util.ArrayDeque) GraphqlTypeComparatorRegistry(graphql.schema.GraphqlTypeComparatorRegistry) GraphQLDirectiveContainer(graphql.schema.GraphQLDirectiveContainer) GraphQLFieldDefinition(graphql.schema.GraphQLFieldDefinition) InputValueDefinition(graphql.language.InputValueDefinition) GraphQLInputObjectField(graphql.schema.GraphQLInputObjectField) ARGUMENT_DEFINITION(graphql.introspection.Introspection.DirectiveLocation.ARGUMENT_DEFINITION) UNION(graphql.introspection.Introspection.DirectiveLocation.UNION) EnumTypeDefinition(graphql.language.EnumTypeDefinition) Type(graphql.language.Type) GraphQLEnumValueDefinition.newEnumValueDefinition(graphql.schema.GraphQLEnumValueDefinition.newEnumValueDefinition) Collectors.toMap(java.util.stream.Collectors.toMap) TypeName(graphql.language.TypeName) TypeResolver(graphql.schema.TypeResolver) OperationTypeDefinition(graphql.language.OperationTypeDefinition) GraphQLObjectType(graphql.schema.GraphQLObjectType) NotAnInputTypeError(graphql.schema.idl.errors.NotAnInputTypeError) ObjectTypeDefinition(graphql.language.ObjectTypeDefinition) UnionTypeExtensionDefinition(graphql.language.UnionTypeExtensionDefinition) Collections.emptyList(java.util.Collections.emptyList) GraphQLArgument(graphql.schema.GraphQLArgument) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) Objects(java.util.Objects) NotAnOutputTypeError(graphql.schema.idl.errors.NotAnOutputTypeError) List(java.util.List) Comment(graphql.language.Comment) InterfaceTypeDefinition(graphql.language.InterfaceTypeDefinition) Optional(java.util.Optional) GraphQLEnumType(graphql.schema.GraphQLEnumType) PropertyDataFetcher(graphql.schema.PropertyDataFetcher) Node(graphql.language.Node) InputObjectTypeDefinition(graphql.language.InputObjectTypeDefinition) Deque(java.util.Deque) Function(java.util.function.Function) ENUM(graphql.introspection.Introspection.DirectiveLocation.ENUM) HashSet(java.util.HashSet) UnionTypeDefinition(graphql.language.UnionTypeDefinition) DataFetcherFactories(graphql.schema.DataFetcherFactories) DataFetcher(graphql.schema.DataFetcher) GraphQLSchema(graphql.schema.GraphQLSchema) ScalarTypeDefinition(graphql.language.ScalarTypeDefinition) SchemaGeneratorAppliedDirectiveHelper.buildAppliedDirectives(graphql.schema.idl.SchemaGeneratorAppliedDirectiveHelper.buildAppliedDirectives) DEPRECATED_DIRECTIVE_DEFINITION(graphql.Directives.DEPRECATED_DIRECTIVE_DEFINITION) EnumTypeExtensionDefinition(graphql.language.EnumTypeExtensionDefinition) GraphQLOutputType(graphql.schema.GraphQLOutputType) Directive(graphql.language.Directive) Argument(graphql.language.Argument) GraphQLTypeReference(graphql.schema.GraphQLTypeReference) FpKit(graphql.util.FpKit) GraphQLTypeReference.typeRef(graphql.schema.GraphQLTypeReference.typeRef) TypeResolver(graphql.schema.TypeResolver) GraphQLFieldDefinition(graphql.schema.GraphQLFieldDefinition) ArrayList(java.util.ArrayList) Collections.emptyList(java.util.Collections.emptyList) List(java.util.List) GraphQLInterfaceType(graphql.schema.GraphQLInterfaceType) InterfaceTypeExtensionDefinition(graphql.language.InterfaceTypeExtensionDefinition)

Example 12 with GraphQLAppliedDirective

use of graphql.schema.GraphQLAppliedDirective in project graphql-java by graphql-java.

the class SchemaGeneratorHelper method buildUnionType.

GraphQLUnionType buildUnionType(BuildContext buildCtx, UnionTypeDefinition typeDefinition) {
    GraphQLUnionType.Builder builder = GraphQLUnionType.newUnionType();
    builder.definition(buildCtx.isCaptureAstDefinitions() ? typeDefinition : null);
    builder.name(typeDefinition.getName());
    builder.description(buildDescription(buildCtx, typeDefinition, typeDefinition.getDescription()));
    builder.comparatorRegistry(buildCtx.getComparatorRegistry());
    List<UnionTypeExtensionDefinition> extensions = unionTypeExtensions(typeDefinition, buildCtx);
    builder.extensionDefinitions(buildCtx.isCaptureAstDefinitions() ? extensions : emptyList());
    typeDefinition.getMemberTypes().forEach(mt -> {
        GraphQLOutputType outputType = buildOutputType(buildCtx, mt);
        if (outputType instanceof GraphQLTypeReference) {
            builder.possibleType((GraphQLTypeReference) outputType);
        } else {
            builder.possibleType((GraphQLObjectType) outputType);
        }
    });
    Pair<List<GraphQLDirective>, List<GraphQLAppliedDirective>> appliedDirectives = buildAppliedDirectives(buildCtx, inputTypeFactory(buildCtx), typeDefinition.getDirectives(), directivesOf(extensions), UNION, buildCtx.getDirectives(), buildCtx.getComparatorRegistry());
    buildAppliedDirectives(buildCtx, builder, appliedDirectives);
    extensions.forEach(extension -> extension.getMemberTypes().forEach(mt -> {
        GraphQLNamedOutputType outputType = buildOutputType(buildCtx, mt);
        if (!builder.containType(outputType.getName())) {
            if (outputType instanceof GraphQLTypeReference) {
                builder.possibleType((GraphQLTypeReference) outputType);
            } else {
                builder.possibleType((GraphQLObjectType) outputType);
            }
        }
    }));
    GraphQLUnionType unionType = builder.build();
    if (!buildCtx.getCodeRegistry().hasTypeResolver(unionType.getName())) {
        TypeResolver typeResolver = getTypeResolverForUnion(buildCtx, typeDefinition);
        buildCtx.getCodeRegistry().typeResolver(unionType, typeResolver);
    }
    return directivesObserve(buildCtx, unionType);
}
Also used : Value(graphql.language.Value) INPUT_FIELD_DEFINITION(graphql.introspection.Introspection.DirectiveLocation.INPUT_FIELD_DEFINITION) FIELD_DEFINITION(graphql.introspection.Introspection.DirectiveLocation.FIELD_DEFINITION) GraphQLInputObjectType(graphql.schema.GraphQLInputObjectType) GraphQLInterfaceType(graphql.schema.GraphQLInterfaceType) GraphQLUnionType(graphql.schema.GraphQLUnionType) DirectiveDefinition(graphql.language.DirectiveDefinition) GraphQLEnumValueDefinition(graphql.schema.GraphQLEnumValueDefinition) GraphQLAppliedDirective(graphql.schema.GraphQLAppliedDirective) INPUT_OBJECT(graphql.introspection.Introspection.DirectiveLocation.INPUT_OBJECT) TypeResolverProxy(graphql.schema.TypeResolverProxy) DataFetcherFactory(graphql.schema.DataFetcherFactory) Description(graphql.language.Description) EnumValueDefinition(graphql.language.EnumValueDefinition) ObjectTypeExtensionDefinition(graphql.language.ObjectTypeExtensionDefinition) OBJECT(graphql.introspection.Introspection.DirectiveLocation.OBJECT) Map(java.util.Map) SchemaGeneratorAppliedDirectiveHelper.buildDirectiveDefinitionFromAst(graphql.schema.idl.SchemaGeneratorAppliedDirectiveHelper.buildDirectiveDefinitionFromAst) SCALAR(graphql.introspection.Introspection.DirectiveLocation.SCALAR) Pair(graphql.util.Pair) SpecifiedByDirective(graphql.Directives.SpecifiedByDirective) GraphQLDirective(graphql.schema.GraphQLDirective) GraphQLNamedOutputType(graphql.schema.GraphQLNamedOutputType) SPECIFIED_BY_DIRECTIVE_DEFINITION(graphql.Directives.SPECIFIED_BY_DIRECTIVE_DEFINITION) FieldDefinition(graphql.language.FieldDefinition) GraphQLInputType(graphql.schema.GraphQLInputType) Set(java.util.Set) TypeDefinition(graphql.language.TypeDefinition) ENUM_VALUE(graphql.introspection.Introspection.DirectiveLocation.ENUM_VALUE) InterfaceTypeExtensionDefinition(graphql.language.InterfaceTypeExtensionDefinition) FieldCoordinates(graphql.schema.FieldCoordinates) GraphQLCodeRegistry(graphql.schema.GraphQLCodeRegistry) GraphqlDirectivesContainerTypeBuilder(graphql.schema.GraphqlDirectivesContainerTypeBuilder) Internal(graphql.Internal) DirectiveLocation(graphql.introspection.Introspection.DirectiveLocation) GraphQLScalarType(graphql.schema.GraphQLScalarType) GraphQLNamedInputType(graphql.schema.GraphQLNamedInputType) GraphQLType(graphql.schema.GraphQLType) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) InputObjectTypeExtensionDefinition(graphql.language.InputObjectTypeExtensionDefinition) ScalarTypeExtensionDefinition(graphql.language.ScalarTypeExtensionDefinition) LinkedHashSet(java.util.LinkedHashSet) AssertException(graphql.AssertException) StringValue(graphql.language.StringValue) Assert.assertNotNull(graphql.Assert.assertNotNull) ArrayDeque(java.util.ArrayDeque) GraphqlTypeComparatorRegistry(graphql.schema.GraphqlTypeComparatorRegistry) GraphQLDirectiveContainer(graphql.schema.GraphQLDirectiveContainer) GraphQLFieldDefinition(graphql.schema.GraphQLFieldDefinition) InputValueDefinition(graphql.language.InputValueDefinition) GraphQLInputObjectField(graphql.schema.GraphQLInputObjectField) ARGUMENT_DEFINITION(graphql.introspection.Introspection.DirectiveLocation.ARGUMENT_DEFINITION) UNION(graphql.introspection.Introspection.DirectiveLocation.UNION) EnumTypeDefinition(graphql.language.EnumTypeDefinition) Type(graphql.language.Type) GraphQLEnumValueDefinition.newEnumValueDefinition(graphql.schema.GraphQLEnumValueDefinition.newEnumValueDefinition) Collectors.toMap(java.util.stream.Collectors.toMap) TypeName(graphql.language.TypeName) TypeResolver(graphql.schema.TypeResolver) OperationTypeDefinition(graphql.language.OperationTypeDefinition) GraphQLObjectType(graphql.schema.GraphQLObjectType) NotAnInputTypeError(graphql.schema.idl.errors.NotAnInputTypeError) ObjectTypeDefinition(graphql.language.ObjectTypeDefinition) UnionTypeExtensionDefinition(graphql.language.UnionTypeExtensionDefinition) Collections.emptyList(java.util.Collections.emptyList) GraphQLArgument(graphql.schema.GraphQLArgument) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) Objects(java.util.Objects) NotAnOutputTypeError(graphql.schema.idl.errors.NotAnOutputTypeError) List(java.util.List) Comment(graphql.language.Comment) InterfaceTypeDefinition(graphql.language.InterfaceTypeDefinition) Optional(java.util.Optional) GraphQLEnumType(graphql.schema.GraphQLEnumType) PropertyDataFetcher(graphql.schema.PropertyDataFetcher) Node(graphql.language.Node) InputObjectTypeDefinition(graphql.language.InputObjectTypeDefinition) Deque(java.util.Deque) Function(java.util.function.Function) ENUM(graphql.introspection.Introspection.DirectiveLocation.ENUM) HashSet(java.util.HashSet) UnionTypeDefinition(graphql.language.UnionTypeDefinition) DataFetcherFactories(graphql.schema.DataFetcherFactories) DataFetcher(graphql.schema.DataFetcher) GraphQLSchema(graphql.schema.GraphQLSchema) ScalarTypeDefinition(graphql.language.ScalarTypeDefinition) SchemaGeneratorAppliedDirectiveHelper.buildAppliedDirectives(graphql.schema.idl.SchemaGeneratorAppliedDirectiveHelper.buildAppliedDirectives) DEPRECATED_DIRECTIVE_DEFINITION(graphql.Directives.DEPRECATED_DIRECTIVE_DEFINITION) EnumTypeExtensionDefinition(graphql.language.EnumTypeExtensionDefinition) GraphQLOutputType(graphql.schema.GraphQLOutputType) Directive(graphql.language.Directive) Argument(graphql.language.Argument) GraphQLTypeReference(graphql.schema.GraphQLTypeReference) FpKit(graphql.util.FpKit) GraphQLTypeReference.typeRef(graphql.schema.GraphQLTypeReference.typeRef) GraphQLOutputType(graphql.schema.GraphQLOutputType) GraphQLTypeReference(graphql.schema.GraphQLTypeReference) GraphQLUnionType(graphql.schema.GraphQLUnionType) UnionTypeExtensionDefinition(graphql.language.UnionTypeExtensionDefinition) TypeResolver(graphql.schema.TypeResolver) GraphQLObjectType(graphql.schema.GraphQLObjectType) ArrayList(java.util.ArrayList) Collections.emptyList(java.util.Collections.emptyList) List(java.util.List) GraphQLNamedOutputType(graphql.schema.GraphQLNamedOutputType)

Aggregations

GraphQLAppliedDirective (graphql.schema.GraphQLAppliedDirective)12 GraphQLDirective (graphql.schema.GraphQLDirective)12 ArrayList (java.util.ArrayList)11 GraphQLArgument (graphql.schema.GraphQLArgument)10 GraphQLObjectType (graphql.schema.GraphQLObjectType)10 GraphQLSchema (graphql.schema.GraphQLSchema)10 GraphQLType (graphql.schema.GraphQLType)10 List (java.util.List)10 GraphQLEnumType (graphql.schema.GraphQLEnumType)9 GraphQLEnumValueDefinition (graphql.schema.GraphQLEnumValueDefinition)9 GraphQLFieldDefinition (graphql.schema.GraphQLFieldDefinition)9 GraphQLInputObjectField (graphql.schema.GraphQLInputObjectField)9 GraphQLInputObjectType (graphql.schema.GraphQLInputObjectType)9 GraphQLInputType (graphql.schema.GraphQLInputType)9 GraphQLInterfaceType (graphql.schema.GraphQLInterfaceType)9 GraphQLNamedOutputType (graphql.schema.GraphQLNamedOutputType)9 GraphQLScalarType (graphql.schema.GraphQLScalarType)9 GraphQLUnionType (graphql.schema.GraphQLUnionType)9 LinkedHashMap (java.util.LinkedHashMap)9 Map (java.util.Map)9