Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeResolver of GraphQL interface type is not working #3881

Closed
4 tasks
daveekr opened this issue Apr 28, 2022 · 4 comments
Closed
4 tasks

TypeResolver of GraphQL interface type is not working #3881

daveekr opened this issue Apr 28, 2022 · 4 comments
Assignees
Labels
stage/0-issue-prerequisites Needs more information before we can start working on it

Comments

@daveekr
Copy link

daveekr commented Apr 28, 2022

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
Copy link
Author

daveekr commented Apr 28, 2022

@charlypoly we already had a conversation about this issue.

@paradigm314
Copy link

I believe this is the same issue here: #2382 opened back in June of last year.

@charlypoly
Copy link
Collaborator

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 charlypoly added the stage/0-issue-prerequisites Needs more information before we can start working on it label May 18, 2022
@charlypoly charlypoly assigned charlypoly and ardatan and unassigned charlypoly May 18, 2022
@theguild-bot theguild-bot mentioned this issue Aug 11, 2022
@ardatan
Copy link
Owner

ardatan commented Mar 31, 2023

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 ardatan closed this as completed Mar 31, 2023
@theguild-bot theguild-bot mentioned this issue Sep 28, 2023
This was referenced Apr 30, 2024
This was referenced May 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stage/0-issue-prerequisites Needs more information before we can start working on it
Projects
None yet
Development

No branches or pull requests

4 participants