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

responseCache plugin additional extension metadata when disabled #2224

Closed
mmadson opened this issue May 2, 2024 · 7 comments
Closed

responseCache plugin additional extension metadata when disabled #2224

mmadson opened this issue May 2, 2024 · 7 comments
Labels
kind/enhancement New feature or request

Comments

@mmadson
Copy link

mmadson commented May 2, 2024

Is your feature request related to a problem? Please describe.

When enabled expression evaluates to false and includeExtensionMetadata is set to true, there is no indication in the response that caching did or did not occur.

Describe the solution you'd like

Given

  • enabled expression is supplied to the responseCache plugin configuration
  • includeExtensionMetadata is set to true for the responseCache plugin configuration

When

  • enabled expression evaluates to false

Then

Include extension metadata indicating that

  • hit: false
  • didCache: false
  • enabled: false

This new enabled field in the extension metadata should also be present for other responses when enabled evaluates to true and should indicate true in these cases.

Describe alternatives you've considered

Patching the lib via package-patch

Additional context

N/A

@mmadson
Copy link
Author

mmadson commented May 15, 2024

@n1ru4l thoughts on this? I have a local patch that adds the enabled field to the extension metadata, but I'm not sure it's implemented in an elegant way. Happy to work with you on this if you think it's a valuable feature though.

@EmrysMyrddin
Copy link
Collaborator

Hi @mmadson ! Sorry for the response delay here.
This seems a reasonable feature to add :-) PR are very welcome if you want to implement this!

If you're not sure how to do it, don't hesitate to create a draft PR and ask any questions :-) We are here to help!

@EmrysMyrddin EmrysMyrddin added the kind/enhancement New feature or request label May 17, 2024
@mmadson
Copy link
Author

mmadson commented May 20, 2024

Thanks @EmrysMyrddin, no worries about the delay. I'll take a pass at an implementation and get back to ya asap.

@mmadson
Copy link
Author

mmadson commented May 20, 2024

Okay so here is the issue I'm having @EmrysMyrddin, hopefully you have a suggestion.

I'd like enabled: false to appear whenever includeExtensionMetadata is true but response cache is disabled. And I'd like enabled: true to appear whenever includeExtensionMetadata is true and response cache is enabled.

For the enabled: true case, it's pretty simple. I just need to add enabled: true to all the current resultWithMetadata calls in the envelope response cache plugin:

The enabled: false case is where things get tricky.

Instead of simply returning on this line

I need to add the enabled: false to the result metadata: so I was thinking something like:

return {
    onExecuteDone({ result, setResult }) {
        if (isAsyncIterable(result)) {
            return handleAsyncIterableResult(disabledResult);
        }
        return disabledResult(result, setResult);
    },
};

where disabledResult returns something like:

function disabledResult(result, setResult) {
    if (includeExtensionMetadata) {
        setResult(resultWithMetadata(result, { hit: false, didCache: false, enabled: false }));
    }
} 

This gets us most of the way there, but there is still one bit of metadata related to the response cache plugin that for some reason gets set from the graphql yoga package. I believe this is the case when there is a cache hit.

So we'd need to modify this line to include enabled: true

The fact that this metadata is spread across multiple projects is a bit surprising so let me know if I've missed something. If you agree with all of this, I can go ahead and get the 2 PRs ready -- one for this project and one for graphql yoga. Not really sure how to coordinate releases.

@ardatan
Copy link
Collaborator

ardatan commented May 20, 2024

I am not sure if we really need an extension metadata when it is disabled.
Because when it is enabled, we always have the extension metadata so it means it is enabled.
If the metadata doesn't exist, it means it is disabled.

@n1ru4l
Copy link
Owner

n1ru4l commented May 20, 2024

Unless there is another reason on why we dould need this new field, I agree with @ardatan. Afaik dows not provide any additional value over checking whether the extendion field exists.

@mmadson
Copy link
Author

mmadson commented May 20, 2024

@ardatan honestly, I didn't even think about using the presence of the root metadata node to detect if caching was or wasn't enabled -- so now that you mention it, I suppose you are right, that would be sufficient. Thanks for taking the time to consider this issue, feel free to consider it resolved.

@EmrysMyrddin EmrysMyrddin closed this as not planned Won't fix, can't repro, duplicate, stale May 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants