Socket
Book a DemoInstallSign in
Socket

react-apollo-typed-hooks

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-apollo-typed-hooks

Wrappers for Apollo's React hooks with simplified typings

1.0.0
latest
Source
npmnpm
Version published
Maintainers
1
Created
Source

react-apollo-typed-hooks

Wrappers for Apollo's React hooks with simplified typings.

Usage

tl;dr:

  • Extend Mutation or Query with type parameters for the shapes of the result data and the allowed parameters for each query or mutation allowed by your application.
  • Instantiate the classes with the query to execute.
  • Use useQuery and useMutation with the same API provided by @apollo/react-hooks, but pass the instance instead of the query node. You'll get detailed type information for all query and mutation variables and results.
import * as React from "react";
import gql from "graphql-tag";
import { Query, useQuery } from "react-apollo-typed-hooks";

const QUERY = gql`
  query {
    testQuery {
      ok
    }
  }
`;

class TestQuery extends Query<{ testQuery: { ok: boolean } }, {}> {}

const q = new TestQuery(QUERY);

export const Component = () => {
  const { data } = useQuery(q);

  return <div>{data?.testQuery?.ok && `${data.testQuery.ok}`</div>;
};

Copyright © 2020 Jesse B. Hannah. Licensed under the MIT License.

FAQs

Package last updated on 02 Mar 2020

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

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.