smallrye-graphql icon indicating copy to clipboard operation
smallrye-graphql copied to clipboard

Fire CDI event for graphql.schema.idl.TypeDefinitionRegistry for extensions

Open beikov opened this issue 4 years ago • 7 comments

The initial discussion happened here: https://github.com/eclipse/microprofile-graphql/issues/127

I would like to be able to contribute GraphQL types, based on existing discovered types via graphql.schema.idl.TypeDefinitionRegistry. This is the way I integrate with graphql-java already: https://github.com/Blazebit/blaze-persistence/blob/master/integration/graphql/src/main/java/com/blazebit/persistence/integration/graphql/GraphQLEntityViewSupportFactory.java#L180

This allows me to add support for the Relay specification which can be used to implement a very efficient keyset based pagination approach.

beikov avatar Jul 07 '20 15:07 beikov

Thanks @beikov :)

Let me try something and let you know once I have something. Doing the same as what I have done for the schemaBuilder, but for TypeDefinitionRegistry. Right ?

phillip-kruger avatar Jul 07 '20 15:07 phillip-kruger

Correct

beikov avatar Jul 07 '20 15:07 beikov

Hi @beikov . I am not sure how to do this. Maybe you can look at https://github.com/smallrye/smallrye-graphql/blob/master/server/implementation/src/main/java/io/smallrye/graphql/bootstrap/Bootstrap.java, this is where we build the schema. If you can suggest how we should get to TypeDefinitionRegistry that can help. I am not sure how...

phillip-kruger avatar Jul 07 '20 15:07 phillip-kruger

Sure. Usually you just instantiate the TypeDefinitionRegistry or start from a schema SDL file. The support for a SDL file could be a good nice extension.

TypeDefinitionRegistry typeRegistry;
if (sdl == null) {
    typeRegistry = new TypeDefinitionRegistry();
} else {
    typeRegistry = new SchemaParser().parse(sdl);
}
// Register types as discovered by SmallRye to typeRegistry
// publish CDI event for typeRegistry

TypeRuntimeWiring.Builder queryWiringBuilder = TypeRuntimeWiring.newTypeWiring("Query");
// Wire query methods as discovered to queryWiringBuilder
// Maybe also publish a CDI event for queryWiringBuilder?

RuntimeWiring runtimeWiring = RuntimeWiring.newRuntimeWiring()
                .type(queryWiringBuilder.build());
SchemaGenerator schemaGenerator = new SchemaGenerator();
GraphQLSchema schema = schemaGenerator.makeExecutableSchema(typeRegistry, runtimeWiring);

beikov avatar Jul 07 '20 16:07 beikov

Hi @beikov - thanks, this will be a different way than how we build the schema at the moment... I'll look at this a.s.a.p, if you need it soon, you are welcome to do a PR with your proposed solution ? That would be very cool :)

phillip-kruger avatar Jul 07 '20 18:07 phillip-kruger

Thanks for looking into this, I don't have a rush. Sorry that I can't contribute that right now, but I'm about to finish a project and already quite busy with that. Looking forward to testing this though when you manage to try this!

beikov avatar Jul 08 '20 06:07 beikov

I would like to point out that in the Spring world, the DGS framework is currently the leading declarative solution for GraphQL which is very advanced. DGS offers support for federation and dynamic types by allowing to provide custom TypeDefinitionRegistry: https://netflix.github.io/dgs/advanced/dynamic-schemas/

beikov avatar Jul 25 '21 09:07 beikov