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

Source Schema Chapter #30

Open
wants to merge 45 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
45 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
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
98 changes: 80 additions & 18 deletions spec/Section 2 -- Source Schema.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Source Schema

A _source schema_ is a GraphQL schema that is part of a larger
_composite schema_. Source schemas use directives to express intent and
requirements for the composition process. In the following chapters, we will
describe the directives that are used to annotate a source schema.
A _source schema_ is a GraphQL schema that is part of a larger _composite
schema_. Source schemas use directives to express intent and requirements for
the composition process. In the following chapters, we will describe the
directives that are used to annotate a source schema.

## Directives

Expand All @@ -21,12 +21,11 @@ The stable key is defined by the arguments of the field. Each argument must
match a field on the return type of the lookup field.

Source schemas can provide multiple lookup fields for the same entity that
resolve the entity by sets of keys.
resolve the entity by different keys.

In this example, the source schema specifies that the `Product` entity can be
resolved with the `productById` field or the `productByName` field on the
`Query` type. Both fields can resolve the `Product` entity but do so with
different keys.
resolved with the `productById` field or the `productByName` field. Both lookup
fields are able to resolve the `Product` entity but do so with different keys.

```graphql example
type Query {
michaelstaib marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -42,7 +41,7 @@ type Product @key(fields: "id") @key(fields: "name") {
```

The arguments of a lookup field must correspond to fields specified as an entity
key with the `@key` directive.
key with the `@key` directive on the entity type.

```graphql example
type Query {
Expand All @@ -55,9 +54,9 @@ interface Node @key(fields: "id") {
```

Lookup fields may return object, interface, or union types. In case a lookup
field returns an interface or union type, all possible object types are
considered entities and must have keys that correspond with the fields argument
signature.
field returns an abstract type (interface type or union type), all possible
object types are considered entities and must have keys that correspond with the
fields argument signature.
michaelstaib marked this conversation as resolved.
Show resolved Hide resolved

```graphql example
type Query {
Expand Down Expand Up @@ -113,7 +112,7 @@ type Clothing @key(fields: "id") {
```

If the lookup returns an interface, the interface must also be annotated with a
`@key` directive.
`@key` directive and declare it's keys.
michaelstaib marked this conversation as resolved.
Show resolved Hide resolved

```graphql example
interface Node @key(fields: "id") {
Expand All @@ -139,6 +138,53 @@ type Product @key(fields: "id") {
}
```

Lookups, can also be nested with other lookups and allow resolving nested
michaelstaib marked this conversation as resolved.
Show resolved Hide resolved
entities that are part of an aggregate. In the following example the `Product`
can be resolved by it's id but also the `ProductPrice` can be resolved by
michaelstaib marked this conversation as resolved.
Show resolved Hide resolved
passing in a composite key containing the product id and region name of the
michaelstaib marked this conversation as resolved.
Show resolved Hide resolved
product price.

```graphql example
type Query {
productById(id: ID!): Product @lookup
}

type Product @key(fields: "id") {
id: ID!
price(regionName: String!): ProductPrice @lookup
}

type ProductPrice @key(fields: "regionName product { id }") {
regionName: String!
product: Product
value: Float!
}
```

Nested lookups must imediately follow the parent lookup and cannot be nested
michaelstaib marked this conversation as resolved.
Show resolved Hide resolved
with fields inbetween.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe we agreed that inbetween fields are allowed only if they don't have any arguments


```graphql counter-example
type Query {
productById(id: ID!): Product @lookup
}

type Product @key(fields: "id") {
id: ID!
details: ProductDetails
}

type ProductDetails {
price(regionName: String!): ProductPrice @lookup
}

type ProductPrice @key(fields: "regionName product { id }") {
regionName: String!
product: Product
value: Float!
}
```

### @internal

```graphql
Expand All @@ -161,8 +207,9 @@ type Query {
```

The `@internal` directive provides control over which source schemas are used to
resolve entities and which merely provide data to entities. Additionally it also
allows hiding "technical" lookup fields from the composite schema.
resolve entities and which source schemas merely contribute data to entities.
Further, using `@internal` allows hiding "technical" lookup fields that are not
meant for the client-facing composite schema.

### @is

Expand Down Expand Up @@ -208,16 +255,31 @@ extend type Query {
}
```

The `@is` directive can also be used in combination with oneOf to specify lookup
michaelstaib marked this conversation as resolved.
Show resolved Hide resolved
fields that can resolve entities by different keys.

```graphql example
extend type Query {
person(
by: PersonByInput @is(field: "{ id } | { addressId: address.id } { name }")
): Person
}

input PersonByInput @oneOf {
id: ID
addressId: ID
name: String
}
```

**Arguments:**

- `field`: Represents a selection path map syntax.

### @require

```graphql
directive @require(
field: FieldSelectionMap!
) on ARGUMENT_DEFINITION
directive @require(field: FieldSelectionMap!) on ARGUMENT_DEFINITION
```

The `@require` directive is used to express data requirements with other source
Expand Down
Loading