graphql-java-kickstart / graphql-java-servlet

Servlet endpoint for GraphQL Java
https://www.graphql-java-kickstart.com/servlet/
Other
223 stars 113 forks source link

SDL support for OSGi servlet #143

Open sergehuber opened 5 years ago

sergehuber commented 5 years ago

It would be nice to add SDL (https://www.graphql-java.com/documentation/v11/schema/) support to the GraphQL Java Servlet project. But this might also imply having a way to provide "parts" of SDL as well as Data Fetchers (TypeProviders should be ok) in a pluggable way (to stay compatible with OSGi notably).

oliemansm commented 5 years ago

@sergehuber Not sure I quite follow you here. This servlet is a wrapper around graphql-java and therefore provides support for this. When used in combination with graphql-java-tools you get automatic parsing of SDL found on the class path. So what it is exactly that you would like to be able to do which you can't right now?

sergehuber commented 5 years ago

I wasn't aware this was possible. So basically I need to provide a schema Provider that uses graphql-java-tools?

I thought SDL was directly supported by graphql-java or did I misunderstand there? it seems they have a SchemaParser available ? https://www.graphql-java.com/tutorials/getting-started-with-spring-boot/#schema

Regards, Serge...

oliemansm commented 5 years ago

Well you don't have to use graphql-java-tools, you can use the SchemaParser from graphql-java directly. So the way to use it in combination with graphql-java-servlet would be to first create a GraphQLSchema with that SchemaParser from graphql-java and then pass that in to create the servlet using GraphQLHttpServlet.with(schema).

Does that answer your question?

sergehuber commented 5 years ago

Almost, I'm using the OSGi servlet right now, which seems to lack an extension point for that. Maybe I will need to contribute it if my understanding is correct ?

oliemansm commented 5 years ago

Right, I don't have any experience with OSGi unfortunately. There's a GraphQLSchemaProvider in the OsgiGraphQLHttpServlet that's responsible for providing the GraphQLSchema. Can't you use that somehow?

sergehuber commented 5 years ago

Actually that schemaProvider is initialized this way :

    this.schemaProvider = new DefaultGraphQLSchemaProvider(newSchema().query(queryTypeBuilder.build())
            .mutation(mutationType)
            .subscription(subscriptionType)
            .additionalTypes(types)
            .build());

so it's not pluggeable (yet) and can't hook a parser to generate it. I could provide a patch to do this but I need to get around to implementing and testing that.