react-apollo-graphqls
TypeScript icon, indicating that this package has built-in type declarations

1.0.3 • Public • Published

Graphqls

Tiny wrapper around react-apollo's graphql container, with support for multiple queries with a single call.

Install

$ npm install --save react-apollo-graphqls

Usage

The standard react-apollo's graphql container requires a GraphQL query as the first argument, and an optional options object as the second.

This function simply requires a single object, with the GraphQL query being under the gql property of it. This enables calling it only once but with multiple queries.

import gql from 'graphql-tag';
import * as React from 'react';
import graphqls from 'react-apollo-graphql';
 
const user = {
  gql: gql`
    query CurrentUserForLayout {
      currentUser {
        login
        avatar_url
      }
    }
  `,
  options: {
    fetchPolicy: 'network-only'
  }
};
 
const categories = {
  gql: gql`
    query Categories {
      categories {
        _id
        name
        description
      }
    }
  `,
  withRef: true
};
 
@graphqls ( user, categories )
class Example extends React.Component {}
 
export {Example};

License

MIT © Fabio Spampinato

Readme

Keywords

Package Sidebar

Install

npm i react-apollo-graphqls

Weekly Downloads

1

Version

1.0.3

License

MIT

Unpacked Size

6.9 kB

Total Files

11

Last publish

Collaborators

  • fabiospampinato