Package graphql.schema.idl
Class SchemaGenerator
- java.lang.Object
-
- graphql.schema.idl.SchemaGenerator
-
@PublicApi public class SchemaGenerator extends java.lang.Object
This can generate a working runtime schema from a type registry and runtime wiringThe generator uses the
RuntimeWiringto insert code that runs behind the schema elements such asDataFetchers,TypeResolvers and scalarCoercing.The order of
DataFetcherresolution is as follows:- If the
WiringFactoryprovides theDataFetcherFactoryfor a field in its parent type then that is used - If the
WiringFactoryprovides theDataFetcherfor a field in its parent type then that is used - If the
RuntimeWiringprovides theDataFetcherfor a field in its parent type, then that is used - If the
RuntimeWiringprovides a defaultDataFetcherfor a fields parent type, then that is used - If the
WiringFactoryprovides a defaultDataFetcherFactoryfor any element then that is used - If the
GraphQLCodeRegistry.Builder.getDefaultDataFetcherFactory()provides aDataFetcherFactoryfor a value then that is used - Finally a
PropertyDataFetcheris used as a last resort for the field
The order of
TypeResolverresolution is as follows:- If the
WiringFactoryprovides aTypeResolverthen that is used - If the
TypeRuntimeWiringprovides aTypeResolverthen that is used
The order of
GraphQLScalarTyperesolution is as follows:- If the
WiringFactoryprovides aGraphQLScalarTypethen that is used - Otherwise
RuntimeWiring.getScalars()is used
- If the
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classSchemaGenerator.OptionsThese options control how the schema generation works
-
Constructor Summary
Constructors Constructor Description SchemaGenerator()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static GraphQLSchemacreatedMockedSchema(java.lang.String sdl)Created a schema from the SDL that is has a mocked runtime.GraphQLSchemamakeExecutableSchema(SchemaGenerator.Options options, TypeDefinitionRegistry typeRegistry, RuntimeWiring wiring)This will take aTypeDefinitionRegistryand aRuntimeWiringand put them together to create a executable schema controlled by the provided options.GraphQLSchemamakeExecutableSchema(TypeDefinitionRegistry typeRegistry, RuntimeWiring wiring)This will take aTypeDefinitionRegistryand aRuntimeWiringand put them together to create a executable schema
-
-
-
Method Detail
-
createdMockedSchema
public static GraphQLSchema createdMockedSchema(java.lang.String sdl)
Created a schema from the SDL that is has a mocked runtime.- Parameters:
sdl- the SDL to be mocked- Returns:
- a schema with a mocked runtime
- See Also:
RuntimeWiring.MOCKED_WIRING
-
makeExecutableSchema
public GraphQLSchema makeExecutableSchema(TypeDefinitionRegistry typeRegistry, RuntimeWiring wiring) throws SchemaProblem
This will take aTypeDefinitionRegistryand aRuntimeWiringand put them together to create a executable schema- Parameters:
typeRegistry- this can be obtained viaSchemaParser.parse(String)wiring- this can be built usingRuntimeWiring.newRuntimeWiring()- Returns:
- an executable schema
- Throws:
SchemaProblem- if there are problems in assembling a schema such as missing type resolvers or no operations defined
-
makeExecutableSchema
public GraphQLSchema makeExecutableSchema(SchemaGenerator.Options options, TypeDefinitionRegistry typeRegistry, RuntimeWiring wiring) throws SchemaProblem
This will take aTypeDefinitionRegistryand aRuntimeWiringand put them together to create a executable schema controlled by the provided options.- Parameters:
options- the controlling optionstypeRegistry- this can be obtained viaSchemaParser.parse(String)wiring- this can be built usingRuntimeWiring.newRuntimeWiring()- Returns:
- an executable schema
- Throws:
SchemaProblem- if there are problems in assembling a schema such as missing type resolvers or no operations defined
-
-