Skip to content

ResponseMapFactory #3857 #3894

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

Merged
merged 1 commit into from
May 6, 2025

Conversation

dfa1
Copy link
Contributor

@dfa1 dfa1 commented Apr 5, 2025

Proposal for #3857. I would like to write a unit test too: the idea is to make sure that all nested maps are really built with the customization.

@dfa1 dfa1 changed the title proposal for 3857 proposal for #3857 Apr 5, 2025
@dfa1 dfa1 force-pushed the proposal/3857-custom-map branch 5 times, most recently from 58cdde1 to bf510c2 Compare April 5, 2025 17:45
@andimarek
Copy link
Member

Thanks for the PR @dfa1.

In general we prefer not to open up ExecutionStrategy more or encourage people to derive from it.

Can we instead define an abstract Factory method or so that can be provided via config, similar to ValueUnboxer? thx

@dfa1
Copy link
Contributor Author

dfa1 commented Apr 6, 2025

@andimarek sounds good... I have several concrete classes deriving from ExecutionStrategy (and feels wrong actually, because I'm tapping into the internals).

What could be a good name? MapFactory?

@dfa1 dfa1 force-pushed the proposal/3857-custom-map branch 2 times, most recently from 69c9ee7 to a68fee8 Compare April 6, 2025 08:51
@andimarek
Copy link
Member

@andimarek sounds good... I have several concrete classes deriving from ExecutionStrategy (and feels wrong actually, because I'm tapping into the internals).

What could be a good name? MapFactory?

Let's go with ResponseMapFactory for now.

@dfa1 dfa1 force-pushed the proposal/3857-custom-map branch from a68fee8 to 8f07b72 Compare April 6, 2025 15:33
@dfa1
Copy link
Contributor Author

dfa1 commented Apr 6, 2025

@andimarek done... please have another look and feel free to suggest better javadoc ;)

@dfa1 dfa1 force-pushed the proposal/3857-custom-map branch 3 times, most recently from a5cfbd8 to fca1f2c Compare April 8, 2025 08:04
@dfa1
Copy link
Contributor Author

dfa1 commented Apr 8, 2025

@andimarek @bbakerman I just rebased to fix some conflicts, do you like the current state? do you expect more javadoc?

@dfa1 dfa1 changed the title proposal for #3857 proposal ResponseMapFactory #3857 Apr 13, 2025
@dfa1 dfa1 changed the title proposal ResponseMapFactory #3857 ResponseMapFactory #3857 Apr 13, 2025
*/
ResponseMapFactory DEFAULT = new DefaultResponseMapFactory();

Map<String, Object> create(List<String> fieldNames, List<Object> results);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like this should be generic

    <K,V> Map<K, V> create(List<K> fieldNames, List<V> results);

Also naming matters

The map we give back is insertion ordered. This is important at times

So I think the create method should be createInsertionOrdered(...)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

List<String> fieldNames, List<Object> results

the names here should be generic

List<String> keys, List<Object> values

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

at some time in the future we might be using this to make more "maps" in different places say

Copy link
Contributor Author

@dfa1 dfa1 Apr 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the feedback! I covered all the points but one: I left out the generics because it is in contrast with a comment from @andimarek.

I do see 2 alternatives:

  • use MapFactory and have the generics
  • use ResponseMapFactory and drop the generics (as they will always K=String and V=Object)

it is acceptance to keep ResponseMapFactory without generics by now?

This will allows to customize which java.util.Map concrete class to use.
For example, eclipse-collections has Map implementations with better
memory footprint than JDK maps.
@dfa1 dfa1 force-pushed the proposal/3857-custom-map branch from fca1f2c to bff9b62 Compare April 14, 2025 07:29
@dfa1
Copy link
Contributor Author

dfa1 commented Apr 28, 2025

@andimarek @bbakerman hi guys, this PR is ready to be reviewed... or do you see something else missing?

@bbakerman
Copy link
Member

I am happy to take this PR in shape HOWEVER I dont think we should wire the MapResponseFactory into the graphql object

This is unsual config - we dont expect people to use this very often.

As such I think we should wire this into play via the new unusualConfiguration() mechanism

#3945

If we had out time again I would do this for ValueUnboxer as well but that is a past decision and this is a present once

So while I support the idea of a MapResponseFactory - it is not usual to expect this to be set and its clutters the API.

Thoughts @andimarek ?

@andimarek
Copy link
Member

I agree with @bbakerman here .. perfect for our very new unusual config area.

second question @dfa1 : does it need to be a function doing so much? could it be a just a constructor/factory function?

@bbakerman
Copy link
Member

@dfa1 - we are likely to merge this PR and then change so that ResponseMapFactory is not set per GraphQL object but rather per execution.

This fits in with our new "unusual configutation" mechanism AND it declutters the public common API

@bbakerman bbakerman added this to the 24.0 milestone May 6, 2025
Copy link
Member

@bbakerman bbakerman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving but we are going to fix this up to the shape we want. This will be set per request not per GraphQL

@bbakerman bbakerman merged commit a272575 into graphql-java:master May 6, 2025
1 check passed
@dfa1 dfa1 deleted the proposal/3857-custom-map branch May 6, 2025 12:53
@dfa1
Copy link
Contributor Author

dfa1 commented May 6, 2025

thanks @bbakerman @andimarek ! 💯

second question @dfa1 : does it need to be a function doing so much? could it be a just a constructor/factory function?

@andimarek : yes, also a factory function is fine

Approving but we are going to fix this up to the shape we want. This will be set per request not per GraphQL

@bbakerman in our projects, all requests will use same ResponseMapFactory...right now I cannot think a usecase to customize this per request rather per instance).

We are using GraphQL.tranform extensively (and it is working nicely, by caching the instances via caffeine) to customize the behavior per request.

... of course, I'm going to our code to use the "unusual configuration" mechanism you're proposing ;)

@dondonz dondonz modified the milestones: 24.0, 25.x breaking changes May 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants