How to "require" / rely upon nullable fields when extending an entity

While extending the following entity with a nullable field title:

type Product @key(fields:"id language") {
    id: ID!
    language: String!
    title: String
}

with this one in another subgraph:

type Product @key(fields: "id language") @extends {
  id: ID! @external
  language: String! @external
  title: String @external
  url(region: String!): String @requires(fields: "title")
}

everything works just fine when querying products that have a non-empty title. However, when we query products that do have an empty title Apollo returns the following error:

"message": "Field \"title\" was not found in response."

in which case the resolver for the url query is never reached. What we like to achieve, however, is that in this case the resolver is actually called with an empty title field, so we can implement logic that deals with an empty title. The @requires annotation does not seem to fit our use case.

What is the correct way of extending this product entity in such a way that both null and non-null titles are passed on to the resolver that’s responsible for producing the result of the url query?

I’m actually beginning to wonder if this is behaviour is actually desired… because I would expect two options:

  • it just works with null values (in this case when the title == null)
  • this graph spec is not accepted because we require a nullable field.

Should I create a bug for that?

I am still interested in knowing the correct way of extending this product entity s.t. both null and non-null titles are passed on to the resolver that’s responsible for producing the result of the url query…