Skip to content

Global identification #946

@glen-84

Description

@glen-84

As discussed in #232, __id doesn't really make sense if it actually returns the global ID, since double-underscore fields are usually used for type information. But what if it did return type information (the name of the global ID field), and that field was defined using a directive?

The original idea comes from @leebyron and @calebmer here.

Example

Specifying a global identifier field

type Person {
    id: ID! # Entity/local ID.
    myGlobalId: ID! @globalIdField # This could instead be added to a `Node` interface, that `Person` implements.
    name: String
}

Selection

{
    person {
        __globalIdField
        myGlobalId
        id
        name
    }
}
{
    "data": {
        "person": {
            "__globalIdField": "myGlobalId",
            "myGlobalId": "person-123",
            "id": "123",
            "name": "Jane Doe",
        }
    }
}

Introspection

{
    __type(name: "Person") {
      name
      globalIdField
    }
}
{
    "data": {
        "__type": {
            "name": "Person",
            "globalIdField": "myGlobalId"
        }
    }
}

Something like @idField could perhaps also be added for non-global IDs. Built-in directives may need some form of namespacing – not sure if something like @__idField would look good, but there may be other alternatives like @@idField).


Could something like this work?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions