typed-graphqlify is a TypeScript library designed to streamline the process of building GraphQL queries by providing a single source of truth for both the GraphQL query structure and its corresponding TypeScript types. It eliminates the common problem of redundancy found in many GraphQL client setups where developers must define a GraphQL query string and then separately define a matching TypeScript interface. The library, currently at version 3.1.6, generally sees minor updates every few weeks to months, focusing on dependency updates and minor feature enhancements. Its core differentiator lies in its ability to generate GraphQL query strings and strong TypeScript types directly from a GraphQL-like JavaScript object structure, using dedicated `types` helpers for scalar and optional fields. It primarily acts as a query builder, providing the necessary string for execution, but does not handle the network request itself, integrating seamlessly with existing GraphQL clients like Apollo or Relay for actual data fetching.
npm install typed-graphqlifyVerified import paths — ran on the pinned version, not inferred.
This example demonstrates how to define a typed GraphQL query, generate its string representation, and type-safely consume its result.
Integrate `typed-graphqlify` with an existing GraphQL client or an HTTP request library for query execution.
Always use the `types` helpers provided by the library to correctly define the data types for your GraphQL fields. Refer to the documentation for specific usage of `types.oneOf` for enums and `types.array` for lists.
Replace `types.enum` with `types.oneOf` and provide an array of possible values or a plain object mapping, e.g., `status: types.oneOf(['ACTIVE', 'INACTIVE'])`.
Call the `.toString()` method on your generated query object to convert it into a GraphQL string: `executeGraphql(myQuery.toString())`.
To infer the type of the GraphQL response data, use `typeof myQuery.data` (e.g., `const result: typeof myQuery.data = ...`). The `.data` property is a type-only construct.
Ensure you have correctly imported the required symbols using named imports: `import { query, types, alias } from 'typed-graphqlify';`.No dependency data recorded yet.