]>
Commit | Line | Data |
---|---|---|
c1bc5993 | 1 | import { ApolloError } from '@apollo/client/core'; |
38416066 | 2 | import { readable } from 'svelte/store'; |
c1bc5993 RBR |
3 | import { client } from '$config/apollo'; |
4 | import { GET_FORUMS } from '$data/queries'; | |
890274a7 | 5 | |
e749c95b BB |
6 | const internals = { |
7 | ||
e749c95b BB |
8 | // The exported data structure |
9 | ||
c1bc5993 RBR |
10 | initialValue: { |
11 | loading: true, | |
12 | data: [], | |
13 | error: undefined | |
14 | } | |
15 | }; | |
e749c95b | 16 | |
c1bc5993 | 17 | export const forums = readable(internals.initialValue, (set) => { |
e749c95b | 18 | |
c1bc5993 | 19 | client.watchQuery({ query: GET_FORUMS }).subscribe((result) => { |
e749c95b | 20 | |
c1bc5993 RBR |
21 | if (result.errors) { |
22 | const error = new ApolloError({ graphQLErrors: result.errors }); | |
23 | return set({ | |
24 | loading: false, | |
25 | data: [], | |
26 | error | |
27 | }); | |
e749c95b | 28 | } |
890274a7 | 29 | |
c1bc5993 RBR |
30 | set({ |
31 | loading: false, | |
32 | data: result.data.forums, | |
33 | error: undefined | |
34 | }); | |
35 | }); | |
38416066 | 36 | }); |