Comments (5)
I think I can help you on your way here a bit, since your usecase somewhat resembles mine in Issue 475.
The GraphQLSchemaGenerator provides several methods to expand the schema with types that are not annotated. In your case you can use the withAdditionalTypes method to register the extra interfaces to the Schema.
Please note that this method takes a list of GraphQLTypes. For the interface of your external project you would have to create the GraphQLType definition yourself, using the methods provided by the GraphQL Java project on which SPQR depends.
Like so: Creating a schema programatically.
That way you can register custom types to the Schema. To automatically discover any implementations of that interface you would probably need to create your own ImplementationDiscoveryStrategy and add that to the SchemaGenerator. Here is a link to the default one provided by SPQR to discover implementations of an interface: DefaultImplementationStrategy.
However, if you're not able to annotate your data classes I'm not sure SPQR is the right solution for your project. SPQR's benefits are mostly in that area. Assuming that your data structure does not change (often) you might be better off by creating an SDL file for it and use that to define a schema.
Take a look at GraphQL Java and GraphQL Kickstart for more information on how to define a schema and attach the required DataFetchers and TypeResolvers to it.
from graphql-spqr.
Hi @Balf, I really appreciate you helping out.
The workaround you propose seems very promising, but if I understand it correctly, it would require me to create the schema manually for these interface types.
Since in the data structure we use, there are quite many and complex abstract classes, this would result in a lot of work.
I ended up with the very same approach you mentioned in the end, i.e. I hacked the annotations into the third-party dependency and imported the schema generated by SPQR into another application using standard graphql-java.
The only thing I still use from SPQR are the scalar definitions since graphql-java-extended-scalars does not cover all scalar types for me.
Thank you again :)
from graphql-spqr.
Hey @niliha, sorry for the slow response.
Are these interfaces reachable from your root types (the one you registered with GraphQLSchemaGenerator
)? If so, you can easily control what gets mapped using various InterfaceMappingStrategy
implementations. E.g. you can map interfaces from specific packages or something custom. Everything in SPQR is configurable without annotations, that was one of the design goals.
from graphql-spqr.
@Balf Your situation looks a bit nore complicated, but I'll give it a look. I'm pretty sure you can also get away without manually mapping things...
from graphql-spqr.
Hi @kaqqao, thank you for guiding me in the right direction!
I had a look at InterfaceMappingStrategy
before, but was confused by the use of AnnotatedType
, thinking it would require annotations.
However, having a look at the documentation of AnnotatedType
, it's clear that the type must not be annotated.
For ayone else who might have a similar issue in the future, i.e. mapping java classes to GraphQL interfaces without using annotations, here is a more detailed description of what you need to do:
- Create a custom
InterfaceMappingStrategy
implementation, i.e.getInterfaces()
must return all class types you want to register as GraphQL interface andsupports()
must return true for these class types. One way to implement this is store the affected class types statically in the implementation. - Register this implementation using
GraphQLSchemaGenerator#withInterfaceMappingStrategy()
from graphql-spqr.
Related Issues (20)
- Explicitly register Java classes to the GraphQL schema. HOT 4
- Best way to error handling HOT 1
- Help in Handling Exceptions with SPQR HOT 1
- Question: Extending an InputObject type and handle it in SPQR HOT 3
- SDL Printing Fails on Schema Directives with Arguments HOT 4
- Spring 3.2: Cannot resolve parameter names for constructor public io.leangen.graphql.spqr.spring.web.dto.GraphQLRequest(java.lang.String,java.lang.String,java.lang.String,java.util.Map) HOT 2
- Compile parameters to support Spring Boot 3.2.1 (Spring Framework 6.1) HOT 1
- null values sent in response json HOT 1
- Schema Generation Regression in 0.12.4 HOT 1
- Polymorphism type on input
- Scalars containing an Instant cannot be serialized over subscription
- Schema generation at compile time?
- BUG: The DelegatingTypeResolver breaks when updating the GraphQLSchema using a Visitor HOT 1
- Feature Request: Add support for GraphQLOutputType to the SchemaTransformer HOT 39
- Make a public OperationMapper#createResolver overload to help with creating custom field resolvers
- Mark the gson-java8-datatype dependency as optional HOT 3
- Kotlin boolean property setters are skipped if isX prefixed HOT 11
- How can I define a GraphQL DTO attribute holding raw JSON?
- Change Date format HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from graphql-spqr.