]> git.r.bdr.sh - rbdr/forum/blobdiff - src/stores/forums.js
Add stores for GraphQL data:
[rbdr/forum] / src / stores / forums.js
index ade01a7110e76ed0fa2c14d30e19ca7ba22d16e1..5cce7ba60f836584a8ecc1316c08626767a14229 100644 (file)
@@ -1,36 +1,4 @@
-import { ApolloError } from '@apollo/client/core';
-import { readable } from 'svelte/store';
-import { client } from '$config/apollo';
+import { store } from './apollo';
 import { GET_FORUMS } from '$data/queries';
 
-const internals = {
-
-  // The exported data structure
-
-  initialValue: {
-    loading: true,
-    data: [],
-    error: undefined
-  }
-};
-
-export const forums = readable(internals.initialValue, (set) => {
-
-  client.watchQuery({ query: GET_FORUMS }).subscribe((result) => {
-
-    if (result.errors) {
-      const error = new ApolloError({ graphQLErrors: result.errors });
-      return set({
-        loading: false,
-        data: [],
-        error
-      });
-    }
-
-    set({
-      loading: false,
-      data: result.data.forums,
-      error: undefined
-    });
-  });
-});
+export const forums = store({ key: 'forums', query: GET_FORUMS, initialValue: [] });