Enigmatis / graphql-java-annotations

GraphQL Annotations for Java
Other
387 stars 97 forks source link

Graphql java 12 #209

Closed yarinvak closed 5 years ago

yarinvak commented 5 years ago

Solving https://github.com/Enigmatis/graphql-java-annotations/issues/206

This PR intends to work with new GraphQL-Java 12. In their new version, graphql-java broke their API completely and now Data Fetching and Type Resolving are separated from the GraphQL type objects into a new GraphQLCodeRegistry.

In this PR, we have refactored the way we handle data fetching and type resolving in graphql-java-annotations. GraphQLCodeRegistry.Builder is now encapsulated inside the GraphQLAnnotations object, so that in every place we previously went accross some data fetcher/type resolver and added it to the graphql object, we now add it to the code registry builder instead.

Then, when building the schema, it will be necessary to not only provide the object built by GraphQLAnnotations, but also provide the GraphQLCodeRegistry (so it needs to be taken from the GraphQLAnnotations object, to be built, and then provided to the GraphQLSchema Builder).

To make things easier, a new class called AnnotationsSchema is now providing a builder class to help you create your schema without the need of handling the code registry. You can simply call query, mutation, directive, etc, methods - and provide them with the class you want to build a GraphQL Object from.

For example:

GraphQLSchema schema = newAnnotationsSchema().query(Query.class).mutation(Mutation.class).directive(MyDirective.class).build();

A breaking change in this PR is that GraphQLAnnotations is not a singletone anymore. You should instatiate a GraphQLAnnotations object in order to use it to build your graphql objects (or use the static AnnotationsSchema.Builder).