Programmatically building Schema objects -- use "ObjectType" or "ObjectTypeDefinition" etc? #2681
-
I've been programmatically building schemas using val schema = GraphQLSchema.newSchema().query(
GraphQLObjectType.newObject().name("Query").fields() // ...
) But I see there are a distinction between IE, What's the difference between these two, and which should I be using to dynamically generate schemas programmatically? Thank you =) |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 2 replies
-
We have 2 phases in the definition of schema. The raw Abtract Syntax Tree objects are created by the parser during textual analysis.
The above SDL text would result in a parsed The second phase involves |
Beta Was this translation helpful? Give feedback.
-
If you make a schema programmatically - then you don't need AST elements - you just need |
Beta Was this translation helpful? Give feedback.
-
Ahh understood, thank you! So if I am interpreting this right, what I want to do is something like this? GraphQLSchema.Builder schemaBuilder = GraphQLSchema.newSchema();
schemaBuilder.query(GraphQLObjectType.newObject()
.name("Query")
.field(GraphQLFieldDefinition.newFieldDefinition()
.name("sayHello")
.type(Scalars.GraphQLString)
.argument(GraphQLArgument.newArgument()
.name("name")
.type(Scalars.GraphQLString)
.build())
)
.build());
GraphQLSchema schema = schemaBuilder.build();
schema.transform(builder -> {
GraphQLCodeRegistry.Builder codeRegistryBuilder = GraphQLCodeRegistry.newCodeRegistry();
codeRegistryBuilder
.dataFetcher(
FieldCoordinates.coordinates("Query", "sayHello"),
(DataFetcher<String>) environment -> "Hello " + environment.getArgument("name")
)
.build();
}); |
Beta Was this translation helpful? Give feedback.
If you make a schema programmatically - then you don't need AST elements - you just need
raphql.schema.GraphQXXXX
classes