Open StringKe opened 1 year ago
I think you're confusing GraphQL SPQR with Spring GraphQL. While these 2 can be made to work together, you won't be getting any benefit from doing so, and neither is aware of the other.
SPQR doesn't understand @SchemaMapping
, as those annotations don't really map well to what SPQR is doing. Neither does SPQR generate schema files (schema.graphqls
) at any point, because it doesn't need to. It instead generates an executable schema directly in memory.
With all that said, you could make a composite annotation that acts as both @RequestMapping
and e.g. @GraphQLQuery
, or other SPQR annotations. Or configure SPQR to recognize any other annotation. For that you'd have to provide custom implementations of (at least) ResolverBuilder
and InputFieldBuilder
to the GraphQLSchemaGenerator
:
generator
.withResolverBuilders(new CustomResolverBuilder())
.withInputFieldBuilders(new CustomInputFieldBuilder())
There's a lot you could reuse from the existing implementations, so your customizations should be pretty simple. I can help you further in doing so if you get stuck. But. Before you attempt any of that, make triple sure this is really what you want to do, because it seems you currently have wrong expectations from SPQR. So please first get a cleaner understanding of what each tool in your toolchain does for you. SPQR Spring Boot starter is intended to be used by itself (e.g. using SPQR's annotations), and not to be mixed with Spring GraphQL's schema mapping features, as they work drastically differently on the conceptual level.
I envision using spring-graphq as a code-first-schema approach.
So I want to borrow the power of sqpr to generate schema, because spring-graphql must have a definition of grpahql.schema.
Since we have some other services that still need to be implemented using resetful (some hardware systems, we don't have the ability to modify it)
But why not use SPQR Spring starter directly? It gives you exactly what you want, right?
The annotations in spqr don't exist in a separate package.
My overall project is a microservice.
I don't use graphql in microservices but dubbo (an RPC protocol), and when my POJO needs to use sqpr's annotations I need to bring it in all my projects.
So instead of using sqpr, I'm currently using spring-graphql in gateway and publishing both graphql and restful api with custom annotations
Ok, it's easy enough to configure SPQR to scan for your custom annotations. I'd make an example, but I'm traveling and don't have a computer with me. I'll be back in a couple of days. In the meantime, look at AnnotatedResolverBuilder
and AnnotatedInputFieldBuilder
. You can extend those 2 and change the annotations they're looking for.
Thank you for your reply, I will try this way.
any updates?
I'm using
spring-graphql
and have aHttpAction
annotation defined in the project to implement bothhttp
andgraphql
functionality, I currently want to scan theHttpAction
annotation to generateschema.graphqls
viagraphql-spqr
What should I do to generate graphql schema for the type of the method tagged with
@HttpAction
?