Created
March 19, 2019 22:09
-
-
Save Loschcode/bb7381ae5989ea525d2b96760e43773a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import gql from 'graphql-tag' | |
import EventsService from '@/services/EventsService' | |
import _ from 'lodash' | |
const CurrentIdentity = gql` | |
query CurrentIdentity { | |
currentIdentity { | |
id | |
role | |
token | |
firstName | |
lastName | |
} | |
} | |
` | |
const updateQuery = ( | |
previousResult, | |
{ | |
subscriptionData: { | |
data: { subscribeToCurrentIdentity: { currentIdentity } } | |
} | |
} | |
) => { | |
delete currentIdentity['__typename'] | |
this.currentIdentityInput = currentIdentity | |
} | |
export const currentIdentity = { | |
query: CurrentIdentity, | |
subscribeToMore: { | |
document: gql` | |
subscription SubscribeToBullshit { | |
subscribeToCurrentIdentity { | |
currentIdentity { | |
firstName | |
lastName | |
} | |
} | |
} | |
`, | |
updateQuery, | |
}, | |
result ({ data: { currentIdentity } }) { | |
this.currentIdentity = currentIdentity | |
return currentIdentity | |
}, | |
error (error) { | |
new EventsService(this).crash( | |
'We were unable to retrieve the current identity' | |
) | |
}, | |
skip () { | |
return this.identityToken == null | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment