Skip to content

Fix results cache shared between different schemas #1014

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

Open
wants to merge 2 commits into
base: 8.x-4.x
Choose a base branch
from

Conversation

Sut3kh
Copy link

@Sut3kh Sut3kh commented May 28, 2020

We came across this when using a standalone GraphiQL (not the one in Drupal admin). The introspection query gets cached for the first hit schema and then is returned for all other endpoints/schemas (because the query is exactly the same, admittedly a very unlikely scenario for anything but introspection).

I have assumed that the results should be cached per schema in all cases so I've added the url.path context (as you require different schemas/servers to be on different urls). I don't fully understand the context bubbling so this may not be the best place(s) to do it but here is the patch we have used successfully to solve it for us.

add_url_path_context.patch.txt

@codecov
Copy link

codecov bot commented May 28, 2020

Codecov Report

Merging #1014 into 8.x-4.x will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             8.x-4.x    #1014   +/-   ##
==========================================
  Coverage      54.43%   54.43%           
  Complexity       626      626           
==========================================
  Files            113      113           
  Lines           1578     1578           
==========================================
  Hits             859      859           
  Misses           719      719           
Impacted Files Coverage Δ Complexity Δ
src/GraphQL/Execution/FieldContext.php 22.22% <100.00%> (ø) 7.00 <0.00> (ø)
src/GraphQL/Execution/ResolveContext.php 32.50% <100.00%> (ø) 16.00 <0.00> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 45c6f1d...2e16980. Read the comment docs.

@klausi klausi added the 4.x label Jun 24, 2020
Copy link
Contributor

@klausi klausi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this makes sense, don't have a better idea where we should a cache context instead or what other one we should use.

We should make a test case for this. Creating 2 schemas, sending the inspection query, check that the response on the second schema is correct.

@fubhy
Copy link
Contributor

fubhy commented Jun 24, 2020

I think this makes sense, don't have a better idea where we should a cache context instead or what other one we should use.

We should make a test case for this. Creating 2 schemas, sending the inspection query, check that the response on the second schema is correct.

This shouldn't use the url because that binds it to the router, which is a big nono for me for an API (and actually in general). The router / url context should only be used for very high level http caching imho.

Let's instead use a custom cache context string including the schema name. I built a generic custom string cache context for this purpose: https://github.com/drupal-graphql/graphql/blob/8.x-4.x/src/Cache/Context/StaticCacheContext.php

So static:$schemaName

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

Successfully merging this pull request may close these issues.

3 participants