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

bug: Optional null fields are not returned #1936

Closed
AlexanderPruss opened this issue Jun 11, 2024 · 5 comments
Closed

bug: Optional null fields are not returned #1936

AlexanderPruss opened this issue Jun 11, 2024 · 5 comments
Labels
bug Something isn't working

Comments

@AlexanderPruss
Copy link

AlexanderPruss commented Jun 11, 2024

EDIT: Turns out to be a spring configuration error, other dependencies were reconfiguring the jackson object mapper. See the resolution below.

Observed in DGS 8.7.1 - null return values are not being returned.

Expected behavior

Given the following schema

type Query {
  fetchFoo : Foo!
}

type Foo {
    required: String!
    nullable: String
}

and a query asking for both fields

query GiveMeAllMyFieldsPlease {
    fetchFoo {
        required
        optional
    }
}

and a server that contains a Foo object with required := "required", optional := null,

then the DGS query should return with

{
  "data": {
    "fetchFoo": {
       "required" : "required",
       "optional" : null
    }
  }
}

Actual behavior

The optional field is not returned; the response ends up being

{
  "data": {
    "fetchFoo": {
       "required" : "required",
    }
  }
}

This runs counter to the graphQL spec - https://spec.graphql.org/draft/#sec-Value-Completion - and breaks some client integrations, such as the one from Apollo.

Steps to reproduce

Start a DGS server with the above schema, execute the query against it. Or more generally, just query an optional type that ends up being null.

@AlexanderPruss AlexanderPruss added the bug Something isn't working label Jun 11, 2024
@AlexanderPruss
Copy link
Author

AlexanderPruss commented Jun 11, 2024

Could this be a configuration error? Is there a way I can poke at the serializer inside of DGS?

@srinivasankavitha
Copy link
Contributor

srinivasankavitha commented Jun 12, 2024

I don't seem to be able to reproduce this behavior. I do see the null fields if they are optional and requested for in the query.

query {
 movies {
    title
    director
   }
}

where director is a. nullable field:

{
  "data": {
    "movies": [
      {
        "title": "Crouching Tiger",
        "director": null
      },
      {
        "title": "Black hawk down",
        "director": null
      },
      {
        "title": "American Horror Story",
        "director": "Scary movie director"
      },
      {
        "title": "Love Death + Robots",
        "director": "Scary movie director"
      }
    ]
  }
}

@srinivasankavitha
Copy link
Contributor

Separately, are you using the new spring-graphql integration: https://netflix.github.io/dgs/spring-graphql-integration/? If not switching to that would be good as well.

@AlexanderPruss
Copy link
Author

Sounds like a configuration problem then. I'll update if I can fix it locally, maybe that can help someone else

@AlexanderPruss
Copy link
Author

Fixed it locally, so closing this ticket.

DGS uses Jackson; the Custom Object Mapper DGS Documentation suggests that this can customized by adding a Jackson2ObjectMapperBuilder to the Spring Context. This doesn't prevent other autowired configurations from then further customizing the object mapper, however; this is what was happening in our case. Spring magic doing spring magic things.

If you run into this, try and hunt down where the ObjectMapper is being reconfigured. In our case, it was simpler to explicitly create a not a Jackson2ObjectMapperBuilder bean, as the docs suggest, but rather the MappingJackson2HttpMessageConverter itself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants