question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

MapToListTypeAdapter nullability

See original GitHub issue

(Using the default MapToListTypeAdapter)

Output types

If I have an object annotated like:

@GraphQLNonNull
@GraphQLQuery(name = "field")
public Map<@GraphQLNonNull String, @GraphQLNonNull String>getField() {
  return null;
}

In the schema I get the field field [mapEntry_String_String]!

The type mapEntry_String_String picks the non-nulls up fine for its fields, but I would expect the field to be of type field [mapEntry_String_String!]! as it doesn’t make sense to have a null map entry in the list.

Input types

If I have a field annotated like:

@GraphQLNonNull
@GraphQLInputField(name = "field")
private Map<@GraphQLNonNull String, @GraphQLNonNull String> field;

Then in the schema I get the field field [mapEntry_String_String_input!] I would expect it to be field [mapEntry_String_String_input!]! as it’s annotated to be non-null. The object mapEntry_String_String_input picks up the annotations fine for its own fields. Is there something I’m missing a way to mark these non-null myself? Seems like a bug to me.

summary

  • For output types it applies the @GraphQLNonNull annotation correctly, but should change to make the generated mapEntry object always non-null.
  • For input types is applies the @GraphQLNonNull annotation to the generated mapEntry object instead of to the list itself, and should have the mapEntry object be always non-null.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
kaqqaocommented, Aug 19, 2018

Ah, this is an exceptional case indeed, because it is Jackson that looks at private fields and not SPQR, but Jackson is configured to respect @GraphQLInputField annotations, so it seems surprising.

I opened a separate issue #160 about annotation on private fields, so track that one for progress.

1reaction
kaqqaocommented, Aug 9, 2018

I made the entries non-nullable, so that change will land in 0.9.8. The transparent treatment of private fields is in popular demand, so I’m starting the work on it. But I don’t want to delay the 0.9.8 release any further, so this will land in 0.9.9.

In the meantime, I’ll try replicating your setup, but if you have the time a simple test demonstrating the behavior you’re seeing would be helpful.

Cheers!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Take annotations on private fields into account (also enables ...
SPQR never looks at private elements, so annotating a private field will not work (with the exception of @GraphQLInputField with Jackson, ...
Read more >
graphql.schema.GraphQLNonNull.<init> java code examples ...
A factory method for creating non null types so that when used with static imports allows * more readable code such as *...
Read more >
Nullability - GraphQL Nexus
This is the effect where, within a schema runtime, a null or error received from some data ... Nexus defaults to both inputs...
Read more >
Get the detected generic type inside Jackson's JsonDeserializer
... beanProperty) throws JsonMappingException { //beanProperty is null when the type to deserialize is the top-level type or a generic type, ...
Read more >
io.leangen.graphql.annotations.GraphQLNonNull Java Exaples
withTypeAdapters(new MapToListTypeAdapter()) . ... findById(id); if (toDo != null) { toDoRepository.deleteById(id); return true; } else { return false; } }.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found