-
-
Notifications
You must be signed in to change notification settings - Fork 818
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix aliased shared root fields (#6619)
* chore: add failing tests * Fix and isolated test * Remove unused import * Changeset --------- Co-authored-by: Tomas Kroupa <[email protected]> Co-authored-by: Arda TANRIKULU <[email protected]>
- Loading branch information
1 parent
17bfe64
commit e9906eb
Showing
4 changed files
with
135 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
'@graphql-tools/delegate': minor | ||
'@graphql-tools/federation': patch | ||
--- | ||
|
||
Handle shared root field queries with aliases |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
import { parse } from 'graphql'; | ||
import { buildSubgraphSchema } from '@apollo/subgraph'; | ||
import { normalizedExecutor } from '@graphql-tools/executor'; | ||
import { getStitchedSchemaFromLocalSchemas } from './getStitchedSchemaFromLocalSchemas'; | ||
|
||
describe('Aliased Shared Root Fields', () => { | ||
it('issue #6613', async () => { | ||
const query = /* GraphQL */ ` | ||
query { | ||
testNestedField { | ||
subgraph1 { | ||
id | ||
sub1 | ||
} | ||
testUserAlias: subgraph2 { | ||
id | ||
sub2 | ||
} | ||
} | ||
} | ||
`; | ||
|
||
const expectedResult = { | ||
data: { | ||
testNestedField: { | ||
subgraph1: { | ||
id: 'user1', | ||
email: '[email protected]', | ||
sub1: true, | ||
}, | ||
testUserAlias: { | ||
id: 'user2', | ||
email: '[email protected]', | ||
sub2: true, | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
const subgraph1 = buildSubgraphSchema({ | ||
typeDefs: parse(/* GraphQL */ ` | ||
type Query { | ||
testNestedField: TestNestedField | ||
} | ||
type TestNestedField { | ||
subgraph1: TestUser1! | ||
} | ||
type TestUser1 { | ||
id: String! | ||
email: String! | ||
sub1: Boolean! | ||
} | ||
`), | ||
resolvers: { | ||
Query: { | ||
testNestedField: () => ({ | ||
subgraph1: () => ({ | ||
id: 'user1', | ||
email: '[email protected]', | ||
sub1: true, | ||
}), | ||
}), | ||
}, | ||
}, | ||
}); | ||
const subgraph2 = buildSubgraphSchema({ | ||
typeDefs: parse(/* GraphQL */ ` | ||
type Query { | ||
testNestedField: TestNestedField | ||
} | ||
type TestNestedField { | ||
subgraph2: TestUser2! | ||
} | ||
type TestUser2 { | ||
id: String! | ||
email: String! | ||
sub2: Boolean! | ||
} | ||
`), | ||
resolvers: { | ||
Query: { | ||
testNestedField: () => ({ | ||
subgraph2: () => ({ | ||
id: 'user2', | ||
email: '[email protected]', | ||
sub2: true, | ||
}), | ||
}), | ||
}, | ||
}, | ||
}); | ||
|
||
const gatewaySchema = await getStitchedSchemaFromLocalSchemas({ | ||
subgraph1, | ||
subgraph2, | ||
}); | ||
|
||
const result = await normalizedExecutor({ | ||
schema: gatewaySchema, | ||
document: parse(query), | ||
}); | ||
|
||
expect(result).toEqual(expectedResult); | ||
}); | ||
}); |