What is the correct graphql response if a requested child object does not exist?

What is the correct graphql response if a requested child object does not exist?


0

What shall the graphql server return if a child object does not exist?

Example schema:

type Person {
  name: String!
  address: Address
}

type Address {
  street: String
  city: String
}

On the server, there is a Person, but no Address exist on that person.
The fact that the address is missing is not an error, it is just not yet set.

Then I have this query:

query Person(name: "Otto") {
    name
    address {
        street
        city
    }
}

What is the correct response?
I can think of two alternatives:

Alt 1:

{
    "data": {
        "person": {
            "name": "Otto",
            "address": null
            "__typename": "Person"
        }
    }
}

Alt 2:

{
    "data": {
        "person": {
            "name": "Otto",
            "address": {
                "street": null,
                "city": null
                "__typename": "Address"
            }
            "__typename": "Person"
        }
    }
}


Load 6 more related questions


Show fewer related questions

0



Leave a Reply

Your email address will not be published. Required fields are marked *