Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@graphql-codegen/typescript-react-query

Package Overview
Dependencies
Maintainers
4
Versions
444
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@graphql-codegen/typescript-react-query

GraphQL Code Generator plugin for generating a ready-to-use React-Query Hooks based on GraphQL operations

  • 6.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
161K
increased by19.23%
Maintainers
4
Weekly downloads
 
Created

What is @graphql-codegen/typescript-react-query?

@graphql-codegen/typescript-react-query is a plugin for GraphQL Code Generator that generates TypeScript types and React Query hooks from your GraphQL schema and operations. This allows you to seamlessly integrate GraphQL queries and mutations into your React applications using React Query, providing type safety and reducing boilerplate code.

What are @graphql-codegen/typescript-react-query's main functionalities?

Generate TypeScript Types

This configuration generates TypeScript types for your GraphQL schema and operations. The generated types ensure type safety when working with GraphQL queries and mutations in your React application.

```json
{
  "schema": "https://my-graphql-endpoint.com/schema",
  "documents": "src/graphql/**/*.graphql",
  "generates": {
    "src/generated/graphql.tsx": {
      "plugins": [
        "typescript",
        "typescript-operations",
        "typescript-react-query"
      ]
    }
  }
}
```

Generate React Query Hooks

This code sample demonstrates how to use the generated React Query hooks for fetching and mutating data. The `useGetUserQuery` hook is used to fetch user data, and the `useCreateUserMutation` hook is used to create a new user.

```typescript
import { useGetUserQuery, useCreateUserMutation } from './generated/graphql';

const UserComponent = () => {
  const { data, error, isLoading } = useGetUserQuery({ id: '1' });
  const mutation = useCreateUserMutation();

  if (isLoading) return <div>Loading...</div>;
  if (error) return <div>Error: {error.message}</div>;

  return (
    <div>
      <h1>{data.user.name}</h1>
      <button onClick={() => mutation.mutate({ name: 'New User' })}>Create User</button>
    </div>
  );
};
```

Other packages similar to @graphql-codegen/typescript-react-query

FAQs

Package last updated on 02 Feb 2024

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc