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

__resolveType receiving Promise after __resolveReference for interfaces #2552

Closed
jhanggi opened this issue May 1, 2023 · 2 comments · Fixed by #2556
Closed

__resolveType receiving Promise after __resolveReference for interfaces #2552

jhanggi opened this issue May 1, 2023 · 2 comments · Fixed by #2556

Comments

@jhanggi
Copy link

jhanggi commented May 1, 2023

Issue Description

When using __resolveReference to resolve an interface, it ends up passing a promise to __resolveType. It is my understanding that while __resolveType can return a promise, it should not receive a promise.

In my example, if I take out the __resolveType, I get an expected error about needing to implement __resolveType or isTypeOf. If I make the __resolveReference synchronous, everything works fine. But if it's async (like it would be if it hit an actual database), then the type of the object going into __resolveType is a promise which means that it won't match any of my conditionals.

I was able to make a codesandbox with this issue. I was originally trying to do this with typegraph, but when I ran into the issue, I decided to take that out of the equation and came up with this. I have a PR over there as well: MichalLytek/type-graphql#1448

Link to Reproduction

https://codesandbox.io/p/sandbox/naughty-keldysh-phhss6?file=%2Fsrc%2Fproducts.ts

Reproduction Steps

I've set it up so "Product" is an interface for Books and Movies.

Run this of :4000 (the supergraph):

query ExampleQuery {
  reviews {
    id
      product {
        id
        name
        __typename
        ... on Book {
          author
        }
        ... on Movie {
          director
        }
      }
  
  }
}

You can also run the reference resolution query directly on the products subgraph (:4001):

query ($representations: [_Any!]!) {
    _entities(representations: $representations) {
      ... on Product {
        name
      }
    }
  }

variable:
{"representations": [{"__typename": "Product", "id": "1"}]}
@trevor-scheer
Copy link
Member

This seems like a legitimate issue (if it's not then we surely must have another way of accomplishing what you're after). I've opened a PR with a reproduction and a proposed fix, I'll surface it to the team. Thanks for taking the time to put together a reproduction!

@jhanggi
Copy link
Author

jhanggi commented May 19, 2023

I've upgrade to subgraph 2.4.5 and that fixes our issue. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants