Skip to content

Commit

Permalink
fix: detect incorrect subtypes of interface fields across subgraphs (#64
Browse files Browse the repository at this point in the history
)

- [x] cover a case when interface field expects an interface (or union)
and the field of an object type implementing the interface resolves a
member.
  • Loading branch information
kamilkisiela authored Jun 26, 2024
1 parent 988eb9a commit 9ec8078
Show file tree
Hide file tree
Showing 29 changed files with 929 additions and 217 deletions.
5 changes: 5 additions & 0 deletions .changeset/witty-ghosts-applaud.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@theguild/federation-composition': patch
---

fix: detect incorrect subtypes of interface fields across subgraphs
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ node_modules
.DS_Store
dist
*.cpuprofile
.bob
.bob
24 changes: 19 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,43 @@

### Patch Changes

- [#62](https://github.com/the-guild-org/federation/pull/62) [`e50bc90`](https://github.com/the-guild-org/federation/commit/e50bc90d4dc65769dbe44fa01994148d968755dc) Thanks [@kamilkisiela](https://github.com/kamilkisiela)! - Fix: do not expose `federation__Scope` and `federation__Policy` scalar definitions to a supergraph
- [#62](https://github.com/the-guild-org/federation/pull/62)
[`e50bc90`](https://github.com/the-guild-org/federation/commit/e50bc90d4dc65769dbe44fa01994148d968755dc)
Thanks [@kamilkisiela](https://github.com/kamilkisiela)! - Fix: do not expose `federation__Scope`
and `federation__Policy` scalar definitions to a supergraph

## 0.11.2

### Patch Changes

- [#60](https://github.com/the-guild-org/federation/pull/60) [`2f7fef1`](https://github.com/the-guild-org/federation/commit/2f7fef10409a25f8366182448a48e72d5451abf9) Thanks [@kamilkisiela](https://github.com/kamilkisiela)! - Normalize enum values to be printed as enum values in Supergraph SDL, even if the user's subgraph schema has them as strings
- [#60](https://github.com/the-guild-org/federation/pull/60)
[`2f7fef1`](https://github.com/the-guild-org/federation/commit/2f7fef10409a25f8366182448a48e72d5451abf9)
Thanks [@kamilkisiela](https://github.com/kamilkisiela)! - Normalize enum values to be printed as
enum values in Supergraph SDL, even if the user's subgraph schema has them as strings

## 0.11.1

### Patch Changes

- [#58](https://github.com/the-guild-org/federation/pull/58) [`ab707b9`](https://github.com/the-guild-org/federation/commit/ab707b9517c141377ab10d46ec6ce2efa1401450) Thanks [@kamilkisiela](https://github.com/kamilkisiela)! - Support directives on Input Object types
- [#58](https://github.com/the-guild-org/federation/pull/58)
[`ab707b9`](https://github.com/the-guild-org/federation/commit/ab707b9517c141377ab10d46ec6ce2efa1401450)
Thanks [@kamilkisiela](https://github.com/kamilkisiela)! - Support directives on Input Object
types

## 0.11.0

### Minor Changes

- [#52](https://github.com/the-guild-org/federation/pull/52) [`589effd`](https://github.com/the-guild-org/federation/commit/589effd5b82286704db2a4678bf47ffe33e01c0d) Thanks [@kamilkisiela](https://github.com/kamilkisiela)! - Support @interfaceObject directive
- [#52](https://github.com/the-guild-org/federation/pull/52)
[`589effd`](https://github.com/the-guild-org/federation/commit/589effd5b82286704db2a4678bf47ffe33e01c0d)
Thanks [@kamilkisiela](https://github.com/kamilkisiela)! - Support @interfaceObject directive

### Patch Changes

- [#52](https://github.com/the-guild-org/federation/pull/52) [`589effd`](https://github.com/the-guild-org/federation/commit/589effd5b82286704db2a4678bf47ffe33e01c0d) Thanks [@kamilkisiela](https://github.com/kamilkisiela)! - Improve INTERFACE_KEY_MISSING_IMPLEMENTATION_TYPE
- [#52](https://github.com/the-guild-org/federation/pull/52)
[`589effd`](https://github.com/the-guild-org/federation/commit/589effd5b82286704db2a4678bf47ffe33e01c0d)
Thanks [@kamilkisiela](https://github.com/kamilkisiela)! - Improve
INTERFACE_KEY_MISSING_IMPLEMENTATION_TYPE

## 0.10.1

Expand Down
6 changes: 3 additions & 3 deletions __tests__/ast.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ConstDirectiveNode, Kind, TypeKind, parse } from 'graphql';
import { ConstDirectiveNode, Kind, parse, TypeKind } from 'graphql';
import { describe, expect, test } from 'vitest';
import { ArgumentKind } from '../src/subgraph/state.js';
import {
createEnumTypeNode,
createInputObjectTypeNode,
Expand All @@ -11,7 +12,6 @@ import {
createUnionTypeNode,
stripFederation,
} from '../src/supergraph/composition/ast.js';
import { ArgumentKind } from '../src/subgraph/state.js';

function createDirective(name: string): ConstDirectiveNode {
return {
Expand Down Expand Up @@ -893,7 +893,7 @@ describe('input object type', () => {
}),
).toEqualGraphQL(/* GraphQL */ `
input Filter {
obj: Obj = {limit: 1}
obj: Obj = { limit: 1 }
limit: Int = 2
}
`);
Expand Down
7 changes: 3 additions & 4 deletions __tests__/composition.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ testImplementations(api => {

assertCompositionSuccess(result);


expect(result.supergraphSdl).toContainGraphQL(/* GraphQL */ `
type Query @join__type(graph: A) {
users(type: UserType! = Regular): [User!]!
Expand Down Expand Up @@ -1245,7 +1244,7 @@ testImplementations(api => {
@join__unionMember(graph: A, member: "Book")
@join__unionMember(graph: B, member: "Movie")
@join__unionMember(graph: B, member: "Book") =
Movie
| Movie
| Book
`);
});
Expand Down Expand Up @@ -1303,7 +1302,7 @@ testImplementations(api => {
@join__type(graph: B)
@join__unionMember(graph: A, member: "Book")
@join__unionMember(graph: B, member: "Movie") =
Book
| Book
| Movie
`);
});
Expand Down Expand Up @@ -5426,7 +5425,7 @@ testImplementations(api => {
@join__unionMember(graph: A, member: "Movie")
@join__unionMember(graph: B, member: "Book")
@join__unionMember(graph: C, member: "Song") =
Movie
| Movie
| Book
| Song
`);
Expand Down
34 changes: 29 additions & 5 deletions __tests__/fixtures/dgs/aside397.graphql
Original file line number Diff line number Diff line change
@@ -1,22 +1,46 @@
schema @link(url: "https://specs.apollo.dev/link/v1.0") @link(url: "https://specs.apollo.dev/federation/v2.0", import: ["@key", "@external", "@provides", "@requires", "@extends", "@shareable", "@tag", "@inaccessible"]) {
schema
@link(url: "https://specs.apollo.dev/link/v1.0")
@link(
url: "https://specs.apollo.dev/federation/v2.0"
import: [
"@key"
"@external"
"@provides"
"@requires"
"@extends"
"@shareable"
"@tag"
"@inaccessible"
]
) {
query: Query
}

directive @extends on INTERFACE | OBJECT

directive @external(reason: String) on FIELD_DEFINITION | OBJECT

directive @key(fields: federation__FieldSet!, resolvable: Boolean = true) repeatable on INTERFACE | OBJECT
directive @key(
fields: federation__FieldSet!
resolvable: Boolean = true
) repeatable on INTERFACE | OBJECT

directive @link(as: String, for: link__Purpose, import: [link__Import], url: String) repeatable on SCHEMA
directive @link(
as: String
for: link__Purpose
import: [link__Import]
url: String
) repeatable on SCHEMA

directive @provides(fields: federation__FieldSet!) on FIELD_DEFINITION

directive @requires(fields: federation__FieldSet!) on FIELD_DEFINITION

directive @shareable on FIELD_DEFINITION | OBJECT

directive @tag(name: String!) repeatable on ARGUMENT_DEFINITION | ENUM | ENUM_VALUE | FIELD_DEFINITION | INPUT_FIELD_DEFINITION | INPUT_OBJECT | INTERFACE | OBJECT | SCALAR | UNION
directive @tag(
name: String!
) repeatable on ARGUMENT_DEFINITION | ENUM | ENUM_VALUE | FIELD_DEFINITION | INPUT_FIELD_DEFINITION | INPUT_OBJECT | INTERFACE | OBJECT | SCALAR | UNION

enum whosec2c {
first056
Expand Down Expand Up @@ -56,4 +80,4 @@ scalar link__Import
enum link__Purpose {
EXECUTION
SECURITY
}
}
Loading

0 comments on commit 9ec8078

Please sign in to comment.