Created
June 9, 2019 21:33
-
-
Save johansmitsnl/07d39f452cab2e6a2d4cabf84b7f0946 to your computer and use it in GitHub Desktop.
Typescript vue apollo
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 {Vue, Component} from "vue-property-decorator"; | |
import {user} from "packs/types/user"; | |
@Component({ | |
apollo: { | |
user: { | |
query: require('../graphql/user.graphql'), | |
loadingKey: 'loading', | |
subscribeToMore: { | |
document: require('../graphql/user_updates.graphql'), | |
updateQuery: (previousResult, {subscriptionData}) => { | |
if (previousResult.id === subscriptionData.data.profileUpdated.id) { | |
return { | |
user: subscriptionData.data.profileUpdated | |
} | |
} | |
}, | |
}, | |
update(data): user { | |
return data.user | |
}, | |
// Optional result hook | |
result({data, loader, networkStatus}) { | |
this.loading = false; | |
}, | |
// Error handling | |
error(error) { | |
console.error('We\'ve got an error!', error) | |
}, | |
} | |
}, | |
}) | |
export default class App extends Vue{ | |
user: user = <user> {}; | |
loading: boolean = true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment