Skip to content

Replace argument type with @Source to determine source/parent #322

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

Conversation

dugenkui03
Copy link
Contributor

@dugenkui03 dugenkui03 commented Mar 10, 2022

Annotation way will be more precise.

leniency model: argument type

I think argumentType way may lead mismatch. There will be various parameter types when spring-graphql support custom HandlerMethodArgumentResolver.

This way also require strict restriction of code: SourceMethodArgumentResolver must be put after other HandlerMethodArgumentResolver.

strictness model: @Source

Developers will easily know whether argument is source/parent by @Source, they don't have to look at the implementations of HandlerMethodArgumentResolver to determine which one supports the parameter.

And there is no need to take SourceMethodArgumentResolver as fallback.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Mar 10, 2022
@rstoyanchev
Copy link
Contributor

Thanks for the proposal, and I admit there is something appealing about having an @Source annotation that explicitly marks the method parameter, and it's something we did consider.

The pause that I have is that the annotation does not serve any real purpose. We can work it out just fine without it, without any ambiguity that we've come across so far. In terms of developers wondering, well if someone new wants to find out how to get a hold of the parent, the answer is just declare it. I think that's as simple as it gets and you don't need to know more.

From the opposite perspective as well, if we had @Source, it would be legitimate to ask, should it be required and if so why? I don't think there is a good reason to require it, so that leads back again to having some controller methods with it and some without it. This reminds of @ModelAttribute in Spring MVC where you could have it or not, but the point there is that when you do add it, it can serve a purpose. There would be no such case here.

@rstoyanchev
Copy link
Contributor

To address specifically the arguments brought up:

There will be various parameter types when spring-graphql support custom HandlerMethodArgumentResolver.

I don't see how it could lead to a mismatch since custom arguments are before the SourceMethodArgumentResolver.

This way also require strict restriction of code: SourceMethodArgumentResolver must be put after other HandlerMethodArgumentResolver.

This is an internal implementation detail, and there is no reason to expose it.

@dugenkui03
Copy link
Contributor Author

dugenkui03 commented Mar 17, 2022

Thanks for your reply, I respect your final decision. I further explain the reason of this proposal.

about mismatch(match incorrectly)

With @Source, developers can easily avoid mismatching the 'parent/source' in their custom MethodArgumentResolver.

Conversely, if the parent/source and parameter parsed by custom MethodArgumentResolver share many characteristics, parent/source maybe easy to mismatch——That's extreme scene, maybe we can ignore.

about readability of strictness model

Developers will easily know whether argument is source/parent by @Source, they don't have to look at the implementations of HandlerMethodArgumentResolver to determine which one supports the parameter.

Consider the @Controller method:

@SchemaMapping
public X  test(A a, B b, C c){
      // do something and return
}

Maybe developer must read source code about custom HandlerMethodArgumentResolver and the DataFetcher of parent for determining which one is parent/source(and which one will be resolved by custom HandlerMethodArgumentResolver).

All the strategies about resolving parameter in @SchemaMapping are marked with concrete class types(DataFetchingEnvironment,GraphQLContext ,Principal,) or annotation(@Argument,@Arguments), except for source.

@dugenkui03
Copy link
Contributor Author

The same thing occur in @BatchMapping((List<V>)). And developer may want to define list-type-argument on batch method, the code below will have problem, that's another issue discussed in #324.

@rstoyanchev
Copy link
Contributor

Thanks for elaborating. For now, I'm closing this but we can always reconsider when it becomes an actual issue.

@rstoyanchev rstoyanchev added status: declined A suggestion or change that we don't feel we should currently apply and removed status: waiting-for-triage An issue we've not yet triaged labels Mar 17, 2022
rstoyanchev added a commit that referenced this pull request Mar 21, 2022
rstoyanchev added a commit that referenced this pull request Mar 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: declined A suggestion or change that we don't feel we should currently apply
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants