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);
}
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));
}
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;
}
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();
}
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();
}
Aggregations