GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Override type resolution for a single type · graphql-java-kickstart/graphql-java-tools · Discussion #718

Override type resolution for a single type #718

Unanswered
rrva asked this question in Q&A
Override type resolution for a single type #718
@rrva rrva
Nov 7, 2022 · 2 comments · 2 replies
Return to top
Discussion options
  • Uh oh!

    There was an error while loading. Please reload this page.

rrva
Nov 7, 2022

If you use the automatic wiring for types, is there a way to override the wiring/type resolution for a single type but keep the rest?

I have a GraphQL interface Fruit which has subtypes Apple and Banana. There exists a corresponding java interface Fruit and java classes Apple and Banana .

How do I introduce a new class only on the java side, lets say called Orange, which on the java side implements Fruit, but I want it to resolve to Banana on the GraphQL side (so I do not have to introduce another GraphQL type in the schema).

You must be logged in to vote
All reactions

Replies: 2 comments · 2 replies

Comment options
  • Uh oh!

    There was an error while loading. Please reload this page.

  • Uh oh!

    There was an error while loading. Please reload this page.

rrva
Nov 7, 2022
Author

This gets me half-way:

    val executableSchema = schemaParser.makeExecutableSchema()
    val oldFruitTypeResolver =
        executableSchema.codeRegistry.getTypeResolver(GraphQLInterfaceType.newInterface().name("Fruit").build())

    val fruitTypeResolver = TypeResolver { env ->
        when {
            env.getObject<Any>() is Orange -> env.schema.getObjectType("Banana")
            else -> oldFruitTypeResolver.getType(env)
        }
    }

    val schemaObjects = schemaParser.parseSchemaObjects()

    return GraphQLSchema.newSchema()
        .description(schemaObjects.description)
        .query(schemaObjects.query)
        .mutation(schemaObjects.mutation)
        .subscription(schemaObjects.subscription)
        .additionalTypes(schemaObjects.dictionary)
        .additionalDirectives(schemaObjects.directives)
        .codeRegistry(

            schemaObjects.codeRegistryBuilder
                .typeResolver("Fruit", fruitTypeResolver)
                .build()
        )
        .build()

but then I end up building a schema which does not have the correct data fetchers

You must be logged in to vote
All reactions
0 replies
Comment options
  • Uh oh!

    There was an error while loading. Please reload this page.

rrva
Nov 11, 2022
Author

@oryan-block do you if there is an easy solution with the current graphql-java-tools for this? I am even considering departing graphql-java-tools and using pure graphql-java for this type of issue, but this is substantial work on my end and I loose out on all of the niceties of auto-wiring.

You must be logged in to vote
All reactions
2 replies
@oryan-block
Comment options
  • Uh oh!

    There was an error while loading. Please reload this page.

  • Uh oh!

    There was an error while loading. Please reload this page.

oryan-block Mar 3, 2023
Maintainer

Sorry I didn't have time to look at this sooner.
Did you try using a TypeDefinitionFactory? This can be done to add GraphQL types dynamically even if they are not present in the schema.

https://www.graphql-java-kickstart.com/tools/type-definition-factory/

All reactions
@rrva
Comment options
  • Uh oh!

    There was an error while loading. Please reload this page.

rrva Mar 3, 2023
Author

Thanks I forgot to mark this one as resolved. graphql-java/graphql-java#3013 (reply in thread)

All reactions
  • 👍 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
🙏
Q&A
Labels
None yet
2 participants
@rrva @oryan-block
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.