Hello! We released a new preview version of connectors with one breaking change and one super useful new feature. Check out the changelog here!
To use the new version:
- Update your supergraph.yaml files to point to
federation_version: =2.10.0-preview.4
- Pass
APOLLO_ROVER_DEV_ROUTER_VERSION=2.0.0-preview.4
torover dev
- Continue using
Federation Next
as the build pipeline version for your variants in GraphOS. You’ll pick up preview.4 on your next publish.
New feature: ->methods
in URLs and headers
Methods for value transformations are a powerful feature of connectors. Previously, they were available only in @connect(selection:)
and @connect(http: {body:})
, but you can now use them in the {dynamic}
segments of URL paths and header values.
type Query {
products(status: Status): [Product]
@connect(
http: {
GET: "http://my.api/products?status={$args.status->match(["AVAILABLE", "in stock"], [@, @])}"
headers: [
{ name: "x-header", value: "{$context.value->slice(0, 100)}" }
]
}
selection: "id status: status->match(["in stock", "AVAILABLE"], [@, @])"
)
}
Breaking change when using @key
directives
The breaking change clarifies the relationship between @key
directives and @connect(entity: true)
. When you add a @key
directive to a type, you’re declaring that you can resolve instances of that type when given the keys fields. In a subgraph, you would implement that with something like __resolveReference()
in Apollo Server.
When using Apollo Connectors, adding entity: true
to certain connectors is the basically the same as defining __resolveReference()
. So if you don’t have an entity: true
connector, we now tell you that you’ve defined a @key
but have not defined a resolver for that key. The error message looks like:
MISSING_ENTITY_CONNECTOR: [storefront] Entity resolution for
`@key(fields: "id")` on `Product` is not implemented by a connector.
See https://go.apollo.dev/connectors/directives/#rules-for-entity-true
The most common remediation is to add resolvable: false
to your @key
, which marks the type as an entity, but informs federation that this subgraph doesn’t provide an entity resolver.
General availability is coming soon!
We’re dotting our I
s and crossing our T
s so we can remove the “preview” label from Apollo Connector fairly soon, marking the feature as generally available and ready for use in production. Stay tuned for more info on the release, and please post questions and feedback here using the connectors tag. Thank you!