-
Notifications
You must be signed in to change notification settings - Fork 45
Handling user logout and registering gql tag #19
Conversation
import { registerGqlTag } from 'apollo-client/gql'; | ||
|
||
// register gql tag for queries | ||
registerGqlTag(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Stylistically I prefer not having comments that mainly repeat the code. In this case, I'd either assume the reader knows what a gql tag is or change the comment to maybe // setup query template literal tag
, probably former
Can you elaborate on #4 for user caching? I actually created buy own caching mechanism, but it's very silly. would love to have something more robust. |
Sure, something like this: USER_CACHE_MAX = 1000
cache = lruCache(config.userCacheMax || USER_CACHE_MAX)
// inside apollo options function
cacheEntry = cache.get req.headers.authorization
if cacheEntry.user
isExpired = cacheEntry.expiresAt < new Date()
if not isExpired
options.context = {user}
else
updateCache = (user) ->
cache.set req.headers.authorization,
user: user
expiresAt: // todo
cursor = Meteor.users.find({"services.resume.loginTokens.hashedToken": hashedToken})
user = await cursor.findOne()
if user
updateCache(user)
options.context = {user}
handle = cursor.observe
changed(newDoc, oldDoc): ->
if token expired
cache.del(req.headers.authorization)
handle.stop()
else
if cache.has req.headers.authorization
updateCache(newDoc)
else
handle.stop()
removed(oldDoc): ->
cache.del(req.headers.authorization)
handle.stop() |
@lorensr you are a star! Thank you! |
|
@stubailo what's the substitute? |
1 similar comment
@stubailo what's the substitute? |
Nevermind, ... But I liked the central approach ... Call me old fashioned :) |
4 similar comments
Nevermind, ... But I liked the central approach ... Call me old fashioned :) |
Nevermind, ... But I liked the central approach ... Call me old fashioned :) |
Nevermind, ... But I liked the central approach ... Call me old fashioned :) |
Nevermind, ... But I liked the central approach ... Call me old fashioned :) |
Oh, sh.t I'm in Eastern Europe in a mountain cottage on Edge connection, things always get interesting this way I guess. Sorry! Going offline now. |
This pull request handles: