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

Aliases in inline fragments not resolved properly using gateway #2392

Closed
miguelwebtales opened this issue Feb 13, 2023 · 3 comments
Closed

Comments

@miguelwebtales
Copy link

I am getting two different behaviours depending if I request the query bellow on the subgraph or the gateway.

query {
  search {
    __typename
   id
    ... on Repository {
      good_alias: name
      broken_alias: repository_name
    }			
    ... on User {
	good_alias: name
	broken_alias: user_name
    }
  }
}

Running this query on the subgraph the expected/correct output is returned.

{
	"data": {
		"search": {
			"__typename": "User",
			"id": "user-id",
			"good_alias": "Miguel",
			"broken_alias": "miguelwebtales"
		}
	}
}

But running the same query on the gateway the alias "broken_alias" fails and returns null.

{
  "data": {
    "search": {
      "__typename": "User",
      "id": "user-id",
      "good_alias": "Miguel",
      "broken_alias": null
    }
  }
}

The query planner for the above query is the following one:

QueryPlan {
  Fetch(service: "example") {
    {
      search {
        __typename
        id
        ... on Repository {
          good_alias: name
          broken_alias: repository_name
        }
        ... on User {
          good_alias: name
          broken_alias__alias_0: user_name
        }
      }
    }
  },
}

As we can see the alias "broken_alias" is transformed into "broken_alias__alias_0" on the User Inline Fragment, probably causing this issue.

Is this a bug or a limitation using aliases on the gateway?

You can find a demo with this problem here: https://github.com/miguelwebtales/federated-alias-bug-example

@korinne
Copy link
Contributor

korinne commented Feb 17, 2023

Thanks for raising this issue! Our team will look into it and get back to you as soon as possible.

@pcmanus
Copy link
Contributor

pcmanus commented Feb 20, 2023

Hi @miguelwebtales. The issue, at least in the linked demo, is a dependency issue. Looking at [the package.json|https://github.com/miguelwebtales/federated-alias-bug-example/blob/master/package.json] file, you have:

"@apollo/gateway": "2.0.5",
"@apollo/query-planner": "^2.3.2",

but you really need to use the same version for the gateway and query-planner. My advice would be never manually list the dependency on @apollo/query-planner, so it always get pulled as a dependency of @apollo/gateway with the proper version.

The longer answer is that the transformation of the alias (from broken_alias to broken_alias__alias_0) in the subgraph query is done as a way to avoid the bug described in #1257 (which doesn't affect the particular query of this example, but the fix is a bit conservative and triggers in this case too). The alias transformation happens because you are using a "newer" query planner (2.3.2), but it relies on the gateway knowing how to handle it and that is not the case of gateway 2.0.5.

We do not, in general, support mismatched versions of the gateway and the query planner, because some fixes (like the one here) require cooperation between the plan generation side (the query planner) and the plan execution side (the gateway). But we could probably make a better job at warning about this/documenting this ...

@pcmanus
Copy link
Contributor

pcmanus commented Feb 20, 2023

Closing as I've validated that updating the dependency of @apollo/gateway to ^2.3.2 does fix the issue in the demo above. But I've also created #2409 to follow up on ideas to improve the experience when versions of packages are mismatched in incompatible ways.

@pcmanus pcmanus closed this as completed Feb 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants