Search in sources :

Example 1 with GraphQLNamedInputType

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

the class SchemaGeneratorHelper 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
 */
Set<GraphQLType> buildAdditionalTypes(BuildContext buildCtx) {
    TypeDefinitionRegistry typeRegistry = buildCtx.getTypeRegistry();
    Set<String> detachedTypeNames = getDetachedTypeNames(buildCtx);
    Set<GraphQLType> additionalTypes = new LinkedHashSet<>();
    // recursively record detached types on the ctx and add them to the additionalTypes set
    typeRegistry.types().values().stream().filter(typeDefinition -> detachedTypeNames.contains(typeDefinition.getName())).forEach(typeDefinition -> {
        TypeName typeName = TypeName.newTypeName().name(typeDefinition.getName()).build();
        if (typeDefinition instanceof InputObjectTypeDefinition) {
            if (buildCtx.hasInputType(typeDefinition) == null) {
                buildCtx.putInputType((GraphQLNamedInputType) buildInputType(buildCtx, typeName));
            }
            additionalTypes.add(buildCtx.inputGTypes.get(typeDefinition.getName()));
        } else {
            if (buildCtx.hasOutputType(typeDefinition) == null) {
                buildCtx.putOutputType(buildOutputType(buildCtx, typeName));
            }
            additionalTypes.add(buildCtx.outputGTypes.get(typeDefinition.getName()));
        }
    });
    typeRegistry.scalars().values().stream().filter(typeDefinition -> detachedTypeNames.contains(typeDefinition.getName())).forEach(scalarTypeDefinition -> {
        if (ScalarInfo.isGraphqlSpecifiedScalar(scalarTypeDefinition.getName())) {
            return;
        }
        if (buildCtx.hasInputType(scalarTypeDefinition) == null && buildCtx.hasOutputType(scalarTypeDefinition) == null) {
            buildCtx.putOutputType(buildScalar(buildCtx, scalarTypeDefinition));
        }
        if (buildCtx.hasInputType(scalarTypeDefinition) != null) {
            additionalTypes.add(buildCtx.inputGTypes.get(scalarTypeDefinition.getName()));
        } else if (buildCtx.hasOutputType(scalarTypeDefinition) != null) {
            additionalTypes.add(buildCtx.outputGTypes.get(scalarTypeDefinition.getName()));
        }
    });
    return additionalTypes;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) 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) TypeName(graphql.language.TypeName) GraphQLType(graphql.schema.GraphQLType) InputObjectTypeDefinition(graphql.language.InputObjectTypeDefinition)

Aggregations

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