Search in sources :

Example 1 with Pair

use of graphql.util.Pair in project graphql-java by graphql-java.

the class SchemaGeneratorHelper method buildObjectType.

GraphQLObjectType buildObjectType(BuildContext buildCtx, ObjectTypeDefinition typeDefinition) {
    GraphQLObjectType.Builder builder = GraphQLObjectType.newObject();
    builder.definition(buildCtx.isCaptureAstDefinitions() ? typeDefinition : null);
    builder.name(typeDefinition.getName());
    builder.description(buildDescription(buildCtx, typeDefinition, typeDefinition.getDescription()));
    builder.comparatorRegistry(buildCtx.getComparatorRegistry());
    List<ObjectTypeExtensionDefinition> extensions = objectTypeExtensions(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);
        }
    }));
    buildObjectTypeInterfaces(buildCtx, typeDefinition, builder, extensions);
    return directivesObserve(buildCtx, builder.build());
}
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) ObjectTypeExtensionDefinition(graphql.language.ObjectTypeExtensionDefinition) InputObjectTypeExtensionDefinition(graphql.language.InputObjectTypeExtensionDefinition) GraphQLObjectType(graphql.schema.GraphQLObjectType) GraphQLFieldDefinition(graphql.schema.GraphQLFieldDefinition) ArrayList(java.util.ArrayList) Collections.emptyList(java.util.Collections.emptyList) List(java.util.List)

Example 2 with Pair

use of graphql.util.Pair in project graphql-java by graphql-java.

the class SchemaGeneratorHelper method buildScalar.

GraphQLScalarType buildScalar(BuildContext buildCtx, ScalarTypeDefinition typeDefinition) {
    TypeDefinitionRegistry typeRegistry = buildCtx.getTypeRegistry();
    RuntimeWiring runtimeWiring = buildCtx.getWiring();
    WiringFactory wiringFactory = runtimeWiring.getWiringFactory();
    List<ScalarTypeExtensionDefinition> extensions = scalarTypeExtensions(typeDefinition, buildCtx);
    ScalarWiringEnvironment environment = new ScalarWiringEnvironment(typeRegistry, typeDefinition, extensions);
    GraphQLScalarType scalar;
    if (wiringFactory.providesScalar(environment)) {
        scalar = wiringFactory.getScalar(environment);
    } else {
        scalar = buildCtx.getWiring().getScalars().get(typeDefinition.getName());
    }
    if (!ScalarInfo.isGraphqlSpecifiedScalar(scalar)) {
        String description = getScalarDesc(scalar, typeDefinition);
        Pair<List<GraphQLDirective>, List<GraphQLAppliedDirective>> appliedDirectives = buildAppliedDirectives(buildCtx, inputTypeFactory(buildCtx), typeDefinition.getDirectives(), directivesOf(extensions), SCALAR, buildCtx.getDirectives(), buildCtx.getComparatorRegistry());
        scalar = scalar.transform(builder -> {
            builder.description(description).definition(buildCtx.isCaptureAstDefinitions() ? typeDefinition : null).comparatorRegistry(buildCtx.getComparatorRegistry()).specifiedByUrl(getSpecifiedByUrl(typeDefinition, extensions));
            buildAppliedDirectives(buildCtx, builder, appliedDirectives);
        });
    }
    return directivesObserve(buildCtx, scalar);
}
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) ArrayList(java.util.ArrayList) Collections.emptyList(java.util.Collections.emptyList) List(java.util.List) ScalarTypeExtensionDefinition(graphql.language.ScalarTypeExtensionDefinition) GraphQLScalarType(graphql.schema.GraphQLScalarType)

Example 3 with Pair

use of graphql.util.Pair in project graphql-java by graphql-java.

the class SchemaGeneratorHelper method buildEnumType.

