GithubHelp home page GithubHelp logo

Comments (4)

Balf avatar Balf commented on June 6, 2024

@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.

kaqqao avatar kaqqao commented on June 6, 2024

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 not io.leangen.
  • withNestedResolverBuilders(new AnnotatedResolverBuilder()) - This is redundant. AnnotatedResolverBuilder is the default.

I'll have a look at #480.

from graphql-spqr.

Balf avatar Balf commented on June 6, 2024

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.

Balf avatar Balf commented on June 6, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.