HoudiniGraphql / houdini

The disappearing GraphQL client

Home Page:http://www.houdinigraphql.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Changing session should refresh queries

endigma opened this issue · comments

Describe the feature

Some improvements should be made to the session handling in houdini, in particular the ability to invalidate session dependent queries would be cool. This may or may not be blocked by #891. The thread also discusses some "extra" stuff like being able to absorb an existing response payload and update the cache without the request, but that is likely out of scope for a single ticket.

Previously discussed here: https://discord.com/channels/1024421016405016718/1164588891605565440

Some quotes to try and summarize the issue, I'll clean this up later if I have time.

(endigma)
well perhaps if setSession handled persistence and reloads internally?
localStorage or a cookie or etc
probably a cookie so SSR works
maybe a plugin for checking like meta.authDependent or something for point 2?
or just rerun everything

(alec)
yea that's what I'm thinking too. since the logic has to be on the server, the simplest API is just to provide some function you call on the server to update the session. setSession is the best API - it doesn't exactly match the existing use but maybe it's okay having the one just because its easy to remember cc @jycouet

i think i'm going to wire it up to refresh all of the active queries (maybe we could explore some directive like @sessionless to say that a query doesn't depend on the session). I think it's the easiest to understand and it sets us up for being able to do something like to rerefresh a single entry in the cache

const user = cache.get('User', { id: "1"})

user.refresh()

(endigma)
i checked, it does set __houdini__session__ but does not rerun the necessary queries
am I correct in saying invalidateAll() does nothing to houdini queries
i've wired up a button that runs it and even after the session variable gets set invalidateAll button does not make any graphql requests

(alec)
yea re-running the queries will take some plumbing. the current channel between the cache and stores is just used to send data but now the cache needs to be able to "talk" to the active stores and send signals that they can respond to do to things

(alec) it's not gonna be that tricky - just gotta nest the current payload under some kind: 'update' and it opens up all sorts of neat things if we have more kinds of messages

(endigma)
could that be a signal sent by the server? so setSession does something to event.locals which causes a reload?

(alec)
no i'm thinking that's a separate part
something on the client will need to detect the changed state and retrigger the queries
we already do the detection to keep the client-side singleton in sync

(endigma)
i wonder if you could sort of pack this change into having houdini generally play nice with form actions, like if you could run a mutation on the server and plumb the result through to the client to update the cache if enhanced

(alec)
yea its the must-have escape hatch before we get into the fine-grained stuff

(alec)
ultimately I'd like to have a way for you to push abitrary updates from the server to the client and have it update the cache (ie, you just need to send the mutation payload back and move on)

(alec)
the biggest hurdle is that features like these need to take a lot of opinions that could conflict with people's setups. ie if we push the events from the server to the client via websockets then spa adapters don't work. so the trick is finding the right way to package it up so that users naturally fall into a pit of success but that's tricky

(alec)
so until we figure that bit out, we can just worry on the refreshing bit

Criticality

cool improvement, my projects will benefit from it