Skip to content

Instantly share code, notes, and snippets.

@Loschcode
Created March 19, 2019 22:09
Show Gist options
  • Save Loschcode/e0b298c21e03cd9e9e7e44caa02d51d9 to your computer and use it in GitHub Desktop.
Save Loschcode/e0b298c21e03cd9e9e7e44caa02d51d9 to your computer and use it in GitHub Desktop.
import gql from 'graphql-tag'
import EventsService from '@/services/EventsService'
import _ from 'lodash'
const CurrentIdentity = gql`
query CurrentIdentity {
currentIdentity {
id
role
token
email
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