The ID Scalar Type in Absinthe

What’s the intended usage of ID in Absinthe?

I see this.

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…

Just a guess …

http://graphql.org/learn/schema/#scalar-types

1 Like

It is not related to Absinthe, but to GraphQL

It is the unique id used to fetch a node, which might be different from the object internal id

eg : user id:1 might be node id:‘myuniqueid’

Here You may find docs about node interface

https://facebook.github.io/relay/docs/en/graphql-object-identification.html

BTW It is highly used client side to indicate the current cursor position, internally, so You may ask give me last 10 after ‘myuniqueid’

1 Like

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.

3 Likes