0.1.0 • Published 6 years ago

graphql-proxy-client v0.1.0

Weekly downloads
6
License
MIT
Repository
github
Last release
6 years ago

graphql-proxy-client

Travis npm package Coveralls

Send proxied actions to arbitrary GraphQL endpoints.

Install

$ yarn add @pi-cubed/graphql-proxy-client

Usage

import React, { Component } from 'react';
import { render } from 'react-dom';
import { Put } from 'typed-ui';
import { Action, ProxyProvider } from '@pi-cubed/graphql-proxy-client';

const Demo = () => (
  <div>
    <h1>graphql-proxy-client Demo</h1>
    <ProxyProvider>
      <Action
        url="http://proxy-graphql.herokuapp.com"
        action="query Q { test }"
      >
        <Put />
      </Action>
    </ProxyProvider>
  </div>
);

render(<Demo />, document.querySelector('#demo'));

API

Members

withAction

TODO docs

Kind: global variable

Action ⇒ Component

Return component outputting the response of the GraphQL action.

Kind: global variable
Returns: Component - A component that displays the response from the action.

ParamTypeDescription
propsObjectThe component props.
props.urlstringThe GraphQL api endpoint.
props.actionstringThe GraphQL action.
props.schemaGraphQLSchemaThe schema for the GraphQL api.
props.onChangeonChangeThe data change handler.
props.clientApolloClientThe Apollo client.

Example (Display users' names from GraphQL API)

<ProxyProvider>
  <Action url="http://proxy-graphql.herokuapp.com" action="query Q { test }">
    <Put />
  </Action>
</ProxyProvider>

Action~onChange : function

This callback handles Action change events.

Kind: inner typedef of Action

ParamType
value*

ProxyProvider ⇒ Component

Return the children with an ApolloClient which defaults to point at http://proxy-graphql.herokuapp.com.

Kind: global variable
Returns: Component - An ApolloProvider with a custom client.

ParamTypeDescription
propsObjectThe component props.
props.uriApolloClientThe GraphQL endpoint.
props.clientApolloClientThe Apollo client.

Example (Display users' names from GraphQL API)

<ProxyProvider>
  <Action url="https://proxy-graphql.herokuapp.com" action="query Q { test }">
    <Put />
  </Action>
</ProxyProvider>

Maintainers

License

MIT © Pi Cubed