jotai-apollo
Advanced tools
Comparing version
import * as jotai_vanilla from 'jotai/vanilla'; | ||
import { Getter, WritableAtom } from 'jotai/vanilla'; | ||
import { ApolloClient, OperationVariables, ApolloQueryResult, QueryOptions, DefaultContext, FetchResult, MutationOptions, SubscriptionOptions, SubscriptionResult } from '@apollo/client'; | ||
import { ApolloClient, OperationVariables, ApolloQueryResult, WatchQueryOptions, DefaultContext, FetchResult, MutationOptions, SubscriptionOptions, SubscriptionResult } from '@apollo/client'; | ||
declare const clientAtom: jotai_vanilla.WritableAtom<ApolloClient<unknown>, [client: ApolloClient<unknown>], void>; | ||
declare type QueryArgs<Variables extends object = OperationVariables, Data = any> = QueryOptions<Variables, Data>; | ||
declare type QueryArgs<Variables extends object = OperationVariables, Data = any> = WatchQueryOptions<Variables, Data>; | ||
declare type AtomWithQueryAction = { | ||
@@ -9,0 +9,0 @@ type: 'refetch'; |
@@ -91,17 +91,3 @@ // src/clientAtom.ts | ||
var atomsWithQuery = (getArgs, getClient = (get) => get(clientAtom)) => { | ||
return createAtoms(getArgs, getClient, (client, args) => { | ||
return { | ||
subscribe: (observer) => { | ||
client.query(args).then((result) => { | ||
var _a; | ||
(_a = observer.next) == null ? void 0 : _a.call(observer, result); | ||
}).catch((error) => { | ||
var _a; | ||
(_a = observer.error) == null ? void 0 : _a.call(observer, error); | ||
}); | ||
return { unsubscribe: () => { | ||
} }; | ||
} | ||
}; | ||
}, (action, _client, refresh) => { | ||
return createAtoms(getArgs, getClient, (client, args) => client.watchQuery(args), (action, _client, refresh) => { | ||
if (action.type === "refetch") { | ||
@@ -108,0 +94,0 @@ refresh(); |
{ | ||
"name": "jotai-apollo", | ||
"version": "0.2.0", | ||
"version": "0.2.1", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "type": "module", |
@@ -17,3 +17,3 @@ # Jotai Apollo 🚀👻 | ||
`atomsWithQuery` creates two atoms with a query. It internally uses [client.query](https://www.apollographql.com/docs/react/api/core/ApolloClient/#ApolloClient.query). | ||
`atomsWithQuery` creates two atoms with a query. It internally uses [client.watchQuery](https://www.apollographql.com/docs/react/api/core/ApolloClient/#ApolloClient.watchQuery). | ||
@@ -20,0 +20,0 @@ ```ts |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
39610
-4.23%334
-7.73%