
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
graphql-ts-codegen
Advanced tools
A TypeScript application that validates .graphql files against a GraphQL API schema and generates type-safe React hooks. It fetches the schema from a GraphQL endpoint, parses it, validates your queries, and generates ready-to-use TypeScript code.
✅ Fetch a GraphQL schema using an introspection query.
✅ Parse the schema into a usable TypeScript structure.
✅ Parse .graphql files into an Abstract Syntax Tree (AST).
✅ Validate .graphql files against the schema.
✅ Generate TypeScript type definitions based on GraphQL types.
✅ Create React Query hooks for all valid GraphQL operations.
✅ Bundle hooks and types into a clean, importable package.
| Stage | Description | Status |
|---|---|---|
| 1. Fetch GraphQL Schema | Fetch the schema from the GraphQL API using an introspection query. | ✅ Completed |
| 2. Parse Schema | Convert the raw introspection result into a TypeScript-friendly structure. | ✅ Completed |
| 3. Parse GraphQL Files | Convert .graphql files into an Abstract Syntax Tree (AST). | ✅ Completed |
| 4. Validate GraphQL Files | Compare parsed .graphql files with the schema for validation. | ✅ Completed |
| 5. Generate TypeScript Types | Create TypeScript interfaces based on GraphQL types. | ✅ Completed |
| 6. Create React Query Hooks | Generate custom hooks for each validated GraphQL operation. | ✅ Completed |
| 7. Error Handling & Edge Cases | Handle errors (e.g., invalid fields, missing arguments). | ✅ Completed |
| 8. Unit Tests | Write tests to ensure validation logic works correctly. | ❌ Not Started |
| 9. Optimization & Refactoring | Improve performance and code modularity. | 🚧 In Progress |
Schema Fetching: The application starts by fetching the GraphQL schema using an introspection query.
Query Parsing: Your .graphql files are parsed into an Abstract Syntax Tree (AST) structure that represents:
query, mutation, etc.)Validation: Parsed queries are validated against the schema to ensure they're correct.
Code Generation: For valid queries, the application generates:
Clone the repository:
git clone https://github.com/your-username/graphql-schema-validator.git
cd graphql-schema-validator
Install dependencies:
npm install
Add your GraphQL queries to the src/queries folder with .graphql extension.
Run the code generator:
npm run generate-hooks
Use the generated hooks in your React application:
import { useGetUser } from "./generated";
function UserProfile({ userId }) {
const { data, isLoading, error } = useGetUser({ id: userId });
if (isLoading) return <div>Loading...</div>;
if (error) return <div>Error: {error.message}</div>;
return <div>Name: {data.user.name}</div>;
}
After running the code generator, you'll have:
generated/
├── hooks/
│ ├── useQueryName1.ts
│ ├── useQueryName2.ts
│ └── ...
├── types.ts
├── graphqlClient.ts
└── index.ts
Starting with a GraphQL query:
query GetUser($id: ID!) {
user(id: $id) {
name
email
}
}
The generator produces:
// TypeScript interface for variables
export interface GetUserVariables {
id: string;
}
// TypeScript interface for response
export interface GetUserResponse {
user: {
name: string;
email: string;
};
}
// React Query hook
export const useGetUser = (
variables: GetUserVariables,
options?: UseQueryOptions<GetUserResponse, Error>
) => {
return useQuery<GetUserResponse, Error>(
["GetUser", variables],
() => graphqlRequest<GetUserResponse, GetUserVariables>(QUERY, variables),
options
);
};
This gives you fully type-safe access to your GraphQL API with minimal boilerplate code.
FAQs
GraphQL Schema Validator and TypeScript Hook Generator
We found that graphql-ts-codegen demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.