graphql-mesh
graphql-mesh copied to clipboard
TypeResolver of GraphQL interface type is not working
Issue workflow progress
Progress of the issue based on the Contributor Workflow
- [ ] 1. The issue provides a reproduction available on Github, Stackblitz or CodeSandbox
Make sure to fork this template and run
yarn generatein the terminal.Please make sure Mesh package versions under
package.jsonmatches yours.
- [ ] 2. A failing test has been provided
- [ ] 3. A local solution has been provided
- [ ] 4. A pull request is pending review
Describe the bug
The type of an object implementing an interface cannot be resolved, although a resolver has been defined and added to the .meshrc.yaml. Mesh then quits with an error from graphql-jit/execution.ts stating Could not resolve the object type in possible types of Fruit for the value: {"name":"Apple","type":"tree"}, which is because Fruit.resolveType is undefined, so for some reason the defined TypeResolver is not applied.
To Reproduce Steps to reproduce the behavior: I have an OpenAPI schema returning an array of abstract objects (Fruit). Mesh generates:
Fruits {
fruits: [JSON]
}
So Mesh is not capable of producing a proper schema for abstract return types. However I then tried to replace the field Fruits.fruit with a proper representation (.meshrc.yaml).
- replaceField:
typeDefs: |
interface Fruit {
name: String!
}
type FruitsInt {
fruits: [Fruit]
}
type Apple implements Fruit {
name: String!
type: String
}
replacements:
- from:
type: Fruits
field: fruits
to:
type: FruitsInt
field: fruits
I also added an additional resolver resolvers.ts to resolve the type of Fruit.
import { Resolvers } from "./.mesh";
const resolvers: Resolvers = {
Fruit: {
__resolveType: (obj, context, info) => {
return "Apple";
},
},
Apple: {
__isTypeOf: (event) => true,
},
};
export default resolvers;
Expected behavior The defined resolver is being applied properly to the GraphQLInterfaceType instance and consequently the type resolution works as intended.
Environment:
- OS: macOSX 12.3.1
@graphql-mesh/cli: "^0.68.3"@graphql-mesh/json-schema: "^0.28.3"@graphql-mesh/openapi: "^0.24.13"@graphql-mesh/transform-replace-field: "0.3.46"graphql: "^16.3.0"- NodeJS: v17.9.0
@charlypoly we already had a conversation about this issue.
I believe this is the same issue here: https://github.com/Urigo/graphql-mesh/issues/2382 opened back in June of last year.
Hi @g0rill4z,
Thank you for your explanation!
In order to better understand the issue, could you provide a working reproduction on Github, Stackblitz or CodeSandbox?
Thank you!
GraphQL JIT is not used anymore so this doesn't seem to be an issue. Let us know if the issue persists so we can reopen the issue.