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

Support String and Number to be injected as the parent/source #370

Closed
andimarek opened this issue Apr 27, 2022 · 1 comment
Closed

Support String and Number to be injected as the parent/source #370

andimarek opened this issue Apr 27, 2022 · 1 comment
Assignees
Labels
type: enhancement A general enhancement
Milestone

Comments

@andimarek
Copy link
Contributor

This simple example fails at the moment:

type Query {
    pet: Pet
}
type Pet {
    name: String
}
   @QueryMapping
    public String pet() {
       return "123";
    }

    @SchemaMapping(typeName = "Pet", field = "name")
    public String petName(String petId) {
     return "Luna";
    }

The reason seems to be that no HandlerMethodArgumentResolver is applicable to String.
Looking at the source resolver (SourceMethodArgumentResolver)

@Override
	public boolean supportsParameter(MethodParameter parameter) {
		Class<?> type = parameter.getParameterType();
		return (!BeanUtils.isSimpleValueType(type) && !type.isArray() && !Collection.class.isAssignableFrom(type));
	}

simple types and arrays and collections are excluded.
I am wondering why.

This example is not so uncommon: I can return just an id like "123", which is then used to lookup more in the child DataFetchers.

Can we relax that to always fall back to SourceMethodArgumentResolver regardless of type?

@rstoyanchev
Copy link
Contributor

rstoyanchev commented Apr 28, 2022

I think we always imagined that a non-scalar type would map to a "non-simple" Object in order to provide some field values, and hence the defensive exclusions. Now that you mention it, I can see how the parent could be anything as long as all fields are left to child data fetchers.

SourceMethodArgumentResolver is the last one in the order of resolvers. We should be able to relax this a little, perhaps allowing any CharSequence or Number.

@rstoyanchev rstoyanchev added the type: enhancement A general enhancement label Apr 28, 2022
@rstoyanchev rstoyanchev added this to the 1.0.0 milestone Apr 28, 2022
@rstoyanchev rstoyanchev changed the title String not supported as Source argument Support String and Number to be injected as the parent/source Apr 28, 2022
@rstoyanchev rstoyanchev self-assigned this Apr 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

2 participants