Skip to content

Commit

Permalink
docs: Update backward-compatibility with @provides info (#2837)
Browse files Browse the repository at this point in the history
Add info about `@provides` backwards compatibility

---------

Co-authored-by: Maria Elisabeth Schreiber <[email protected]>
  • Loading branch information
smyrick and Meschreiber authored Dec 5, 2023
1 parent 9f9d34a commit 71224f4
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions docs/source/federation-2/backward-compatibility.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,54 @@ type ProductDimensions {

This `@requires` directive should _break_ composition because it depends on subfields of `ProductDimensions` that _don't exist_ (`length` and `depth`).

#### Invalid `@provides` directives

A subgraph can annotate an entity field with the [`@provides` directive](/federation/federated-types/federated-directives/#provides) to indicate that the subgraph can resolve entity fields normally marked as `@external` on its own.

<p style="margin-bottom: 0">✅</p>

```graphql title="Subgraph A"
type Product @key(fields: "id") {
id: ID!
info: ProductInfo @external
}

type ProductInfo {
name: String! @external
inStock: Boolean! @external
}

type Query {
outOfStockProducts: [Product!]! @provides(fields: "info { name }")
discontinuedProducts: [Product!]!
}
```

In the above example, Subgraph A can resolve the `Product.info.name` field when accessed through the `outOfStockProducts` query. Any other path to `Product.info.name` results in an additional subgraph call.

Federation 1 _incorrectly_ allows `@provides` usage like the following:

<p style="margin-bottom: 0">❌</p>

```graphql title="Subgraph A"
type Product @key(fields: "id") {
id: ID!
info: ProductInfo @external
}

type ProductInfo {
name: String! @external
inStock: Boolean! @external
}

type Query {
outOfStockProducts: [Product!]! @provides(fields: "info")
discontinuedProducts: [Product!]!
}
```

The above `@provides` directives usage should _break_ composition because it does not specify which subfields of `ProductInfo` it can resolve. This is correctly caught and surfaced as an error in Federation v2 but Federation v1 incorrectly allows this usage.

</ExpansionPanel>


Expand Down

0 comments on commit 71224f4

Please sign in to comment.