-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],
- error: undefined
- });
- },
- (error: Error) => handleError(error)
- );
- }
- );
+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],
+ error: undefined
+ });
+ },
+ (error: Error) => handleError(error)
+ );
+ });