graphql / graphql/graphql-spec
Global identification
- Dominant language
- JavaScript
- Stars
- 14.6k
- Forks
- 1.2k
- PR merge metrics
- No merged PRs in 30d
Description
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](https://github.com/graphql/graphql-spec/pull/232#issuecomment-262431940).
## Example
### Specifying a global identifier field
```gql
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
```gql
{
person {
__globalIdField
myGlobalId
id
name
}
}
```
```json
{
"data": {
"person": {
"__globalIdField": "myGlobalId",
"myGlobalId": "person-123",
"id": "123",
"name": "Jane Doe",
}
}
}
```
### Introspection
```gql
{
__type(name: "Person") {
name
globalIdField
}
}
```
```json
{
"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?
Contributor guide
Assessment
This issue has not been assessed yet.