Reputation: 33421
I am building a relay compliant GraphQL server where some types will only ever have 1 of each in existence.
A few examples:
Getting the version number of the application:
query version {
version {
version,
buildDate,
builtBy
}
}
Getting the current resource usage (for simplicity, the server only sends the readings measured at the time of the request):
query usage {
resource {
memory{
total,
used
},
cpu{
total,
used
}
}
}
In all the above examples, only 1 of version
, resource
, memory
and cpu
can exist.
The relay object identification spec says that all objects should have an identity. However, in this case, the existence of an id
seems quite superfluous.
Do all objects within a relay-compliant GraphQL server absolutely need an id?
Upvotes: 1
Views: 419
Reputation: 7996
From experience with sangria, no. However, relay will emit an error message if you perform a mutation on an object without an ID because it will be unable to query for changes on just that single object.
Note that the ID is an opaque string given to the client. The simplest way of remaining compliant in your case would probably be to just base64 encode the type of value, e.g. id = base64_encode('version')
, etc.
Upvotes: 1