Search in sources :

Example 1 with GraphQLCodeRegistry

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

the class DirectivesResolver method resolveDirectives.

public Map<String, GraphQLDirective> resolveDirectives(List<Directive> directives, GraphQLSchema schema, Map<String, Object> variables) {
    GraphQLCodeRegistry codeRegistry = schema.getCodeRegistry();
    Map<String, GraphQLDirective> directiveMap = new LinkedHashMap<>();
    directives.forEach(directive -> {
        GraphQLDirective protoType = schema.getDirective(directive.getName());
        if (protoType != null) {
            GraphQLDirective newDirective = protoType.transform(builder -> buildArguments(builder, codeRegistry, protoType, directive, variables));
            directiveMap.put(newDirective.getName(), newDirective);
        }
    });
    return ImmutableMap.copyOf(directiveMap);
}
Also used : GraphQLCodeRegistry(graphql.schema.GraphQLCodeRegistry) GraphQLDirective(graphql.schema.GraphQLDirective) LinkedHashMap(java.util.LinkedHashMap)

Example 2 with GraphQLCodeRegistry

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

the class IntrospectionWithDirectivesSupport method addDirectiveDefinitionFilter.

private GraphQLSchema addDirectiveDefinitionFilter(GraphQLSchema schema) {
    DataFetcher<?> df = env -> {
        List<GraphQLDirective> definedDirectives = env.getGraphQLSchema().getDirectives();
        return filterDirectives(schema, true, null, definedDirectives);
    };
    GraphQLCodeRegistry codeRegistry = schema.getCodeRegistry().transform(bld -> bld.dataFetcher(coordinates(__Schema, "directives"), df));
    return schema.transform(bld -> bld.codeRegistry(codeRegistry));
}
Also used : GraphQLSchemaElement(graphql.schema.GraphQLSchemaElement) GraphQLCodeRegistry(graphql.schema.GraphQLCodeRegistry) Node(graphql.language.Node) SchemaTransformer(graphql.schema.SchemaTransformer) GraphQLString(graphql.Scalars.GraphQLString) GraphQLDirectiveContainer(graphql.schema.GraphQLDirectiveContainer) TraversalControl(graphql.util.TraversalControl) ValuesResolver(graphql.execution.ValuesResolver) Introspection.__Type(graphql.introspection.Introspection.__Type) GraphQLType(graphql.schema.GraphQLType) TraverserContext(graphql.util.TraverserContext) GraphQLList.list(graphql.schema.GraphQLList.list) GraphQLAppliedDirective(graphql.schema.GraphQLAppliedDirective) InputValueWithState(graphql.schema.InputValueWithState) Introspection.__EnumValue(graphql.introspection.Introspection.__EnumValue) Assert.assertShouldNeverHappen(graphql.Assert.assertShouldNeverHappen) GraphQLNonNull.nonNull(graphql.schema.GraphQLNonNull.nonNull) DataFetcher(graphql.schema.DataFetcher) GraphQLSchema(graphql.schema.GraphQLSchema) GraphQLAppliedDirectiveArgument(graphql.schema.GraphQLAppliedDirectiveArgument) DirectivesUtil(graphql.DirectivesUtil) GraphQLObjectType(graphql.schema.GraphQLObjectType) GraphQLDirective(graphql.schema.GraphQLDirective) ImmutableSet(com.google.common.collect.ImmutableSet) PublicSpi(graphql.PublicSpi) CONTINUE(graphql.util.TraversalControl.CONTINUE) Set(java.util.Set) GraphQLTypeVisitorStub(graphql.schema.GraphQLTypeVisitorStub) FieldCoordinates.coordinates(graphql.schema.FieldCoordinates.coordinates) Introspection.__Schema(graphql.introspection.Introspection.__Schema) AstPrinter(graphql.language.AstPrinter) Introspection.__InputValue(graphql.introspection.Introspection.__InputValue) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) PublicApi(graphql.PublicApi) Assert.assertNotNull(graphql.Assert.assertNotNull) GraphQLObjectType.newObject(graphql.schema.GraphQLObjectType.newObject) Introspection.__Field(graphql.introspection.Introspection.__Field) NotNull(org.jetbrains.annotations.NotNull) GraphQLCodeRegistry(graphql.schema.GraphQLCodeRegistry) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList)

