@rest-hooks/graphql
    TypeScript icon, indicating that this package has built-in type declarations

    0.1.7 • Public • Published

    Rest Hooks for GraphQL

    CircleCI Coverage Status npm downloads bundle size npm version PRs Welcome Chat

    GraphQL Endpoints for Rest Hooks

    Define GraphQL endpoint

    const gql = new GQLEndpoint('https://nosy-baritone.glitch.me');

    Simple TypeScript definition

    class User extends GQLEntity {
      readonly name: string = '';
      readonly email: string = '';
    }

    Write type-safe queries

    const userList = gql.query(
      `{
        users {
          id
          name
          email
          }
        }`,
      { users: [User] },
    );
    
    const userDetail = gql.query(
      `query UserDetail($name: String!) {
        user(name: $name) {
          id
          name
          email
        }
      }`,
      { user: User },
    );

    One line data-hookup

    const { user } = useResource(userDetail, { name: 'Fong' });
    return (
      <>
        <h2>{user.name}</h2>
        <p>{user.email}</p>
      </>
    );

    Mutations

    const gql = new GQLEndpoint('https://graphql.org/swapi-graphql');
    
    const createReview = gql.mutation(
      `mutation CreateReviewForEpisode($ep: Episode!, $review: ReviewInput!) {
        createReview(episode: $ep, review: $review) {
          stars
          commentary
        }
      }`,
      { createReview: Review },
    );
    const createReview = useFetcher(createReview);
    return <ReviewForm onSubmit={data => createReview(data)} />;

    Install

    npm i @rest-hooks/graphql

    DownloadsWeekly Downloads

    66

    Version

    0.1.7

    License

    Apache-2.0

    Unpacked Size

    69.4 kB

    Total Files

    29

    Last publish

    Collaborators

    • ntucker
    • ljharb