Search in sources :

Example 11 with GraphQLOutputType

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

the class BatchedExecutionStrategy method fetchData.

private CompletableFuture<FetchedValues> fetchData(ExecutionContext executionContext, ExecutionStrategyParameters parameters, String fieldName, ExecutionNode node, GraphQLFieldDefinition fieldDef) {
    GraphQLObjectType parentType = node.getType();
    List<Field> fields = node.getFields().get(fieldName);
    List<MapOrList> parentResults = node.getParentResults();
    GraphqlFieldVisibility fieldVisibility = executionContext.getGraphQLSchema().getFieldVisibility();
    Map<String, Object> argumentValues = valuesResolver.getArgumentValues(fieldVisibility, fieldDef.getArguments(), fields.get(0).getArguments(), executionContext.getVariables());
    GraphQLOutputType fieldType = fieldDef.getType();
    DataFetchingFieldSelectionSet fieldCollector = DataFetchingFieldSelectionSetImpl.newCollector(executionContext, fieldType, fields);
    DataFetchingEnvironment environment = newDataFetchingEnvironment(executionContext).source(node.getSources()).arguments(argumentValues).fieldDefinition(fieldDef).fields(fields).fieldType(fieldDef.getType()).fieldTypeInfo(parameters.getTypeInfo()).parentType(parentType).selectionSet(fieldCollector).build();
    Instrumentation instrumentation = executionContext.getInstrumentation();
    InstrumentationFieldFetchParameters instrumentationFieldFetchParameters = new InstrumentationFieldFetchParameters(executionContext, fieldDef, environment);
    InstrumentationContext<Object> fetchCtx = instrumentation.beginFieldFetch(instrumentationFieldFetchParameters);
    CompletableFuture<Object> fetchedValue;
    try {
        DataFetcher<?> dataFetcher = instrumentation.instrumentDataFetcher(getDataFetcher(fieldDef), instrumentationFieldFetchParameters);
        Object fetchedValueRaw = dataFetcher.get(environment);
        fetchedValue = Async.toCompletableFuture(fetchedValueRaw);
    } catch (Exception e) {
        fetchedValue = new CompletableFuture<>();
        fetchedValue.completeExceptionally(e);
    }
    return fetchedValue.thenApply((result) -> assertResult(parentResults, result)).whenComplete(fetchCtx::onCompleted).handle(handleResult(executionContext, parameters, parentResults, fields, fieldDef, argumentValues, environment));
}
Also used : DataFetchingFieldSelectionSet(graphql.schema.DataFetchingFieldSelectionSet) Instrumentation(graphql.execution.instrumentation.Instrumentation) DataFetchingEnvironment(graphql.schema.DataFetchingEnvironment) DataFetchingEnvironmentBuilder.newDataFetchingEnvironment(graphql.schema.DataFetchingEnvironmentBuilder.newDataFetchingEnvironment) CompletionException(java.util.concurrent.CompletionException) Field(graphql.language.Field) GraphqlFieldVisibility(graphql.schema.visibility.GraphqlFieldVisibility) GraphQLOutputType(graphql.schema.GraphQLOutputType) CompletableFuture(java.util.concurrent.CompletableFuture) GraphQLObjectType(graphql.schema.GraphQLObjectType) InstrumentationFieldFetchParameters(graphql.execution.instrumentation.parameters.InstrumentationFieldFetchParameters)

Example 12 with GraphQLOutputType

use of graphql.schema.GraphQLOutputType 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 13 with GraphQLOutputType

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

the class ObjectsImplementInterfaces method isCompatible.

/**
 * @return {@code true} if the specified objectType satisfies the constraintType.
 */
boolean isCompatible(GraphQLOutputType constraintType, GraphQLOutputType objectType) {
    if (isSameType(constraintType, objectType)) {
        return true;
    } else if (constraintType instanceof GraphQLUnionType) {
        return objectIsMemberOfUnion((GraphQLUnionType) constraintType, objectType);
    } else if (constraintType instanceof GraphQLInterfaceType && objectType instanceof GraphQLObjectType) {
        return objectImplementsInterface((GraphQLInterfaceType) constraintType, (GraphQLObjectType) objectType);
    } else if (constraintType instanceof GraphQLList && objectType instanceof GraphQLList) {
        GraphQLOutputType wrappedConstraintType = (GraphQLOutputType) ((GraphQLList) constraintType).getWrappedType();
        GraphQLOutputType wrappedObjectType = (GraphQLOutputType) ((GraphQLList) objectType).getWrappedType();
        return isCompatible(wrappedConstraintType, wrappedObjectType);
    } else if (objectType instanceof GraphQLNonNull) {
        GraphQLOutputType nullableConstraint;
        if (constraintType instanceof GraphQLNonNull) {
            nullableConstraint = (GraphQLOutputType) ((GraphQLNonNull) constraintType).getWrappedType();
        } else {
            nullableConstraint = constraintType;
        }
        GraphQLOutputType nullableObjectType = (GraphQLOutputType) ((GraphQLNonNull) objectType).getWrappedType();
        return isCompatible(nullableConstraint, nullableObjectType);
    } else {
        return false;
    }
}
Also used : GraphQLList(graphql.schema.GraphQLList) GraphQLOutputType(graphql.schema.GraphQLOutputType) GraphQLUnionType(graphql.schema.GraphQLUnionType) GraphQLObjectType(graphql.schema.GraphQLObjectType) GraphQLNonNull(graphql.schema.GraphQLNonNull) GraphQLInterfaceType(graphql.schema.GraphQLInterfaceType)