Example 3 with GraphQLCodeRegistry

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

the class SchemaDirectiveWiringSchemaGeneratorPostProcessing method process.

@Override
public GraphQLSchema process(GraphQLSchema originalSchema) {
    codeRegistryBuilder.trackChanges();
    Visitor visitor = new Visitor();
    GraphQLSchema newSchema = SchemaTransformer.transformSchema(originalSchema, visitor);
    if (visitor.schemaChanged() || codeRegistryBuilder.hasChanged()) {
        return newSchema.transform(builder -> {
            // they could have changed the code registry so rebuild it
            GraphQLCodeRegistry codeRegistry = this.codeRegistryBuilder.build();
            builder.codeRegistry(codeRegistry);
        });
    }
    return newSchema;
}
Also used : GraphQLCodeRegistry(graphql.schema.GraphQLCodeRegistry) GraphQLSchema(graphql.schema.GraphQLSchema)

Example 4 with GraphQLCodeRegistry

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

the class MappingExamples method directWiring.

private void directWiring() {
    GraphQLFieldDefinition descriptionField = GraphQLFieldDefinition.newFieldDefinition().name("description").type(Scalars.GraphQLString).build();
    GraphQLCodeRegistry codeRegistry = GraphQLCodeRegistry.newCodeRegistry().dataFetcher(coordinates("ObjectType", "description"), PropertyDataFetcher.fetching("desc")).build();
}
Also used : GraphQLFieldDefinition(graphql.schema.GraphQLFieldDefinition) GraphQLCodeRegistry(graphql.schema.GraphQLCodeRegistry)

Example 5 with GraphQLCodeRegistry

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

the class ReadmeExamples method unionType.

void unionType() {
    TypeResolver typeResolver = new TypeResolver() {

        @Override
        public GraphQLObjectType getType(TypeResolutionEnvironment env) {
            if (env.getObject() instanceof Cat) {
                return CatType;
            }
            if (env.getObject() instanceof Dog) {
                return DogType;
            }
            return null;
        }
    };
    GraphQLUnionType PetType = newUnionType().name("Pet").possibleType(CatType).possibleType(DogType).build();
    GraphQLCodeRegistry codeRegistry = newCodeRegistry().typeResolver("Pet", typeResolver).build();
}
Also used : GraphQLUnionType(graphql.schema.GraphQLUnionType) TypeResolver(graphql.schema.TypeResolver) Cat(graphql.GarfieldSchema.Cat) GraphQLCodeRegistry(graphql.schema.GraphQLCodeRegistry) TypeResolutionEnvironment(graphql.TypeResolutionEnvironment) Dog(graphql.GarfieldSchema.Dog)

Aggregations

GraphQLCodeRegistry (graphql.schema.GraphQLCodeRegistry)13 GraphQLFieldDefinition (graphql.schema.GraphQLFieldDefinition)5 GraphQLObjectType (graphql.schema.GraphQLObjectType)5 GraphQLOutputType (graphql.schema.GraphQLOutputType)4 GraphQLSchema (graphql.schema.GraphQLSchema)4 Map (java.util.Map)4 DataFetcher (graphql.schema.DataFetcher)3 DataFetchingEnvironment (graphql.schema.DataFetchingEnvironment)3 ExecutionStepInfo.newExecutionStepInfo (graphql.execution.ExecutionStepInfo.newExecutionStepInfo)2 ValuesResolver (graphql.execution.ValuesResolver)2 QueryDirectivesImpl (graphql.execution.directives.QueryDirectivesImpl)2 Argument (graphql.language.Argument)2 ExecutableNormalizedField (graphql.normalized.ExecutableNormalizedField)2 DataFetchingEnvironmentImpl.newDataFetchingEnvironment (graphql.schema.DataFetchingEnvironmentImpl.newDataFetchingEnvironment)2 DataFetchingFieldSelectionSet (graphql.schema.DataFetchingFieldSelectionSet)2 GraphQLDirective (graphql.schema.GraphQLDirective)2 GraphQLFieldsContainer (graphql.schema.GraphQLFieldsContainer)2 ArrayList (java.util.ArrayList)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 ImmutableList (com.google.common.collect.ImmutableList)1