-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: handle
@resolveTo
on interfaces correctly (#247)
- Loading branch information
Showing
10 changed files
with
209 additions
and
8 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,5 @@ | ||
--- | ||
'@graphql-tools/stitch': patch | ||
--- | ||
|
||
Fixes the bug when interfaces extended by \`additionalTypeDefs\` |
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,5 @@ | ||
--- | ||
'@graphql-mesh/fusion-runtime': patch | ||
--- | ||
|
||
Handle \`@resolveTo\` for interfaces correctly |
43 changes: 43 additions & 0 deletions
43
e2e/interface-additional-resolvers/interface-additional-resolvers.e2e.ts
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,43 @@ | ||
import { createTenv } from '@internal/e2e'; | ||
import { expect, it } from 'vitest'; | ||
|
||
const { gateway, service } = createTenv(__dirname); | ||
|
||
it('works', async () => { | ||
const { execute } = await gateway({ | ||
supergraph: { | ||
with: 'mesh', | ||
services: [await service('Test')], | ||
}, | ||
pipeLogs: true, | ||
}); | ||
|
||
const result = await execute({ | ||
query: /* GraphQL */ ` | ||
query { | ||
node(id: "1") { | ||
id | ||
... on User { | ||
name | ||
} | ||
self { | ||
id | ||
... on User { | ||
name | ||
} | ||
} | ||
} | ||
} | ||
`, | ||
}); | ||
|
||
expect(result.errors).toBeFalsy(); | ||
expect(result.data.node).toEqual({ | ||
id: '1', | ||
name: 'Alice', | ||
self: { | ||
id: '1', | ||
name: 'Alice', | ||
}, | ||
}); | ||
}); |
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,33 @@ | ||
import { | ||
defineConfig, | ||
loadGraphQLHTTPSubgraph, | ||
} from '@graphql-mesh/compose-cli'; | ||
import { Opts } from '@internal/testing'; | ||
|
||
const opts = Opts(process.argv); | ||
|
||
export const composeConfig = defineConfig({ | ||
subgraphs: [ | ||
{ | ||
sourceHandler: loadGraphQLHTTPSubgraph('Test', { | ||
endpoint: `http://localhost:${opts.getServicePort('Test')}/graphql`, | ||
}), | ||
}, | ||
], | ||
additionalTypeDefs: /* GraphQL */ ` | ||
extend interface Node { | ||
self: Node! | ||
@resolveTo( | ||
sourceName: "Test" | ||
sourceTypeName: "Query" | ||
sourceFieldName: "node" | ||
sourceArgs: { id: "{root.id}" } | ||
requiredSelectionSet: "{ id }" | ||
) | ||
} | ||
extend type User implements Node { | ||
self: Node! | ||
} | ||
`, | ||
}); |
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,15 @@ | ||
{ | ||
"name": "@e2e/interface-additional-resolvers", | ||
"private": true, | ||
"dependencies": { | ||
"@graphql-mesh/compose-cli": "^1.2.0", | ||
"@graphql-mesh/cross-helpers": "^0.4.8", | ||
"@graphql-mesh/store": "^0.103.4", | ||
"@graphql-mesh/types": "^0.103.4", | ||
"@graphql-mesh/utils": "^0.103.4", | ||
"@graphql-tools/utils": "^10.6.0", | ||
"graphql": "^16.9.0", | ||
"graphql-yoga": "^5.10.4", | ||
"tslib": "^2.8.0" | ||
} | ||
} |
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,40 @@ | ||
import { createServer } from 'node:http'; | ||
import { Opts } from '@internal/testing'; | ||
import { createSchema, createYoga } from 'graphql-yoga'; | ||
|
||
export const yoga = createYoga({ | ||
schema: createSchema({ | ||
typeDefs: /* GraphQL */ ` | ||
interface Node { | ||
id: ID! | ||
} | ||
type User implements Node { | ||
id: ID! | ||
name: String! | ||
} | ||
type Query { | ||
node(id: ID!): Node | ||
user(id: ID!): User | ||
} | ||
`, | ||
resolvers: { | ||
Node: { | ||
__resolveType: (obj: { __typename: string }) => obj.__typename, | ||
}, | ||
Query: { | ||
node: () => ({ __typename: 'User', id: '1', name: 'Alice' }), | ||
}, | ||
}, | ||
}), | ||
maskedErrors: false, | ||
}); | ||
|
||
const opts = Opts(process.argv); | ||
|
||
createServer(yoga).listen(opts.getServicePort('Test'), () => { | ||
console.log( | ||
`🚀 Server ready at http://localhost:${opts.getServicePort('Test')}/graphql`, | ||
); | ||
}); |
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
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