]> git.r.bdr.sh - rbdr/forum/blobdiff - src/stores/forum.js
Update dependencies
[rbdr/forum] / src / stores / forum.js
index e7d335e14b0c7b729e3f0fc95a1ee5840821650f..a4a66a55b723a8aaac73f20980dbd08985f21e4e 100644 (file)
@@ -1,39 +1,4 @@
-import { ApolloError } from '@apollo/client/core';
-import { readable } from 'svelte/store';
-import { client } from '$config/apollo';
-import { GET_FORUM } from '$data/queries';
+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 } });