aboutsummaryrefslogtreecommitdiff
path: root/src/lib/stores/apollo.ts
diff options
context:
space:
mode:
authorRuben Beltran del Rio <ruben@unlimited.pizza>2022-05-31 01:04:10 +0200
committerRuben Beltran del Rio <ruben@unlimited.pizza>2022-05-31 01:04:10 +0200
commit852ee620f0a2f6a83cf83eba860ca951b66bb7e2 (patch)
tree3b1db871625c89f08c3c6422c135f84ec116943b /src/lib/stores/apollo.ts
parentd2cd7f1b4c318ac8587ab3dc1dec4a44b6d592fe (diff)
Use supabase
Diffstat (limited to 'src/lib/stores/apollo.ts')
-rw-r--r--src/lib/stores/apollo.ts62
1 files changed, 0 insertions, 62 deletions
diff --git a/src/lib/stores/apollo.ts b/src/lib/stores/apollo.ts
deleted file mode 100644
index c75dd87..0000000
--- a/src/lib/stores/apollo.ts
+++ /dev/null
@@ -1,62 +0,0 @@
-import { ApolloError } from '@apollo/client/core';
-import { readable } from 'svelte/store';
-import { client } from '$lib/config/apollo';
-import type { DocumentNode, ApolloQueryResult } from '@apollo/client/core';
-
-import type { Readable } from 'svelte/store';
-
-/*
- * This is a generic store for use with apollo
- */
-
-type ApolloStoreConfiguration<Type> = {
- key: string;
- query: DocumentNode;
- initialValue?: Type | void;
- variables?: object;
-};
-
-type ApolloStoreState<Type> = {
- loading: boolean;
- data: Type | void;
- error: Error | void;
-};
-
-export const store = function store<Type>({
- key,
- query,
- initialValue = null,
- variables = {}
-}: ApolloStoreConfiguration<Type>): Readable<ApolloStoreState<Type>> {
- const initialState: ApolloStoreState<Type> = {
- loading: true,
- data: initialValue,
- error: undefined
- };
-
- return readable(initialState, (set) => {
- const handleError = function (error: Error) {
- return set({
- loading: false,
- data: initialValue,
- error
- });
- };
-
- client.watchQuery({ query, variables }).subscribe(
- (result: ApolloQueryResult<Type>) => {
- if (result.errors) {
- const error = new ApolloError({ graphQLErrors: result.errors });
- return handleError(error);
- }
-
- set({
- loading: false,
- data: result.data[key].edges.map((item) => item.node),
- error: undefined
- });
- },
- (error: Error) => handleError(error)
- );
- });
-};