Skip to content

Instantly share code, notes, and snippets.

@thisismydesign
Last active March 27, 2022 19:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thisismydesign/3b9d5814fa47e62b9b20fc03bbf61aab to your computer and use it in GitHub Desktop.
Save thisismydesign/3b9d5814fa47e62b9b20fc03bbf61aab to your computer and use it in GitHub Desktop.
Typed GraphQL queries and results /2 Typed client
import { ApolloClient, gql, InMemoryCache, QueryOptions } from '@apollo/client';
import {
Zeus,
ValueTypes,
ModelTypes,
GraphQLTypes,
InputType,
} from './types/zeus';
const client = new ApolloClient({
uri: 'http://localhost:3000/graphql',
cache: new InMemoryCache(),
});
const typedQuery = <Z extends ValueTypes[O], O extends 'Query'>(
query: Z | ValueTypes[O],
operationName?: string,
) => {
return client.query<InputType<GraphQLTypes[O], Z>>({
query: gql(Zeus('query', query, operationName)),
});
};
export default typedQuery;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment