Skip to content

Bind zero-length nested input argument to a zero-length List instead of null #301

Closed
@patrikbjork

Description

@patrikbjork

When sending a mutation with a zero-length collection as a nested field, shouldn't it be extracted as a zero-length list instead of null?

I tried adding a test to org.springframework.graphql.data.method.annotation.support.GraphQlArgumentInitializerTests. It fails since "items" is extracted as null.

@Test
void shouldInstantiateEmptyNestedBeanLists() throws Exception {
	String payload = "{\"nestedList\": { \"items\": [ ] } }";
	DataFetchingEnvironment environment = initEnvironment(payload);
	Object result = initializer.initializeArgument(
			environment, "nestedList", ResolvableType.forClass(NestedList.class));

	assertThat(result).isNotNull().isInstanceOf(NestedList.class);
	assertThat(((NestedList) result).getItems()).hasSize(0);
}

Is this correct behavior or should it be improved?

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions