The ID scalar type represents a unique identifier, often used to refetch an object or as key for a cache. The ID type appears in a JSON response as a String; however, it is not intended to be human-readable. When expected as an input type, any string (such as "4") or integer (such as 4) input value will be accepted as an ID.
Any simple examples?
It just seemed a bit too general to be useful…
Perhaps an IntegerId or StringId type would be better defaults…
Good question! The purpose of it being this general is that as far as the client is concerned it’s supposed to be opaque. Whether on the server its an integer, or a string, or something like "user:123" that is a combo of a type and an integer, it doesn’t matter.
When you’re serializing to JSON there are very, very few options as far as final formats, because JSON is super simple. It’s worth not conflating the GraphQL type with the serialization format. An ID isn’t a string, even if it’s serialized as one. It communicates different meaning, and should be treated differently.