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

Query planner unwraps interface implementations incorrectly #817

Closed
barthez opened this issue Jun 15, 2021 · 3 comments
Closed

Query planner unwraps interface implementations incorrectly #817

barthez opened this issue Jun 15, 2021 · 3 comments
Assignees

Comments

@barthez
Copy link

barthez commented Jun 15, 2021

Description

After updating to recent @apollo/gateway package version we started observing and error when query on a field of type of an interface cause No such type [Type], so it can't be a fragment condition. Simplified setup down below

Example (actual behavior)

Service A:

type Query {
  myField: MyInterface
}

type MyInterface {
  name: String
}

type MyTypeA implements MyInterface {
  name: String
}

type MyTypeB implements MyInterface {
  name: String
}

Service B:

interface MyInterface {
 name: String
}

type MyTypeC implements MyInterface {
  name: String
}

The query:

query {
  myField: {
    ...MyIntFragment
  }
}

fragment MyIntFragment on MyInterface {
  name
}

result in such query to service A:

query {
  myField {
    ...on MyTypeA { name }
    ...on MyTypeB { name }
    ...on MyTypeC { name }
  }
}

which cause an error

Unknown type "MyTypeC".

Expected behavior

Query to the service A doesn't include fragment for MyTypeC that isn't known for the service.

Versions when problem occurs:

Versions when problem did not occur

Working example

https://github.com/barthez/query-planner-error-example

@barthez
Copy link
Author

barthez commented Jun 25, 2021

Hey @trevor-scheer, is there any chance you could give some feedback in here. I have tried to fix it with #816 but it turned out to break other things (when types are actually shared between services). If you could give me some hints I could try to fix it and create a PR.

@pcmanus
Copy link
Contributor

pcmanus commented Nov 5, 2021

The upcoming version of federation (2.0, currently in alpha) fixes this issue and I've pushed 41a9b76 with a test for it. Fixing this is on the 0.x branch is unfortunately a bit tricky (federation 2 has a laregly rewritten query planner, and one of the reasons for such rewrite was to make it easier to solve that kind of issues).

@konalegi
Copy link

@pcmanus have you seen this PR? #864, It works for our cases, could you please take a look if makes sense.

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

No branches or pull requests

5 participants