diff options
| author | Ruben Beltran del Rio <ruben@unlimited.pizza> | 2021-03-14 22:41:16 +0100 |
|---|---|---|
| committer | Ruben Beltran del Rio <ruben@unlimited.pizza> | 2021-03-14 22:41:16 +0100 |
| commit | 18ced3bfaff8ca40edb1a96e631ba1553a3a7a6d (patch) | |
| tree | 450ee3c84e7400e99ba30261e705b2db619d9bcf /src/stores/forum.js | |
| parent | c1bc5993a694f6fd047a3881351827058042483b (diff) | |
Add stores for GraphQL data:
Diffstat (limited to 'src/stores/forum.js')
| -rw-r--r-- | src/stores/forum.js | 39 |
1 files changed, 2 insertions, 37 deletions
diff --git a/src/stores/forum.js b/src/stores/forum.js index e7d335e..110da57 100644 --- a/src/stores/forum.js +++ b/src/stores/forum.js @@ -1,39 +1,4 @@ -import { ApolloError } from '@apollo/client/core'; -import { readable } from 'svelte/store'; -import { client } from '$config/apollo'; +import { store } from './apollo'; import { GET_FORUM } from '$data/queries'; -const internals = { - - // The exported data structure - - initialValue: { - loading: true, - data: null, - error: undefined - } -}; - -export const getForum = function forum(id) { - - return readable(internals.initialValue, (set) => { - - client.watchQuery({ query: GET_FORUM, variables: { id } }).subscribe((result) => { - - if (result.errors) { - const error = new ApolloError({ graphQLErrors: result.errors }); - return set({ - loading: false, - data: null, - error - }); - } - - set({ - loading: false, - data: result.data.forum, - error: undefined - }); - }); - }); -}; +export const getForum = (id) => store({ key: 'forum', query: GET_FORUM, variables: { id } }); |