Skip to content

Commit e423af3

Browse files
committed
add notes about Foo.bar.baz vs Foo.bar(baz:)
1 parent 9caf719 commit e423af3

File tree

1 file changed

+76
-19
lines changed

1 file changed

+76
-19
lines changed

rfcs/SchemaCoordinates.md

Lines changed: 76 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,16 @@
33
**Proposed by:** [Mark Larah](https://twitter.com/mark_larah) - Yelp
44

55
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.
78

89
This should be listed as a non-normative note in the GraphQL specification to
910
serve as an official reference for use by third party tooling.
1011

1112
## 📜 Problem Statement
1213

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.
1516

1617
![](https://i.fluffy.cc/5Cz9cpwLVsH1FsSF9VPVLwXvwrGpNh7q.png)
1718

@@ -27,7 +28,10 @@ specification or name for this convention.
2728
requested**. This may be implemented by incrementing a counter by the name of
2829
the schema coordinate for each field executed in a request.
2930

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
3135

3236
1. GraphiQL and other playgrounds / documentation sites want to show a list of
3337
**search results** when a user searches for a type or field name. We can
@@ -65,23 +69,43 @@ specification or name for this convention.
6569

6670
_Existing implementations: Apollo Studio (see "Prior Art")_
6771

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
6984

7085
- This does not cover "selectors" or "wildcard" syntax - e.g. `User.*`. _(See
7186
alternatives considered.)_
7287
- There are **no proposed GraphQL language/syntax changes**
7388
- There are **no proposed GraphQL runtime changes**
7489
- [Schema coordinate non-goals](#-syntax-non-goals)
7590

76-
## Proposed syntax
91+
## 🧑‍💻 Proposed syntax
7792

7893
### `Type`
7994

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).
8197

8298
### `Type.attribute`
8399

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
85109

86110
### `Type.field(argName:)`
87111

@@ -95,7 +119,7 @@ References the given named directive
95119

96120
References the named argument of the named directive.
97121

98-
## ✨ Worked Examples
122+
### Examples
99123

100124
For example, consider the following schema:
101125

@@ -194,11 +218,12 @@ From the query above, we may calculate the following list of schema coordinates:
194218
- `Business.owner`
195219
- `Person.name`
196220

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
198222
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.
200224

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>.
202227

203228
## 🗳️ Alternatives considered
204229

@@ -290,7 +315,7 @@ This syntax consciously does not cover the following use cases:
290315
Those familiar with `document.querySelector` may be expecting the ability to
291316
pass "wildcards" or "star syntax" to be able to select multiple schema
292317
elements. This implies multiple ways of _selecting_ a schema node.
293-
318+
294319
For example, `User.address` and `User.a*` might both resolve to `User.address`.
295320
But `User.a*` could also ambiguously refer to `User.age`.
296321

@@ -304,10 +329,40 @@ This syntax consciously does not cover the following use cases:
304329
A more general purpose schema selector language could be built on top of this
305330
spec - however, we'll consider this **out of scope** for now.
306331

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+
307362
- **Directive applications**
308363

309-
This spec does not support selecting applications of directive.
310-
364+
This spec does _not_ support selecting applications of directive.
365+
311366
For example:
312367

313368
```graphql
@@ -355,15 +410,17 @@ This syntax consciously does not cover the following use cases:
355410

356411
You may select the `Meal` definition (as "`Meal`"), but you may **not** select
357412
members on `Meal` (e.g. `Meal.Breakfast` or `Meal.Lunch`).
358-
413+
359414
It is unclear what the use case for this would be, so we won't (yet?) support
360415
this. In such cases, consumers may select type members directly (e.g. `Lunch`).
361416

362417
## 🤔 Drawbacks / Open questions
363418

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.
367424

368425
- Should we specify an algorithm for doing the query -> set of schema
369426
coordinates? Or just hint/imply that this mapping theoretically exists? Is this

0 commit comments

Comments
 (0)