GraphQLEnumType buildEnumType(BuildContext buildCtx, EnumTypeDefinition typeDefinition) {
    GraphQLEnumType.Builder builder = GraphQLEnumType.newEnum();
    builder.definition(buildCtx.isCaptureAstDefinitions() ? typeDefinition : null);
    builder.name(typeDefinition.getName());
    builder.description(buildDescription(buildCtx, typeDefinition, typeDefinition.getDescription()));
    builder.comparatorRegistry(buildCtx.getComparatorRegistry());
    List<EnumTypeExtensionDefinition> extensions = enumTypeExtensions(typeDefinition, buildCtx);
    builder.extensionDefinitions(buildCtx.isCaptureAstDefinitions() ? extensions : emptyList());
    EnumValuesProvider enumValuesProvider = buildCtx.getWiring().getEnumValuesProviders().get(typeDefinition.getName());
    typeDefinition.getEnumValueDefinitions().forEach(evd -> {
        GraphQLEnumValueDefinition enumValueDefinition = buildEnumValue(buildCtx, typeDefinition, enumValuesProvider, evd);
        builder.value(enumValueDefinition);
    });
    extensions.forEach(extension -> extension.getEnumValueDefinitions().forEach(evd -> {
        GraphQLEnumValueDefinition enumValueDefinition = buildEnumValue(buildCtx, typeDefinition, enumValuesProvider, evd);
        if (!builder.hasValue(enumValueDefinition.getName())) {
            builder.value(enumValueDefinition);
        }
    }));
    Pair<List<GraphQLDirective>, List<GraphQLAppliedDirective>> appliedDirectives = buildAppliedDirectives(buildCtx, inputTypeFactory(buildCtx), typeDefinition.getDirectives(), directivesOf(extensions), ENUM, buildCtx.getDirectives(), buildCtx.getComparatorRegistry());
    buildAppliedDirectives(buildCtx, builder, appliedDirectives);
    return directivesObserve(buildCtx, builder.build());
}
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) GraphQLEnumType(graphql.schema.GraphQLEnumType) GraphQLEnumValueDefinition(graphql.schema.GraphQLEnumValueDefinition) ArrayList(java.util.ArrayList) Collections.emptyList(java.util.Collections.emptyList) List(java.util.List) EnumTypeExtensionDefinition(graphql.language.EnumTypeExtensionDefinition)

Example 4 with Pair

use of graphql.util.Pair 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 5 with Pair

use of graphql.util.Pair 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

Assert.assertNotNull (graphql.Assert.assertNotNull)5 AssertException (graphql.AssertException)5 DEPRECATED_DIRECTIVE_DEFINITION (graphql.Directives.DEPRECATED_DIRECTIVE_DEFINITION)5 SPECIFIED_BY_DIRECTIVE_DEFINITION (graphql.Directives.SPECIFIED_BY_DIRECTIVE_DEFINITION)5 SpecifiedByDirective (graphql.Directives.SpecifiedByDirective)5 Internal (graphql.Internal)5 DirectiveLocation (graphql.introspection.Introspection.DirectiveLocation)5 ARGUMENT_DEFINITION (graphql.introspection.Introspection.DirectiveLocation.ARGUMENT_DEFINITION)5 ENUM (graphql.introspection.Introspection.DirectiveLocation.ENUM)5 ENUM_VALUE (graphql.introspection.Introspection.DirectiveLocation.ENUM_VALUE)5 FIELD_DEFINITION (graphql.introspection.Introspection.DirectiveLocation.FIELD_DEFINITION)5 INPUT_FIELD_DEFINITION (graphql.introspection.Introspection.DirectiveLocation.INPUT_FIELD_DEFINITION)5 INPUT_OBJECT (graphql.introspection.Introspection.DirectiveLocation.INPUT_OBJECT)5 OBJECT (graphql.introspection.Introspection.DirectiveLocation.OBJECT)5 SCALAR (graphql.introspection.Introspection.DirectiveLocation.SCALAR)5 UNION (graphql.introspection.Introspection.DirectiveLocation.UNION)5 Argument (graphql.language.Argument)5 Comment (graphql.language.Comment)5 Description (graphql.language.Description)5 Directive (graphql.language.Directive)5