Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't apply @shareable if it's already @shareable #2043

Merged
merged 4 commits into from
Aug 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions composition-js/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

This CHANGELOG pertains only to Apollo Federation packages in the 2.x range. The Federation v0.x equivalent for this package can be found [here](https://github.com/apollographql/federation/blob/version-0.x/federation-js/CHANGELOG.md) on the `version-0.x` branch of this repo.

- Don't apply @shareable when upgrading fed1 supergraphs if it's already @shareable [PR #2043](https://github.com/apollographql/federation/pull/2043)
- Update peer dependency `graphql` to `^16.5.0` to use `GraphQLErrorOptions` [PR #2060](https://github.com/apollographql/federation/pull/2060)

## 2.1.0-alpha.3
Expand Down
37 changes: 37 additions & 0 deletions composition-js/src/__tests__/composeFed1Subgraphs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,43 @@ describe('shareable', () => {
}
`);
});

it('supports fed1 subgraphs that define @shareable', () => {
const subgraphA = {
name: 'subgraphA',
typeDefs: gql`
type Queryf {
friendlyFruit: Fruit!
}

directive @shareable on OBJECT | FIELD_DEFINITION

type Fruit @shareable {
id: ID!
name: String!
}
`
};

const subgraphB = {
name: 'subgraphB',
typeDefs: gql`
type Query {
forbiddenFruit: Fruit!
}

directive @shareable on OBJECT | FIELD_DEFINITION

type Fruit @shareable {
id: ID!
name: String!
}
`
};

const result = composeServices([subgraphA, subgraphB]);
assertCompositionSuccess(result);
});
});

describe('override', () => {
Expand Down
4 changes: 2 additions & 2 deletions internals-js/src/schemaUpgrader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -676,14 +676,14 @@ class SchemaUpgrader {
continue;
}
const otherResolvingSubgraphs = this.otherSubgraphs.filter((s) => resolvesField(s, field));
if (otherResolvingSubgraphs.length > 0) {
if (otherResolvingSubgraphs.length > 0 && !field.hasAppliedDirective(shareableDirective)) {
field.applyDirective(shareableDirective);
this.addChange(new ShareableFieldAddition(field.coordinate, otherResolvingSubgraphs.map((s) => s.name)));
}
}
} else {
const otherDeclaringSubgraphs = this.otherSubgraphs.filter((s) => s.schema.type(type.name));
if (otherDeclaringSubgraphs.length > 0) {
if (otherDeclaringSubgraphs.length > 0 && !type.hasAppliedDirective(shareableDirective)) {
type.applyDirective(shareableDirective);
this.addChange(new ShareableTypeAddition(type.coordinate, otherDeclaringSubgraphs.map((s) => s.name)));
}
Expand Down