Skip to content

Commit

Permalink
docs: updated federation guide to include federation-specific graphql… (
Browse files Browse the repository at this point in the history
#3145)

* docs: updated federation guide to incldue federation-specific graphql directives

* docs: clarify directive example

Co-authored-by: Jonathan Ehwald <[email protected]>

* docs: clarify schema example

Co-authored-by: Jonathan Ehwald <[email protected]>

* Remove release file

---------

Co-authored-by: Jonathan Ehwald <[email protected]>
  • Loading branch information
bradleyoesch and DoctorJohn authored Nov 16, 2023
1 parent a6832f2 commit 2aceac1
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions docs/guides/federation.md
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,66 @@ We have provided a full example that you can run and tweak to play with
Strawberry and Federation. The repo is available here:
[https://github.com/strawberry-graphql/federation-demo](https://github.com/strawberry-graphql/federation-demo)

## Federated schema directives

Strawberry provides implementations for [Apollo federation-specific GraphQL directives](https://www.apollographql.com/docs/federation/federated-types/federated-directives/).

Some of these directives may not be necessary to directly include in your code, and are accessed through other means.

- `@interfaceObject` (for more details, see [Extending interfaces](https://strawberry.rocks/docs/federation/entity-interfaces))
- `@key` (for more details, see [Entities (Apollo Federation)](https://strawberry.rocks/docs/federation/entities))
- `@link` (is automatically be added to the schema when any other federated schema directive is used)

Other directives you may need to specifically include when relevant.

- `@composeDirective`
- `@external`
- `@inaccessible`
- `@override`
- `@provides`
- `@requires`
- `@shareable`
- `@tag`

For example, adding the following directives:

```python
import strawberry
from strawberry.federation.schema_directives import Inaccessible, Shareable, Tag


@strawberry.type(directives=[Key(fields="id"), Tag(name="experimental")])
class Book:
id: strawberry.ID


@strawberry.type(directives=[Shareable()])
class CommonType:
foo: str
woops: bool = strawberry.field(directives=[Inaccessible()])
```

Will result in the following GraphQL schema:

```graphql
schema
@link(
url: "https://specs.apollo.dev/federation/v2.3"
import: ["@key", "@inaccessible", "@shareable", "@tag"]
) {
query: Query
mutation: Mutation
}

type Book @tag(name: "experimental") @key(fields: "id", resolveable: true) {
id: ID!
}

type CommonType @shareable {
foo: String!
}
```

## Additional resources

[Apollo Federation Quickstart](https://www.apollographql.com/docs/federation/quickstart/setup/)

0 comments on commit 2aceac1

Please sign in to comment.