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

programmatic-query

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

programmatic-query

Query component for programmatic react-apollo queries.

  • 0.0.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

programmatic-query

Alternative Query component for react-apollo to make manually fired queries less painful.

See the example use case different between react-apollo and programmatic-query here.

Setup

Install

yarn add programmatic-query
# or
npm install programmatic-query

Usage

import { Query } from "programmatic-query";

Query Props

The follow props are identical in use to the Query component in react-apollo:

  • skip
  • query
  • variables
  • onError
  • onCompleted
  • errorPolicy
  • fetchPolicy

Read more about these props here.

children - function

A render prop to return a UI based on the query executed on component mount.

Configurable to allow the execution of the query to be handled by a seperate event other than the component mount.

To switch between the result only and with query handler behavior, pass a parameter name for the query handler to allow the query to be fired when the handler is invoked. Otherwise to use the default behavior, omit the second render prop argument and the query will be fired on component mount.

Render Prop - RESULT ONLY

Query is fired immediately upon component mount with any passed configuration to the Query component:

const App = () => (
  <Query
    query={gql`
      {
        allTodos {
          id
          text
        }
      }
    `}
  >
    {({ data, error, loading, networkStatus }) => (
      <Component>
        {data && data}
        {error && error}
        {loading && "Loading.."}
      </Component>
    )}
  </Query>
);

See children prop here

Render Prop - WITH QUERY HANDLER
const App = () => (
  <Query
    query={gql`
      {
        allTodos {
          id
          text
        }
      }
    `}
  >
    {({ data, error, loading, networkStatus }, fetchAllTodos) => (
      <Component>
        {data && data}
        {error && error}
        {loading && "Loading.."}
        <Button onPress={() => fetchAllTodos()}>Fetch All Todos</Button>
      </Component>
    )}
  </Query>
);

fetchOnMount - boolean

Specify if the query is fired on component mount even when a query handler is passed. Useful to easily fetch data on load, and allow a refetch via the query handler.

Uses the variables passed as the query prop as the variable argument.

Keywords

FAQs

Package last updated on 28 Jan 2019

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