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

feat: add context to query #549

Merged
merged 2 commits into from
Oct 2, 2023
Merged

feat: add context to query #549

merged 2 commits into from
Oct 2, 2023

Conversation

Digni
Copy link
Contributor

@Digni Digni commented Sep 17, 2023

Add Context to useAsyncQuery and useLazyAsynQuery. Extended prep function to extract context and forward it to apollo client. This allows context configuration per query, e.g. custom headers.

Add Context to useAsyncQuery and useLazyAsynQuery.
Extended prep function to extract context and forward it to apollo client.
This allows context configuration per query, e.g. custom headers.
@netlify
Copy link

netlify bot commented Sep 17, 2023

Deploy Preview for apollo-module canceled.

Name Link
🔨 Latest commit 6a1bf0f
🔍 Latest deploy log https://app.netlify.com/sites/apollo-module/deploys/650966029286960008d29120

@Digni
Copy link
Contributor Author

Digni commented Sep 17, 2023

This should enable issue #508

@Diizzayy Diizzayy self-assigned this Sep 17, 2023
@Khaledhesham
Copy link

this is very useful can it get merged sooner

Co-authored-by: Daniel Roe <daniel@roe.dev>
@Kevintjuhz
Copy link

This would be very useful for us. Any updates?

@Diizzayy Diizzayy merged commit da75426 into nuxt-modules:v5 Oct 2, 2023
4 checks passed
@Kevintjuhz
Copy link

Thanks for merging, much appreciated.

@Digni Digni deleted the feature/add_context branch October 2, 2023 10:25
@Diizzayy
Copy link
Collaborator

Diizzayy commented Oct 2, 2023

@Digni @Kevintjuhz It'll be apart of the next minor release (coming shortly).

@gerbenvandijk
Copy link

gerbenvandijk commented Oct 8, 2023

@Diizzayy

Just tested this and it works nicely for my use (setting custom headers from within a global middleware).
However; it is required for me to set cache:false on my request.

If I don't - then useAsyncQuery will simply return the previously queried data and completely disregards that new request headers were set.

Is this intended? It feels like it would be useful to make the caching mechanism aware of changes in the newly added context :)

The same applies to the Apollo DevTools Chrome extension that can be enabled via connectToDevTools: true in nuxt.config.ts. It is also not aware of the new context and crashes.

@fosterdouglas
Copy link

Just tested this and it works nicely for my use (setting custom headers from within a global middleware). However; it is required for me to set cache:false on my request.

If I don't - then useAsyncQuery will simply return the previously queried data and completely disregards that new request headers were set.

Is this intended? It feels like it would be useful to make the caching mechanism aware of changes in the newly added context :)

The same applies to the Apollo DevTools Chrome extension that can be enabled via connectToDevTools: true in nuxt.config.ts. It is also not aware of the new context and crashes.

@gerbenvandijk Can you share where exactly you're setting cache: false ? I'm having the same issue.

@gerbenvandijk
Copy link

Just tested this and it works nicely for my use (setting custom headers from within a global middleware). However; it is required for me to set cache:false on my request.
If I don't - then useAsyncQuery will simply return the previously queried data and completely disregards that new request headers were set.
Is this intended? It feels like it would be useful to make the caching mechanism aware of changes in the newly added context :)
The same applies to the Apollo DevTools Chrome extension that can be enabled via connectToDevTools: true in nuxt.config.ts. It is also not aware of the new context and crashes.

@gerbenvandijk Can you share where exactly you're setting cache: false ? I'm having the same issue.

@fosterdouglas useAsyncQuery has a parameter for that:

    const { data } = await useAsyncQuery({
        query, // -> for me this is an imported .gql file
        cache, // -> true or false
        context: {
            headers: {} //  -> an object with my custom headers
        }
    })

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

Successfully merging this pull request may close these issues.

None yet

7 participants