Skip to content

Commit

Permalink
Release 2.3.0-alpha.0 (#2302)
Browse files Browse the repository at this point in the history
* Implements @interfaceObject and @key on interfaces (#2279)

Add support for the newly added `@interfaceObject` directive and for
`@key` on interfaces, in order to allow using interfaces as abstraction
across subgraphs. See #2277 for details.

Fixes #2277.

* Preserves source of union members and enum values in supergraph (#2288)

While composition allows unions and enums to differ between subgraphs (at
least under certain conditions), the supergraph currently was not
preserving which subgraph defined which union member/enum value, and in
particular the query planner made the (sometimes incorrect) assumption
that unions and enums were defined the same in all the subgraphs in
which they are defined.

As shown in #2256, this was leading to genuine issues in the case of
unions, where the query planner was generating invalid subgraph queries.
I am not sure this created similar issues for enum values due to a
combination of how the merging rule for enum work and the fact that
values of enum are not types, but it is nonetheless a bad idea to
run the query planner with incorrect information on the subgraph it
generates queries for, and this can get in the way of other toolings
that wants to use the supergraph (for instance, this gets in the
way of #2250).

To fix this, this patch ensures the supergraph preserve the information
regarding which subgraph defines which union member and enum values in
the supergraph by adding 2 new dedicated "join spec" directives.

Fixes #2256.

* Use alias in QP when querying conflicting fields (#2294)

* Use alias in QP when querying conflicting fields

In a few situations, the query planner was generating queries where
the same response name was queried at the same "level" with incompatible
types, resulting in invalid queries (the queries were failing the
[`FieldsInSetCanMerge`](https://spec.graphql.org/draft/#FieldsInSetCanMerge()))
validation for the GraphQL sepc).

This commit detects this case, and when it would happen, aliases one
of the occurence in the fetch to make the query valid. Once receiving
the fetch result, the aliased value is rewritten to it's original
response name.

Fixes #1257

* Review feedback: add test for alias conflicts and fix related code

* Regen error doc

* Release

 - @apollo/[email protected]
 - [email protected]
 - @apollo/[email protected]
 - @apollo/[email protected]
 - @apollo/[email protected]
 - @apollo/[email protected]
 - @apollo/[email protected]

Co-authored-by: Sylvain Lebresne <[email protected]>
  • Loading branch information
jeffjakub and Sylvain Lebresne authored Dec 16, 2022
1 parent 195732e commit 972580b
Show file tree
Hide file tree
Showing 50 changed files with 4,814 additions and 806 deletions.
4 changes: 4 additions & 0 deletions composition-js/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ This CHANGELOG pertains only to Apollo Federation packages in the 2.x range. The

## vNext

## 2.3.0

- Preserves source of union members and enum values in supergraph [PR #2288](https://github.com/apollographql/federation/pull/2288).

## 2.2.0

- __BREAKING__: composition now rejects `@shareable` on interface fields. The `@shareable` directive is about
Expand Down
2 changes: 1 addition & 1 deletion composition-js/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@apollo/composition",
"version": "2.2.2",
"version": "2.3.0-alpha.0",
"description": "Apollo Federation composition utilities",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
exports[`composing custom core directives custom tag directive works when federation tag is renamed 1`] = `
"schema
@link(url: \\"https://specs.apollo.dev/link/v1.0\\")
@link(url: \\"https://specs.apollo.dev/join/v0.2\\", for: EXECUTION)
@link(url: \\"https://specs.apollo.dev/join/v0.3\\", for: EXECUTION)
@link(url: \\"https://specs.apollo.dev/tag/v0.2\\", as: \\"mytag\\")
@link(url: \\"https://custom.dev/tag/v1.0\\", import: [\\"@tag\\"])
{
Expand All @@ -14,12 +14,16 @@ directive @link(url: String, as: String, for: link__Purpose, import: [link__Impo
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
directive @join__type(graph: join__Graph!, key: join__FieldSet, extension: Boolean! = false, resolvable: Boolean! = true, isInterfaceObject: Boolean! = false) repeatable on OBJECT | INTERFACE | UNION | ENUM | INPUT_OBJECT | SCALAR
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__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__implements(graph: join__Graph!, interface: String!) repeatable on OBJECT | INTERFACE
directive @join__unionMember(graph: join__Graph!, member: String!) repeatable on UNION
directive @join__enumValue(graph: join__Graph!) repeatable on ENUM_VALUE
directive @mytag(name: String!) repeatable on FIELD_DEFINITION | OBJECT | INTERFACE | UNION | ARGUMENT_DEFINITION | SCALAR | ENUM | ENUM_VALUE | INPUT_OBJECT | INPUT_FIELD_DEFINITION
directive @tag(name: String!, prop: String!) on FIELD_DEFINITION | OBJECT
Expand Down
6 changes: 4 additions & 2 deletions composition-js/src/__tests__/compose.composeDirective.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ describe('composing custom core directives', () => {
});

it.each([
'@join__field', '@join__graph', '@join__implements', '@join__type',
'@join__field', '@join__graph', '@join__implements', '@join__type', '@join__unionMember', '@join__enumValue'
])('join spec directives should result in an error', (directive) => {
const subgraphA = generateSubgraph({
name: 'subgraphA',
Expand All @@ -376,6 +376,8 @@ describe('composing custom core directives', () => {
directive @join__graph(name: String!, url: String!) on ENUM_VALUE
directive @join__implements(graph: join__Graph!, interface: String!) repeatable on OBJECT | INTERFACE
directive @join__type(graph: join__Graph!, key: join__FieldSet, extension: Boolean! = false, resolvable: Boolean! = true) repeatable on OBJECT | INTERFACE | UNION | ENUM | INPUT_OBJECT | SCALAR
directive @join__unionMember(graph: join__Graph!, member: String!) repeatable on UNION
directive @join__enumValue(graph: join__Graph!) repeatable on ENUM_VALUE
scalar join__FieldSet
Expand Down Expand Up @@ -735,7 +737,7 @@ describe('composing custom core directives', () => {
});

it.each([
'@join__field', '@join__graph', '@join__implements', '@join__type'
'@join__field', '@join__graph', '@join__implements', '@join__type', '@join__unionMember', '@join__enumValue'
])('naming conflict with join spec directives', (directive) => {
const subgraphA = generateSubgraph({
name: 'subgraphA',
Expand Down
Loading

0 comments on commit 972580b

Please sign in to comment.