Skip to content

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

@andimarek

Description

@andimarek

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?

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions