jcrygier / graphql-jpa

JPA Implementation of GraphQL (builds on graphql-java)
MIT License
165 stars 46 forks source link

Allowed manual manipulations of schema from the executor #45

Closed Jegp closed 7 years ago

Jegp commented 7 years ago

Inspired by this discussion I let the builder extend the GraphQLSchema.Builder class so it exposes regular builder methods.

I then exposed the builder (as a GraphQLSchema.Builder, not as a GraphQLSchemaBuilder) in the GraphQLExecutor to allow adding mutations runtime.

To keep the bean properties so the executor can be retained as autowired, I allowed the schema manipulations to happen post-construction. To address lestranges comment this could pave the way for dependency injection (1) and hides the specific implementation of the GraphQLSchemaBuilder, so it can be renamed/refactored to what it actually is: a wrapper for the builder that automatically constructs a (initial) schema from JPA entities.

As a practical example, changing the schema with this PR could look something like this:

GraphQLSchema.Builder builder = executor.getBuilder().mutation(droidMutation)
executor.updateSchema(builder)