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 duplicate calls to services on interface types #399

Closed
delyanr opened this issue Dec 30, 2019 · 2 comments · Fixed by #671
Closed

Query planner duplicate calls to services on interface types #399

delyanr opened this issue Dec 30, 2019 · 2 comments · Fixed by #671
Assignees
Labels
🪲 bug component/query routing rust Pull requests that update Rust code

Comments

@delyanr
Copy link
Contributor

delyanr commented Dec 30, 2019

Hello,

Packages: apollo-gateway v0.11.6

I'm running a microservice architecture based on the federation specs with apollo-gateway at the helm. One of the microservices defines a BasePost interface type, that is implemented by RegularPost and FeaturedPost, while another microservices defines a User type.

When I run a query to fetch blogs, their posts and authors, I get duplicated calls to the users microservices due to the BasePost interface. See the query planner below:

QueryPlan {
    Sequence {
      Fetch(service: "blogs") {
        {
          blogs {
            id
            posts {
              __typename
              ... on RegularPost {
                id
                author {
                  id
                  __typename
                }
              }
              ... on FeaturedPost {
                id
                author {
                  id
                  __typename
                }
              }
            }
          }
        }
      },
      Parallel {
        Flatten(path: "blogs.@.posts.@.author") {
          Fetch(service: "users") {
            {
              ... on User {
                __typename
                id
              }
            } =>
            {
              ... on User {
                givenName
              }
            }
          },
        },
        Flatten(path: "blogs.@.posts.@.author") {
          Fetch(service: "users") {
            {
              ... on User {
                __typename
                id
              }
            } =>
            {
              ... on User {
                givenName
              }
            }
          },
        },
      },
    },
  }

Given the author has the same fields between the implementing types, I would expect a single Fetch to the users microservice. Is this behaviour normal?

Thanks!

@jazzyray
Copy link

Hello,

(Using "@apollo/gateway": "^0.19.1")

Just to add something to this.
Federation over interface objects is virutally unusable for us.

Consider the following federated GraphQL query that sits in front
of three services. Described in this blog post:

https://www.ontotext.com/blog/the-rise-of-the-knowledge-graph

The following graphql query

query {
    annotation(id: "https://www.ontotext.com/blog/the-rise-of-the-knowledge-graph/annotation/1") {
      body {
        source { 
          similar {
           id
           name
          }
        }
        purpose
      }
    }
  }

Returns the attached result and query plan. query-response.txt

The gateway invokes 10s of duplicate backend service queries to the same service with the same set of identical query variables/representations. See log apollo-gw.log

This is a performance nightmare.

Is there any further work (PR's) that might help save me time trying to resolve this.

@abernix abernix transferred this issue from apollographql/apollo-server Jan 15, 2021
@abernix abernix changed the title [Federation] Gateway query planner duplicate calls to services on interface types Query planner duplicate calls to services on interface types Mar 4, 2021
@abernix abernix added 🪲 bug component/query routing rust Pull requests that update Rust code labels Mar 4, 2021
@abernix
Copy link
Member

abernix commented Apr 30, 2021

The fix for this was released in @apollo/gateway@0.27.1! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🪲 bug component/query routing rust Pull requests that update Rust code
Projects
None yet
4 participants