3
3
** Proposed by:** [ Mark Larah] ( https://twitter.com/mark_larah ) - Yelp
4
4
5
5
This RFC proposes formalizing "Schema Coordinates" - a human readable syntax to
6
- uniquely identify a type, field, field argument, enum value, directive or directive argument defined in a GraphQL Schema.
6
+ uniquely identify a type, field, field argument, enum value, directive or
7
+ directive argument defined in a GraphQL Schema.
7
8
8
9
This should be listed as a non-normative note in the GraphQL specification to
9
10
serve as an official reference for use by third party tooling.
10
11
11
12
## 📜 Problem Statement
12
13
13
- GraphQL tooling and libraries may wish to refer to the various components of a GraphQL schema. Use cases include documentation, metrics and logging
14
- libraries.
14
+ GraphQL tooling and libraries may wish to refer to various components of a
15
+ GraphQL schema. Use cases include documentation, metrics and logging libraries.
15
16
16
17
![ ] ( https://i.fluffy.cc/5Cz9cpwLVsH1FsSF9VPVLwXvwrGpNh7q.png )
17
18
@@ -27,7 +28,10 @@ specification or name for this convention.
27
28
requested** . This may be implemented by incrementing a counter by the name of
28
29
the schema coordinate for each field executed in a request.
29
30
30
- _ Existing implementations: Yelp (internal), Facebook (internal)_
31
+ _ Existing implementations: Yelp (internal), Facebook (internal),
32
+ [ Shopify (API health report)] [ shopify-api-health ] _
33
+
34
+ [ shopify-api-health ] : https://shopify.dev/concepts/about-apis/versioning/api-health
31
35
32
36
1 . GraphiQL and other playgrounds / documentation sites want to show a list of
33
37
** search results** when a user searches for a type or field name. We can
@@ -65,23 +69,43 @@ specification or name for this convention.
65
69
66
70
_ Existing implementations: Apollo Studio (see "Prior Art")_
67
71
68
- ## 🚫 What this RFC does _ not_ propose
72
+ ## 🥅 RFC Goals
73
+
74
+ - There be one, unambiguous way to write a "schema coordinate" that refers to a
75
+ particular element in a GraphQL schema. (This is to avoid users having to
76
+ "simplify" more complex coordinates to produce a canonical representation.)
77
+ - Schema coordinate syntax should build off of existing de-facto standards
78
+ already adopted for this purpose (i.e. ` Foo.bar ` )
79
+ - Schema coordinate syntax is open for extension in the future. We should make
80
+ design choices that give us flexibility and anticipate future syntax needs
81
+ (based off of discussions around this RFC).
82
+
83
+ ## 🚫 RFC Non-goals
69
84
70
85
- This does not cover "selectors" or "wildcard" syntax - e.g. ` User.* ` . _ (See
71
86
alternatives considered.)_
72
87
- There are ** no proposed GraphQL language/syntax changes**
73
88
- There are ** no proposed GraphQL runtime changes**
74
89
- [ Schema coordinate non-goals] ( #-syntax-non-goals )
75
90
76
- ## Proposed syntax
91
+ ## 🧑💻 Proposed syntax
77
92
78
93
### ` Type `
79
94
80
- Refers to a named type (e.g. something represented by ` __Type ` in GraphQL introspection).
95
+ Refers to a named type (e.g. something represented by ` __typename ` in a GraphQL
96
+ introspection call).
81
97
82
98
### ` Type.attribute `
83
99
84
- Refers to a named attribute on the named type. Not all types support this. For object types and interface types this is a field, for input objects this would be an input field, for enums this would be an enum value, for future GraphQL types this will relate to a related concept if they have one (e.g. for the [ proposed "tagged" type] ( https://github.com/graphql/graphql-spec/pull/733 ) it would refer to the "member field").
100
+ Refers to a named attribute on the named type.
101
+
102
+ Not all types support this. For object types and interface types this is a field,
103
+ for input objects this would be an input field, for enums this would be an enum
104
+ value, for future GraphQL types this will relate to a related concept if they
105
+ have one (e.g. for the [ proposed "tagged" type] [ tagged-typed ] it would refer to
106
+ the "member field").
107
+
108
+ [ tagged-type ] : https://github.com/graphql/graphql-spec/pull/733
85
109
86
110
### ` Type.field(argName:) `
87
111
@@ -95,7 +119,7 @@ References the given named directive
95
119
96
120
References the named argument of the named directive.
97
121
98
- ## ✨ Worked Examples
122
+ ### ✨ Examples
99
123
100
124
For example, consider the following schema:
101
125
@@ -194,11 +218,12 @@ From the query above, we may calculate the following list of schema coordinates:
194
218
- ` Business.owner `
195
219
- ` Person.name `
196
220
197
- _ ` Query.searchBusinesses(name:) ` is also a valid member of the output set. The
221
+ ` Query.searchBusinesses(name:) ` is also a valid member of the output set. The
198
222
serialization algorithm may optionally choose to output all permutations of field
199
- arguments used, should this be specified._
223
+ arguments used, should this be specified.
200
224
201
- A library has been written to demonstrate this mapping: https://github.com/sharkcore/extract-schema-coordinates .
225
+ A library has been written to demonstrate this mapping:
226
+ < https://github.com/sharkcore/extract-schema-coordinates > .
202
227
203
228
## 🗳️ Alternatives considered
204
229
@@ -290,7 +315,7 @@ This syntax consciously does not cover the following use cases:
290
315
Those familiar with ` document.querySelector ` may be expecting the ability to
291
316
pass "wildcards" or "star syntax" to be able to select multiple schema
292
317
elements. This implies multiple ways of _ selecting_ a schema node.
293
-
318
+
294
319
For example, ` User.address ` and ` User.a* ` might both resolve to ` User.address ` .
295
320
But ` User.a* ` could also ambiguously refer to ` User.age ` .
296
321
@@ -304,10 +329,40 @@ This syntax consciously does not cover the following use cases:
304
329
A more general purpose schema selector language could be built on top of this
305
330
spec - however, we'll consider this ** out of scope** for now.
306
331
332
+ - ** Nested field paths**
333
+
334
+ This spec does _ not_ support selecting schema members with a path from a root
335
+ type (e.g. ` Query ` ).
336
+
337
+ For example, given this schema
338
+
339
+ ``` graphql
340
+ type User {
341
+ name : String
342
+ bestFriend : User
343
+ }
344
+
345
+ type Query {
346
+ userById (id : String ): User
347
+ }
348
+ ```
349
+
350
+ The following are invalid schema coordinates:
351
+
352
+ - `Query.userById.name`
353
+ - `User.bestFriend.bestFriend.bestFriend.name`
354
+
355
+ This violates a non-goal that there be one, unambiguous way to write a
356
+ schema coordinate to refer to a schema member. Both examples can be
357
+ "simplified" to `User.name`, which _is_ a valid schema coordinate.
358
+
359
+ Should a use case for this arise in the future, a follow up RFC may investigate
360
+ how schema coordinates could work with "field paths" (e.g. `["query" , "searchBusinesses" , 1, "owner" , "name" ]`) to cover this.
361
+
307
362
- **Directive applications**
308
363
309
- This spec does not support selecting applications of directive.
310
-
364
+ This spec does _not_ support selecting applications of directive.
365
+
311
366
For example:
312
367
313
368
```graphql
@@ -355,15 +410,17 @@ This syntax consciously does not cover the following use cases:
355
410
356
411
You may select the `Meal ` definition (as "`Meal`" ), but you may **not ** select
357
412
members on `Meal ` (e.g. `Meal.Breakfast` or `Meal.Lunch`).
358
-
413
+
359
414
It is unclear what the use case for this would be , so we won 't (yet?) support
360
415
this . In such cases , consumers may select type members directly (e.g. `Lunch`).
361
416
362
417
## 🤔 Drawbacks / Open questions
363
418
364
- - https ://github .com /graphql /graphql -spec /issues /735 discusses potential
365
- conflicts with the upcoming namespaces proposal - would like to seek clarity on
366
- this
419
+ - Should arguments look like `Foo .bar .baz ` instead of `Foo .bar (baz :)`?
420
+
421
+ - See https ://github .com /graphql /graphql -spec /pull /746#discussion_r526365127
422
+ for discussion about this .
423
+ - TODO : Discuss next WG meeting and remove this note .
367
424
368
425
- Should we specify an algorithm for doing the query -> set of schema
369
426
coordinates? Or just hint/imply that this mapping theoretically exists? Is this
0 commit comments