apollographql / federation

🌐  Build and scale a single data graph across multiple services with Apollo's federation gateway.
https://apollographql.com/docs/federation/
Other
668 stars 257 forks source link

Adding a field changes the returned value of another (@requires directive with arguments involved) #2996

Open rickbijkerk opened 7 months ago

rickbijkerk commented 7 months ago

Describe the bug Below a simplified description of the use case we're experiencing.

The problem: Query 1 and query 2 give a different response on 'explicit' field.

When looking at what apollo router sends to the subgraphs; The router send a request to schema 1 to fetch the attributes for Query 1: with the arguments required by the @requires definition in the schema (@requires(fields:"attributes(keys:\"Erotic Content\")}")}) Query 2: with the arguments of the 'attributes' field.

Not sure exactly how it would work but the only way for this to work properly is if apollo would send 2 seperate queries for fetching the attributes field with different arguments

Query 1

query{
  product(id: "123") {
     explicit
  }
}

Query 2

query{
  product(id: "123") {
    explicit
    attributes (keys:"size")
  }
}

Schema 1 (product)

type Query {
    product(id: ID!): Product
}

type Product @key(fields: "id") {
    id: ID!
    attributes(keys: [String!]): [String!]
}

Schema 2 (product enrichment)

type Product @key(fields: "id") {
    id: ID!
    attributes(keys: [String!]): [String!] @external
    explicit: Boolean @requires(fields: "attributes(keys:\"Erotic Content\")}")
}

Apollo router:

rickbijkerk commented 7 months ago

Updates description after some more testing

abernix commented 7 months ago

This appears to be a federation model or query planning consideration more than it is anything Router-specific. If this changes, the Router could consume any updated federation and query planner support for it, but for now I'll transfer this over to the federation repository.