Global IDs
Viaduct uses two different Kotlin types to represent GraphQL ID
types: GlobalID<T>
and String. GlobalID
is an object that consists of a type and an internal ID. They are used to uniquely identify node objects in the graph. GlobalID
values support structural equality, as opposed to referential equality.
There are two conditions under which GlobalID<T>
will be used:
- The
id
field of aNode
object type - A field of type
ID
with the@idOf(type:"T")
directive, whereT
must be a GraphQL object or interface type that implementsNode
Elsewhere in the Kotlin code, String will be used for IDs.
For the examples below, id
, id3
and f2
are GlobalIDs and while id2
and f1
are Strings.
type MyNode implements Node {
id: ID!
id2: ID!
id3: ID! @idOf(type: "MyNode")
}
input Input {
f1: ID!
f2: ID! @idOf(type: "MyNode")
}
If a Node object type implements an interface, and that interface has an id field, then that interface must also implement Node.
Instances of GlobalID
can be created using the Context
objects provided to resolvers, e.g., ctx.globalIDFor(User.Reflection, "123")
.
Feedback
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.