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
?
Scalars are “leaf” values in GraphQL. There are several built-in scalars, and you can define custom scalars, too. (Enums are also leaf values.) The built-in scalars are: String , like a JSON or Ruby string.
Require id field for all GraphQL entities in all queries and mutations.
The __typename field returns the object type's name as a String (e.g., Book or Author ). GraphQL clients use an object's __typename for many purposes, such as to determine which type was returned by a field that can return multiple types (i.e., a union or interface).
GraphQL works by sending operations to an endpoint. There are three types of operations: queries, mutations, and subscriptions. A query is sent through an HTTP POST call to retrieve data. A mutation is also sent through a HTTP POST and is used to modify data.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With