Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Null Default DataFetchers will overwrite non null ones inside RuntimeWiring.Builder #3431

Open
AntoineGRHD opened this issue Feb 1, 2024 · 2 comments
Labels
keep-open Tells Stale Bot to keep PRs and issues open

Comments

@AntoineGRHD
Copy link

Describe the bug

Successive calls to RuntimeWiring.Builder::type will overwrite the defaultDataFetchers value with null if the defaultDataFetcher isn't present.

wiringBuilder.type("Query", builder -> builder.defaultDataFetcher(defaultDataFetcher)) //Sets the default dataFetcher
             .type("Query", builder -> builder.dataFetcher("asset", assetDataFetcher)) //Unsets the default dataFetcher
             .type("Query", builder -> builder.dataFetcher("person", personDataFetcher))

Setting the default data fetcher with the last call will work, but I believe this isn't a good solution since this is a builder pattern and there's already a null check for setting the enumValuesProvider, and typeResolver.

Moreover in my case using it with spring-graphql, Spring's RuntimeWiringConfigurer will first let you set your custom DataFetchers and then add all the annotated data fetchers, not the other way around.

Proposed solution

Inside graphql.schema.idl.RuntimeWiring.class, RuntimeWiring.Builder::type(TypeRuntimeWiring typeRuntimeWiring)

Replace :

this.defaultDataFetchers.put(typeName, typeRuntimeWiring.getDefaultDataFetcher());

With : (Just like the typeResolver and enumValuesProvider right after that)

DataFetcher defaultDataFetcher = typeRuntimeWiring.getDefaultDataFetcher();
if (defaultDataFetcher != null) {
        this.defaultDataFetchers.put(typeName, defaultDataFetcher);
}
@dondonz dondonz added the keep-open Tells Stale Bot to keep PRs and issues open label Feb 11, 2024
@bbakerman
Copy link
Member

Why is that you calling a TypeRuntimeWiring.Builder so many times? Is this trying to show that multiple steps might continue to add more config into an existing type?

eg your example

wiringBuilder.type("Query", builder -> builder.defaultDataFetcher(defaultDataFetcher)) //Sets the default dataFetcher
             .type("Query", builder -> builder.dataFetcher("asset", assetDataFetcher)) //Unsets the default dataFetcher
             .type("Query", builder -> builder.dataFetcher("person", personDataFetcher))

versus

wiringBuilder.type("Query", builder -> builder
    .defaultDataFetcher(defaultDataFetcher)
    .dataFetcher("asset", assetDataFetcher)
    .dataFetcher("person", personDataFetcher)
)

??

I can look into this

@AntoineGRHD
Copy link
Author

Thanks for working on this issue.

Concerning your question, you're absolutely right.
The RuntimeWiring.Builder is used by multiple beans in spring-graphql (through the RuntimeWiringConfigurer), each bean call type(). I wanted to convey that idea in my example.
I wouldn't do repeated calls to type() in the same method

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
keep-open Tells Stale Bot to keep PRs and issues open
Projects
None yet
Development

No branches or pull requests

4 participants
@bbakerman @dondonz @AntoineGRHD and others