Example 14 with GraphQLOutputType

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

the class SchemaGenerator method buildUnionType.

private GraphQLUnionType buildUnionType(BuildContext buildCtx, UnionTypeDefinition typeDefinition) {
    GraphQLUnionType.Builder builder = GraphQLUnionType.newUnionType();
    builder.definition(typeDefinition);
    builder.name(typeDefinition.getName());
    builder.description(schemaGeneratorHelper.buildDescription(typeDefinition, typeDefinition.getDescription()));
    builder.typeResolver(getTypeResolverForUnion(buildCtx, typeDefinition));
    List<UnionTypeExtensionDefinition> extensions = unionTypeExtensions(typeDefinition, buildCtx);
    typeDefinition.getMemberTypes().forEach(mt -> {
        GraphQLOutputType outputType = buildOutputType(buildCtx, mt);
        if (outputType instanceof GraphQLTypeReference) {
            builder.possibleType((GraphQLTypeReference) outputType);
        } else {
            builder.possibleType((GraphQLObjectType) outputType);
        }
    });
    builder.withDirectives(buildDirectives(typeDefinition.getDirectives(), directivesOf(extensions), UNION));
    extensions.forEach(extension -> extension.getMemberTypes().forEach(mt -> {
        GraphQLOutputType outputType = buildOutputType(buildCtx, mt);
        if (!builder.containType(outputType.getName())) {
            if (outputType instanceof GraphQLTypeReference) {
                builder.possibleType((GraphQLTypeReference) outputType);
            } else {
                builder.possibleType((GraphQLObjectType) outputType);
            }
        }
    }));
    return builder.build();
}
Also used : Arrays(java.util.Arrays) Value(graphql.language.Value) INPUT_FIELD_DEFINITION(graphql.introspection.Introspection.DirectiveLocation.INPUT_FIELD_DEFINITION) GraphQLInputObjectType(graphql.schema.GraphQLInputObjectType) GraphQLFieldDefinition(graphql.schema.GraphQLFieldDefinition) GraphQLInterfaceType(graphql.schema.GraphQLInterfaceType) InputValueDefinition(graphql.language.InputValueDefinition) GraphQLInputObjectField(graphql.schema.GraphQLInputObjectField) GraphQLUnionType(graphql.schema.GraphQLUnionType) SchemaDefinition(graphql.language.SchemaDefinition) GraphQLEnumValueDefinition(graphql.schema.GraphQLEnumValueDefinition) UNION(graphql.introspection.Introspection.DirectiveLocation.UNION) EnumTypeDefinition(graphql.language.EnumTypeDefinition) Type(graphql.language.Type) INPUT_OBJECT(graphql.introspection.Introspection.DirectiveLocation.INPUT_OBJECT) TypeResolverProxy(graphql.schema.TypeResolverProxy) GraphQLEnumValueDefinition.newEnumValueDefinition(graphql.schema.GraphQLEnumValueDefinition.newEnumValueDefinition) DataFetcherFactory(graphql.schema.DataFetcherFactory) EnumValueDefinition(graphql.language.EnumValueDefinition) ObjectTypeExtensionDefinition(graphql.language.ObjectTypeExtensionDefinition) OBJECT(graphql.introspection.Introspection.DirectiveLocation.OBJECT) GraphQLError(graphql.GraphQLError) Map(java.util.Map) TypeName(graphql.language.TypeName) TypeResolver(graphql.schema.TypeResolver) OperationTypeDefinition(graphql.language.OperationTypeDefinition) GraphQLObjectType(graphql.schema.GraphQLObjectType) GraphQLDirective(graphql.schema.GraphQLDirective) NotAnInputTypeError(graphql.schema.idl.errors.NotAnInputTypeError) ObjectTypeDefinition(graphql.language.ObjectTypeDefinition) UnionTypeExtensionDefinition(graphql.language.UnionTypeExtensionDefinition) Collections.emptyList(java.util.Collections.emptyList) FieldDefinition(graphql.language.FieldDefinition) GraphQLInputType(graphql.schema.GraphQLInputType) Set(java.util.Set) TypeDefinition(graphql.language.TypeDefinition) GraphQLArgument(graphql.schema.GraphQLArgument) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) NotAnOutputTypeError(graphql.schema.idl.errors.NotAnOutputTypeError) List(java.util.List) Stream(java.util.stream.Stream) ENUM_VALUE(graphql.introspection.Introspection.DirectiveLocation.ENUM_VALUE) InterfaceTypeDefinition(graphql.language.InterfaceTypeDefinition) Optional(java.util.Optional) GraphQLEnumType(graphql.schema.GraphQLEnumType) InterfaceTypeExtensionDefinition(graphql.language.InterfaceTypeExtensionDefinition) DirectiveLocation(graphql.introspection.Introspection.DirectiveLocation) GraphQLScalarType(graphql.schema.GraphQLScalarType) InputObjectTypeDefinition(graphql.language.InputObjectTypeDefinition) SchemaProblem(graphql.schema.idl.errors.SchemaProblem) HashMap(java.util.HashMap) GraphQLType(graphql.schema.GraphQLType) Stack(java.util.Stack) ArrayList(java.util.ArrayList) ENUM(graphql.introspection.Introspection.DirectiveLocation.ENUM) Introspection(graphql.introspection.Introspection) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) UnionTypeDefinition(graphql.language.UnionTypeDefinition) DataFetcherFactories(graphql.schema.DataFetcherFactories) InputObjectTypeExtensionDefinition(graphql.language.InputObjectTypeExtensionDefinition) ScalarTypeExtensionDefinition(graphql.language.ScalarTypeExtensionDefinition) DataFetcher(graphql.schema.DataFetcher) GraphQLSchema(graphql.schema.GraphQLSchema) ScalarTypeDefinition(graphql.language.ScalarTypeDefinition) EnumTypeExtensionDefinition(graphql.language.EnumTypeExtensionDefinition) GraphQLOutputType(graphql.schema.GraphQLOutputType) Directive(graphql.language.Directive) GraphQLTypeReference(graphql.schema.GraphQLTypeReference) PublicApi(graphql.PublicApi) Assert.assertNotNull(graphql.Assert.assertNotNull) GraphQLTypeReference.typeRef(graphql.schema.GraphQLTypeReference.typeRef) Collections(java.util.Collections) GraphQLOutputType(graphql.schema.GraphQLOutputType) GraphQLTypeReference(graphql.schema.GraphQLTypeReference) GraphQLUnionType(graphql.schema.GraphQLUnionType) UnionTypeExtensionDefinition(graphql.language.UnionTypeExtensionDefinition) GraphQLObjectType(graphql.schema.GraphQLObjectType)

