Created
September 4, 2020 01:44
-
-
Save GavinRay97/c24765e406a6376767ebae6414b6b836 to your computer and use it in GitHub Desktop.
GraphQL Zeus + Apollo Client typings integration
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { | |
ApolloProvider, | |
gql, | |
MutationHookOptions, | |
QueryHookOptions, | |
SubscriptionHookOptions, | |
useMutation, | |
useQuery, | |
useSubscription, | |
} from "@apollo/client"; | |
import {$, MapType, mutation_root, order_by, query_root, subscription_root, ValueTypes, Zeus,} from "./graphql-zeus"; | |
function useTypedQuery<Q extends ValueTypes["query_root"]>( | |
query: Q, | |
options?: QueryHookOptions<MapType<query_root, Q>, Record<string, any>> | |
) { | |
return useQuery<MapType<query_root, Q>>(gql(Zeus.query(query)), options); | |
} | |
function useTypedMutation<Q extends ValueTypes["mutation_root"]>( | |
mutation: Q, | |
options?: MutationHookOptions<MapType<mutation_root, Q>, Record<string, any>> | |
) { | |
return useMutation<MapType<mutation_root, Q>>( | |
gql(Zeus.mutation(mutation)), | |
options | |
); | |
} | |
function useTypedSubscription<Q extends ValueTypes["subscription_root"]>( | |
subscription: Q, | |
options?: SubscriptionHookOptions< | |
MapType<subscription_root, Q>, | |
Record<string, any> | |
> | |
) { | |
return useSubscription<MapType<subscription_root, Q>>( | |
gql(Zeus.subscription(subscription)), | |
options | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment