Comments (4)
@kaqqao I noticed your comments in #476 yesterday, both those aimed at nihila and myself, and took a look at the DefaultImplementationDiscoveryStrategy class. This actually already supports a method to add additional implemention classes, which resolves my issue quite nicely! My code now looks like this:
AnimalService animalService = new AnimalService();
GraphQLSchemaGenerator schemaGenerator = new GraphQLSchemaGenerator()
.withBasePackages("io.leangen")
.withOperationsFromSingleton(animalService)
.withNestedResolverBuilders(new AnnotatedResolverBuilder());
var defaultImplementationDiscoveryStrategy = new DefaultImplementationDiscoveryStrategy();
//The new solution that just takes a class that implements IAnimal
for (var additionalImplementationProvider : additionalImplementationProvider) {
// This line returns Llama.class from my original code
Class<?> additionalImplementation = additionalImplementationProvider.getClass();
defaultImplementationDiscoveryStrategy.withAdditionalImplementations(additionalImplementation);
}
schemaGenerator.withImplementationDiscoveryStrategy(defaultImplementationDiscoveryStrategy);
GraphQLSchema schema = schemaGenerator.generate();
This code takes the annotated Llama.class and adds it to the Schema as required, without having to define the entire type myself as per my previous solution. I'm closing this issue, as this solution does exactly what I wanted.
If you have time, could you take a look at #480 that I raised recently? That one is somewhat more complex and I don't know where to start in that case.
from graphql-spqr.
Yup, this looks good! 👍
Just 2 remarks:
withBasePackages("io.leangen")
- Not sure if it was just an example, but this should be your base package, so notio.leangen
.withNestedResolverBuilders(new AnnotatedResolverBuilder())
- This is redundant.AnnotatedResolverBuilder
is the default.
I'll have a look at #480.
from graphql-spqr.
Thanks for your feedback, the package name is indeed my own package in the actual code. The second point I'll update, cheers!
from graphql-spqr.
@kaqqao I'd like to contribute to the documentation, so I can add documentation for issues like mine. What would be the best way to do that?
from graphql-spqr.
Related Issues (20)
- Setup GitHub Pages for documentation
- Apply bean validation annotations only if an appropriate group is enabled [Breaking]
- How to use executionResult data HOT 2
- Failing tests - ComplexityTest class
- How to map a java class to GraphQL interface without using @GraphQLInterface annotation? HOT 5
- 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
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.