Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce Core Source Schema Directives #30

Merged
merged 50 commits into from
Oct 24, 2024
Merged
Changes from 6 commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
14badaf
Introduce Lookup Directive.
michaelstaib Apr 11, 2024
f54f24a
Added more examples
michaelstaib Apr 11, 2024
dc499eb
edits
michaelstaib Apr 11, 2024
5c9d4a1
edits
michaelstaib Apr 11, 2024
9cef444
edits
michaelstaib Apr 11, 2024
8771136
edits
michaelstaib Apr 11, 2024
2798146
edits
michaelstaib Apr 11, 2024
a75d22a
edits
michaelstaib Apr 11, 2024
5766888
format
michaelstaib Apr 11, 2024
a5d8a5e
Remove extend keyword to make examples less confusing.
michaelstaib May 2, 2024
025718a
Reworked lookup proposal.
michaelstaib May 23, 2024
cbd4a36
Added patch
michaelstaib May 23, 2024
e51f92a
Reworked require
michaelstaib May 23, 2024
07daa8b
Reverted changes
michaelstaib Jun 6, 2024
039f588
Reworked require
michaelstaib Jun 6, 2024
5c0fd5c
Removed Schema Coordinate
michaelstaib Jun 6, 2024
b9b6aa2
Format
michaelstaib Jun 6, 2024
628592c
Added Patch
michaelstaib Jun 6, 2024
864b1fa
Removed Patch
michaelstaib Jun 6, 2024
b5266d4
Reworked Example
michaelstaib Jun 13, 2024
91048bc
Update spec/Section 2 -- Source Schema.md
michaelstaib Jun 17, 2024
5e9a84c
edits
michaelstaib Jun 20, 2024
42572df
wip
michaelstaib Jun 27, 2024
f7052eb
wip
michaelstaib Jun 27, 2024
80b7d89
wip
michaelstaib Jun 27, 2024
dcb9825
wip
michaelstaib Jun 27, 2024
e81aa9a
wip
michaelstaib Jun 27, 2024
772a852
more updates
michaelstaib Jul 11, 2024
860e627
more updates
michaelstaib Jul 11, 2024
674fdc3
more updates
michaelstaib Jul 11, 2024
22c2858
more updates
michaelstaib Jul 11, 2024
3b74f17
Edits
michaelstaib Jul 25, 2024
0c1b4ac
edits
michaelstaib Jul 25, 2024
031bebf
edits
michaelstaib Jul 25, 2024
2218ed0
Update spec/Section 2 -- Source Schema.md
michaelstaib Aug 1, 2024
38647c3
Update spec/Section 2 -- Source Schema.md
michaelstaib Aug 1, 2024
17506c5
Update spec/Section 2 -- Source Schema.md
michaelstaib Aug 1, 2024
f38c4e2
Update spec/Section 2 -- Source Schema.md
michaelstaib Aug 1, 2024
f5e5e55
Update spec/Section 2 -- Source Schema.md
michaelstaib Aug 1, 2024
ed4e2ce
Update spec/Section 2 -- Source Schema.md
michaelstaib Aug 1, 2024
bd2d2ef
Update spec/Section 2 -- Source Schema.md
michaelstaib Aug 1, 2024
c45f7eb
wip
michaelstaib Aug 1, 2024
c0fac34
edits
michaelstaib Sep 26, 2024
1b34ada
edits
michaelstaib Sep 26, 2024
09dd376
Merge branch 'main' into mst/lookup
michaelstaib Oct 3, 2024
ab341bf
more
michaelstaib Oct 24, 2024
70c48a1
format
michaelstaib Oct 24, 2024
3281a2b
spelling
michaelstaib Oct 24, 2024
c112736
spelling
michaelstaib Oct 24, 2024
042c12b
spelling
michaelstaib Oct 24, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 31 additions & 17 deletions spec/Section 2 -- Source Schema.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,61 +2,75 @@

## Directives

### @entityResolver
### @lookup

The `@lookup` directive is applied to object fields to enable the resolution of entities from a _source schema_ by a stable key. This directive marks a field as capable of performing a lookup operation.

```graphql
directive @entityResolver on FIELD_DEFINITION
directive @lookup on FIELD_DEFINITION
```

Entity resolvers are fields on the query root type of a subgraph that can
resolve an entity by a stable key. The stable key is defined by the arguments of
the field.
Lookup fields allow the composite schema to resolve entities from a source schema by a stable key. The stable key is defined by the arguments of the field. Only fields that are annotated with the `@lookup` directive will be recognized as lookup field.

```graphql example
extend type Query {
version: Int # NOT an entity resolver.
personById(id: ID!): Person @entityResolver
personById(id: ID!): Person @lookup
michaelstaib marked this conversation as resolved.
Show resolved Hide resolved
michaelstaib marked this conversation as resolved.
Show resolved Hide resolved
}

extend type Person {
id: ID! # matches the argument of personById
extend type Person @key(fields "id") {
id: ID!
}
```

The arguments of an entity resolver field must match fields of the returning
type.
The arguments of a lookup field must correspond to the fields specified by a `@key` directive annotated on the type returned by the lookup field.

```graphql example
extend type Query {
node(id: ID!): Node @entityResolver
node(id: ID!): Node @lookup
}

interface Node {
interface Node @key(fields "id") {
michaelstaib marked this conversation as resolved.
Show resolved Hide resolved
id: ID!
}
```

When an entity resolver returns an interface all implementing types are inferred
as entities.
Lookup fields returning an interface or union type can be used as lookup field for all possible object types.

```graphql example
extend type Query {
entityById(id: ID!, categoryId: Int): Entity @entityResolver
entityById(id: ID!, categoryId: Int): Entity @lookup
michaelstaib marked this conversation as resolved.
Show resolved Hide resolved
}

union Entity = Cat | Dog

extend type Dog {
extend type Dog @key(fields "id") {
id: ID!
categoryId: Int
}

extend type Cat {
extend type Cat @key(fields "id") {
id: ID!
categoryId: Int
}
```

Lookup fields must be accessible from the Query type. If not directly on the Query type, they should be accessible via fields that do not require arguments, starting from the Query type.

```graphql example
extend type Query {
lookups: Lookups!
}

type Lookups {
personById(id: ID!): Person @lookup
}

extend type Person @key(fields "id") {
id: ID!
}
```

### @is

```graphql
Expand Down
Loading