Skip to content

Commit

Permalink
Update overview for fed2 (#1741)
Browse files Browse the repository at this point in the history
The overview example was still in limbo between federation 1 & 2. This updates the Users schema to add `@shareable` to `User.username` and updates the corresponding supergraph schema.
  • Loading branch information
benweatherman authored Apr 18, 2022
1 parent 533ba66 commit 585c624
Showing 1 changed file with 39 additions and 26 deletions.
65 changes: 39 additions & 26 deletions docs/source/federated-types/overview.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ type Query {

type User @key(fields: "id") {
id: ID!
username: String!
username: String! @shareable
}

# (Subgraph schemas include
Expand Down Expand Up @@ -111,65 +111,78 @@ Here's the supergraph schema composed with [the subgraph schemas above](#subgrap

```graphql
schema
@core(feature: "https://specs.apollo.dev/core/v0.2"),
@core(feature: "https://specs.apollo.dev/join/v0.1", for: EXECUTION)
@link(url: "https://specs.apollo.dev/link/v1.0")
@link(url: "https://specs.apollo.dev/join/v0.2", for: EXECUTION)
{
query: Query
}

directive @core(feature: String!, as: String, for: core__Purpose) repeatable on SCHEMA

directive @join__field(graph: join__Graph, requires: join__FieldSet, provides: join__FieldSet) on FIELD_DEFINITION
directive @join__field(graph: join__Graph!, requires: join__FieldSet, provides: join__FieldSet, type: String, external: Boolean, override: String, usedOverridden: Boolean) repeatable on FIELD_DEFINITION | INPUT_FIELD_DEFINITION

directive @join__type(graph: join__Graph!, key: join__FieldSet) repeatable on OBJECT | INTERFACE
directive @join__graph(name: String!, url: String!) on ENUM_VALUE

directive @join__owner(graph: join__Graph!) on OBJECT | INTERFACE
directive @join__implements(graph: join__Graph!, interface: String!) repeatable on OBJECT | INTERFACE

directive @join__graph(name: String!, url: String!) on ENUM_VALUE
directive @join__type(graph: join__Graph!, key: join__FieldSet, extension: Boolean! = false, resolvable: Boolean! = true) repeatable on OBJECT | INTERFACE | UNION | ENUM | INPUT_OBJECT | SCALAR

enum core__Purpose {
EXECUTION
SECURITY
}
directive @link(url: String, as: String, for: link__Purpose, import: [link__Import]) repeatable on SCHEMA

scalar join__FieldSet

enum join__Graph {
USERS @join__graph(name: "users" url: "http://localhost:4001")
PRODUCTS @join__graph(name: "products" url: "http://localhost:4002")
REVIEWS @join__graph(name: "reviews" url: "http://localhost:4003")
PRODUCTS @join__graph(name: "products", url: "http://localhost:4003/graphql")
REVIEWS @join__graph(name: "reviews", url: "http://localhost:4002/graphql")
USERS @join__graph(name: "users", url: "http://localhost:4001/graphql")
}

scalar link__Import

enum link__Purpose {
"""
`SECURITY` features provide metadata necessary to securely resolve fields.
"""
SECURITY

"""
`EXECUTION` features provide metadata necessary for operation execution.
"""
EXECUTION
}

type Product
@join__owner(graph: PRODUCTS)
@join__type(graph: PRODUCTS, key: "upc")
@join__type(graph: REVIEWS, key: "upc")
{
upc: String!
name: String! @join__field(graph: PRODUCTS)
price: Int @join__field(graph: PRODUCTS)
reviews: [Review] @join__field(graph: REVIEWS)
upc: String! @join__field(graph: PRODUCTS)
}

type Query {
me: User @join__field(graph: USERS)
type Query
@join__type(graph: PRODUCTS)
@join__type(graph: REVIEWS)
@join__type(graph: USERS)
{
topProducts(first: Int = 5): [Product] @join__field(graph: PRODUCTS)
me: User @join__field(graph: USERS)
}

type Review {
author: User @join__field(graph: REVIEWS, provides: "username")
type Review
@join__type(graph: REVIEWS)
{
body: String
author: User @join__field(graph: REVIEWS, provides: "username")
product: Product
}

type User
@join__owner(graph: USERS)
@join__type(graph: USERS, key: "id")
@join__type(graph: REVIEWS, key: "id")
@join__type(graph: USERS, key: "id")
{
id: ID! @join__field(graph: USERS)
id: ID!
username: String! @join__field(graph: REVIEWS, external: true) @join__field(graph: USERS)
reviews: [Review] @join__field(graph: REVIEWS)
username: String! @join__field(graph: USERS)
}
```

Expand Down

0 comments on commit 585c624

Please sign in to comment.