File tree Expand file tree Collapse file tree 1 file changed +23
-0
lines changed
design-documents/graph-ql Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Original file line number Diff line number Diff line change
1
+ # ID Fields in Object Types
2
+
3
+ When a GraphQL Object Type is used to represent an entity that can be referenced by ID, it _ should_ follow these best-practices.
4
+
5
+ ## Best Practices
6
+
7
+ ### Do
8
+
9
+ - Use the ` ID ` scalar type
10
+ - Use the field name ` id ` or ` _id `
11
+ - Most GraphQL client libs automatically use this field for caching. Any other field name will require manual caching logic on the client
12
+ - https://www.apollographql.com/docs/react/caching/cache-configuration/#assigning-unique-identifiers
13
+ - https://formidable.com/open-source/urql/docs/graphcache/normalized-caching/#key-generation
14
+ - Include an ID field anytime an Object Type _ could_ have an ID field
15
+
16
+ ### Do Not
17
+ - Include info in the client-facing description describing how the field is encoded/decoded (should be opaque)
18
+ - Example: The client shouldn't know if an ` ID ` is a base64-encoded integer
19
+ - Use ` String ` or ` Int ` type
20
+
21
+ ## Examples where an ID is not helpful
22
+
23
+ - Wrapper types, like ` SearchResultPageInfo `
You can’t perform that action at this time.
0 commit comments