Aggregations

GraphQLOutputType (graphql.schema.GraphQLOutputType)14 GraphQLObjectType (graphql.schema.GraphQLObjectType)5 GraphQLFieldDefinition (graphql.schema.GraphQLFieldDefinition)4 GraphQLList (graphql.schema.GraphQLList)4 GraphQLInterfaceType (graphql.schema.GraphQLInterfaceType)3 GraphQLScalarType (graphql.schema.GraphQLScalarType)3 GraphQLUnionType (graphql.schema.GraphQLUnionType)3 ArrayList (java.util.ArrayList)3 Instrumentation (graphql.execution.instrumentation.Instrumentation)2 InstrumentationFieldFetchParameters (graphql.execution.instrumentation.parameters.InstrumentationFieldFetchParameters)2 Introspection (graphql.introspection.Introspection)2 Field (graphql.language.Field)2 TypeName (graphql.language.TypeName)2 DataFetcher (graphql.schema.DataFetcher)2 DataFetchingEnvironment (graphql.schema.DataFetchingEnvironment)2 DataFetchingEnvironmentBuilder.newDataFetchingEnvironment (graphql.schema.DataFetchingEnvironmentBuilder.newDataFetchingEnvironment)2 DataFetchingFieldSelectionSet (graphql.schema.DataFetchingFieldSelectionSet)2 GraphQLEnumType (graphql.schema.GraphQLEnumType)2 GraphQLSchema (graphql.schema.GraphQLSchema)2 GraphQLType (graphql.schema.GraphQLType)2