use of graphql.schema.GraphQLCodeRegistry in project graphql-java by graphql-java.
the class ReadmeExamples method dataFetching.
void dataFetching() {
DataFetcher<Foo> fooDataFetcher = new DataFetcher<Foo>() {
@Override
public Foo get(DataFetchingEnvironment environment) {
// environment.getSource() is the value of the surrounding
// object. In this case described by objectType
// Perhaps getting from a DB or whatever
Foo value = perhapsFromDatabase();
return value;
}
};
GraphQLObjectType objectType = newObject().name("ObjectType").field(newFieldDefinition().name("foo").type(GraphQLString)).build();
GraphQLCodeRegistry codeRegistry = newCodeRegistry().dataFetcher(coordinates("ObjectType", "foo"), fooDataFetcher).build();
}
use of graphql.schema.GraphQLCodeRegistry in project graphql-java by graphql-java.
the class ReadmeExamples method mutationExample.
void mutationExample() {
GraphQLInputObjectType episodeType = newInputObject().name("Episode").field(newInputObjectField().name("episodeNumber").type(Scalars.GraphQLInt)).build();
GraphQLInputObjectType reviewInputType = newInputObject().name("ReviewInput").field(newInputObjectField().name("stars").type(Scalars.GraphQLString).name("commentary").type(Scalars.GraphQLString)).build();
GraphQLObjectType reviewType = newObject().name("Review").field(newFieldDefinition().name("stars").type(GraphQLString)).field(newFieldDefinition().name("commentary").type(GraphQLString)).build();
GraphQLObjectType createReviewForEpisodeMutation = newObject().name("CreateReviewForEpisodeMutation").field(newFieldDefinition().name("createReview").type(reviewType).argument(newArgument().name("episode").type(episodeType)).argument(newArgument().name("review").type(reviewInputType))).build();
GraphQLCodeRegistry codeRegistry = newCodeRegistry().dataFetcher(coordinates("CreateReviewForEpisodeMutation", "createReview"), mutationDataFetcher()).build();
GraphQLSchema schema = GraphQLSchema.newSchema().query(queryType).mutation(createReviewForEpisodeMutation).codeRegistry(codeRegistry).build();
}
use of graphql.schema.GraphQLCodeRegistry in project graphql-java by graphql-java.
the class SchemaGenerator method makeExecutableSchemaImpl.
private GraphQLSchema makeExecutableSchemaImpl(TypeDefinitionRegistry typeRegistry, RuntimeWiring wiring, Map<String, OperationTypeDefinition> operationTypeDefinitions, Options options) {
SchemaGeneratorHelper.BuildContext buildCtx = new SchemaGeneratorHelper.BuildContext(typeRegistry, wiring, operationTypeDefinitions, options);
GraphQLSchema.Builder schemaBuilder = GraphQLSchema.newSchema();
Set<GraphQLDirective> additionalDirectives = schemaGeneratorHelper.buildAdditionalDirectiveDefinitions(buildCtx);
schemaBuilder.additionalDirectives(additionalDirectives);
schemaGeneratorHelper.buildSchemaDirectivesAndExtensions(buildCtx, schemaBuilder);
schemaGeneratorHelper.buildOperations(buildCtx, schemaBuilder);
Set<GraphQLType> additionalTypes = schemaGeneratorHelper.buildAdditionalTypes(buildCtx);
schemaBuilder.additionalTypes(additionalTypes);
buildCtx.getCodeRegistry().fieldVisibility(buildCtx.getWiring().getFieldVisibility());
GraphQLCodeRegistry codeRegistry = buildCtx.getCodeRegistry().build();
schemaBuilder.codeRegistry(codeRegistry);
buildCtx.getTypeRegistry().schemaDefinition().ifPresent(schemaDefinition -> {
String description = buildDescription(buildCtx, schemaDefinition, schemaDefinition.getDescription());
schemaBuilder.description(description);
});
GraphQLSchema graphQLSchema = schemaBuilder.build();
List<SchemaGeneratorPostProcessing> schemaTransformers = new ArrayList<>();
// schema build traversals
if (buildCtx.isDirectiveWiringRequired()) {
// handle directive wiring AFTER the schema has been built and hence type references are resolved at callback time
schemaTransformers.add(new SchemaDirectiveWiringSchemaGeneratorPostProcessing(buildCtx.getTypeRegistry(), buildCtx.getWiring(), buildCtx.getCodeRegistry()));
}
schemaTransformers.addAll(buildCtx.getWiring().getSchemaGeneratorPostProcessings());
for (SchemaGeneratorPostProcessing postProcessing : schemaTransformers) {
graphQLSchema = postProcessing.process(graphQLSchema);
}
return graphQLSchema;
}
Aggregations