Skip to content

Instantly share code, notes, and snippets.

@Loschcode
Created March 19, 2019 22:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Loschcode/df6894ceed46cfd59965a9f6643def22 to your computer and use it in GitHub Desktop.
Save Loschcode/df6894ceed46cfd59965a9f6643def22 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 = (
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