Last active
March 27, 2022 19:47
-
-
Save thisismydesign/3b9d5814fa47e62b9b20fc03bbf61aab to your computer and use it in GitHub Desktop.
Typed GraphQL queries and results /2 Typed client
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 { 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