Created
March 19, 2019 22:09
-
-
Save Loschcode/e0b298c21e03cd9e9e7e44caa02d51d9 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 = function ( | |
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