Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Introspection query doesn't return latest schema changes when query plan is being persisted on Redis #5006

Closed
nathanmarcos opened this issue Apr 23, 2024 · 6 comments · Fixed by #5007
Assignees

Comments

@nathanmarcos
Copy link

nathanmarcos commented Apr 23, 2024

Describe the bug
Starting from version 1.44.0, up to latest 1.45.0, the introspection query is not returning new parts of the schema when persisting the query plan on Redis and router is using a supergraph from a file.

To Reproduce
Steps to reproduce the behavior:

  1. Start redis:
    • docker run --rm -d -p 6379:6379 redis
  2. Start stock router version 1.44.0 or 1.45.0 as following:
    • APOLLO_KEY="..." APOLLO_GRAPH_REF="..." APOLLO_ROUTER_SUPERGRAPH_PATH="examples/graphql/supergraph.graphql" APOLLO_ROUTER_CONFIG_PATH="router.yaml" cargo run -- --dev
# router.yaml
supergraph:
  query_planning:
    cache:
      in_memory:
        limit: 1024
      redis:
        timeout: 10ms
        urls:
          - "redis://127.0.0.1"
  1. Open sandbox at http://127.0.0.1:4000/ and make sure schema polling is on
  2. Add a new query to examples/graphql/supergraph.graphql and save the file
  3. Router will hot reload
  4. The new query doesn't appear on sandbox

PS: If you manually delete the entry on Redis for the plan:v2.7.2:06402fd188... that contains the {"Ok":{"Response":{"response":{"data":{"__schema":{"queryType":{"name":"Query"},"..., a new entry will be created and the new schema will immediately be delivered and the new query will be visible on sandbox.

Expected behavior
Router should serve via introspection all schema changes after a reload or hot reload even when the query plan is being persisted on Redis.

Desktop (please complete the following information):

  • OS: macOS Sonoma
  • Version: 14.4.1

Additional context
Router version: 1.44.0 or 1.45.0

@nathanmarcos nathanmarcos changed the title Introspection query doesn't returned updated schema when query plan is being persisted on Redis Introspection query doesn't latest schema changes when query plan is being persisted on Redis Apr 23, 2024
@nathanmarcos nathanmarcos changed the title Introspection query doesn't latest schema changes when query plan is being persisted on Redis Introspection query doesn't return latest schema changes when query plan is being persisted on Redis Apr 23, 2024
@Geal
Copy link
Contributor

Geal commented Apr 23, 2024

I think that is related to #4883
The query plan cache key uses a hash of the query that takes into account the relevant parts of the schema to avoid planning again queries that are not affected by a schema change, but I don't think it takes into account introspection queries.
We will soon separate introspection queries from the query planner cache so that will be solved definitely then, but in the meantime I think we should fix this quickly

The schema aware hash is in :

pub(crate) fn hash_query(
schema: &'a schema::Schema,
executable: &'a executable::ExecutableDocument,
operation_name: Option<&str>,
) -> Result<Vec<u8>, BoxError> {
let mut visitor = QueryHashVisitor::new(schema, executable);
traverse::document(&mut visitor, executable, operation_name)?;
Ok(visitor.finish())
}

@abernix
Copy link
Member

abernix commented Apr 24, 2024

Thanks for opening this, @nathanmarcos. We're working on a 1.45.1 patch release with a couple things right now. In the meantime, are you in any position to be able to try the PR that is opened that purports to fix this (#5007)? (If you necessitate a Docker image or something, we could probably make that happen.)

@nathanmarcos
Copy link
Author

Hello @abernix, I tested it, and it works just fine. 🎉

Thanks @Geal for the quick fix. 🚀

@abernix
Copy link
Member

abernix commented Apr 24, 2024

Thanks for the validation, @nathanmarcos. Just to set expectations, it'll probably be a Friday release with that above patch and probably one other smaller fix.

@nathanmarcos
Copy link
Author

No problem. That sounds good, thanks @abernix . 😉

abernix pushed a commit that referenced this issue Apr 25, 2024
Fix #5006

in #4883 we introduced a
query hashing scheme that stays stable across schema updates if the
update does not affect the query. Unfortunately, it was not taking
introspection queries into account.
This fixes the hashing mechanism to add the schema string to hashed data
if we encounter an introspection field. This is a temporary fix until we
move introspection execution out of query planning. At that point, this
hashing mechanism won't ever see introspection fields.
@abernix
Copy link
Member

abernix commented Apr 29, 2024

This was released in https://github.com/apollographql/router/releases/tag/v1.45.1 via #5007. Note that we also brought in another (more critical) hashing fix to that release.

@abernix abernix closed this as completed Apr 29, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants