Reputation: 1905
https://graphql.org/learn/schema/#scalar-types
I have read the description
ID
: The ID scalar type represents a unique identifier, often used to refetch an object or as the key for a cache. The ID type is serialized in the same way as a String; however, defining it as anID
signifies that it is not intended to be human‐readable.
But in practice, what actually changes if I use ID
instead of String
?
Upvotes: 10
Views: 6568
Reputation: 4627
Nothing changes as it is mentioned in the description. ID
is serialized exactly the same as String
type; therefore, if you were to replace ID
with String
, computer would see no difference in it.
However, what is important to you is that YOU as a programmer know for sure that it's a unique identifier which will be useful when you paginate records, modify apollo cache, iteratively create jsx components.
So in practice, it has a very practical implication - it conveys important meaning for the programmer that the field is unique for the type.
Upvotes: 11