A strongly-typed wrapper around graphql-tag that uses TypeScript module augmentation to automatically infer the types of your GraphQL queries, mutations, and subscriptions without manual type declarations. The current stable version is 0.1.16. It integrates seamlessly with Apollo Client hooks (useQuery, useMutation, etc.) and Apollo Server integration testing utilities. The library is minimal, focusing on type safety, and is actively maintained. Unlike alternatives, it does not require code generation or external tools; just install and your gql template literals become typed.
npm install graphql-tag-tsNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Shows how to define a typed GraphQL query using gql from graphql-tag-ts and use it with Apollo's useQuery, getting full type inference for data and variables.
Import gql from 'graphql-tag-ts' instead of 'graphql-tag'.
Manually type your queries if using non-augmented hooks.
Use @apollo/client and consider using graphql-tag-ts with module augmentation for @apollo/client (may need separate augmentation).
Always provide generic parameters: gql<Data, Variables>`...`.
Use manual typing or additional augmentations for other functions.
import { DocumentNode } from 'graphql-tag-ts';Use gql from graphql-tag-ts with generic parameters.
Remove type annotation; gql is a function, not a type.
Add generic type arguments to gql: gql<Data, Variables>`...`.