Skip to content

Commit 1933eb1

Browse files
committed
Extend the non-spec section of the node interface, and link it to caching
1 parent 45c9582 commit 1933eb1

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed

site/learn/BestPractice-Caching.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ One possible pattern for this is reserving a field, like `id`, to be a globally
3333

3434
This is a powerful tool to hand to client developers. In the same way that the URLs of a resource-based API provided a globally unique key, the `id` field in this system provides a globally unique key.
3535

36-
If the backend uses something like UUIDs for identifiers, then exposing this globally unique ID may be very straightforward! If the backend doesn't have a globally unique ID for every object already, the GraphQL layer might have to construct this. Oftentimes, that's as simple as appending the name of the type to the ID and using that as the identifier; the server might then make that ID opaque by base64-encoding it.
36+
If the backend uses something like UUIDs for identifiers, then exposing this globally unique ID may be very straightforward! If the backend doesn't have a globally unique ID for every object already, the GraphQL layer might have to construct this. Oftentimes, that's as simple as appending the name of the type to the ID and using that as the identifier; the server might then make that ID opaque by base64-encoding it.
37+
38+
Optionally, this ID can then be used to work with the [Global Object Identification](learn/global-object-identification/)'s `node` pattern.
3739

3840
## Compatibility with existing APIs
3941

site/learn/BestPractice-NodeInterface.md

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ request an object by ID. Then, in the response, the schema will need to provide
1717
standard way of providing these IDs.
1818

1919
Because little is known about the object other than its ID, we call these
20-
objects "nodes." An example of a query for a node is the following query:
20+
objects "nodes." Here is an example query for a node:
2121

2222
```graphql
2323
{
@@ -29,9 +29,30 @@ objects "nodes." An example of a query for a node is the following query:
2929
}
3030
```
3131

32-
- This API allows refetching the object via the `node` field on the root query object.
33-
- The ID to be used for refetching is provided in an `id` field on the result.
34-
- By using an [Interface](/learn/schema/#interfaces) for the node you can extract out underlying type and data
32+
- The GraphQL schema is formatted to allow fetching any object via the `node` field on the root query object. This
33+
returns objects which conform to a "Node" [interface](/learn/schema/#interfaces).
34+
- The `id` field can be extracted out of the response safely, and can be stored for re-use via caching and refetching.
35+
- Clients can use interface fragments to extract additional information specific to the type which conform to the node interface. In this case a "User".
36+
37+
The Node interface looks like:
38+
39+
```graphql
40+
# An object with a Globally Unique ID
41+
interface Node {
42+
# The ID of the object.
43+
id: ID!
44+
}
45+
```
46+
47+
With a User conforming via:
48+
49+
```graphql
50+
type User implements Node {
51+
id: ID!
52+
# Full name
53+
name: String!
54+
}
55+
```
3556

3657
# Specification
3758

0 commit comments

Comments
 (0)