graphql-mesh icon indicating copy to clipboard operation
graphql-mesh copied to clipboard

TypeResolver of GraphQL interface type is not working

Open daveekr opened this issue 3 years ago • 3 comments

Issue workflow progress

Progress of the issue based on the Contributor Workflow

Make sure to fork this template and run yarn generate in the terminal.

Please make sure Mesh package versions under package.json matches 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

daveekr avatar Apr 28 '22 10:04 daveekr

@charlypoly we already had a conversation about this issue.

daveekr avatar Apr 28 '22 10:04 daveekr

I believe this is the same issue here: https://github.com/Urigo/graphql-mesh/issues/2382 opened back in June of last year.

paradigm314 avatar May 12 '22 17:05 paradigm314

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!

charlypoly avatar May 18 '22 12:05 charlypoly

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.

ardatan avatar Mar 31 '23 07:03 ardatan