0.0.7 • Published 5 years ago

graphql-suspense v0.0.7

Weekly downloads
10
License
ISC
Repository
-
Last release
5 years ago

GraphQL Suspense

Easily add suspense to your GraphQL app.

Warning, the React docs say that Suspense does not yet support data loading, so in the future there may be breaking changes & better options available.

npm.io

Install

yarn add graphql-suspense

# or

npm install graphql-suspense

Usage (Apollo)

import React, { Component, Suspense } from 'react'
import gqlsuspense from 'graphql-suspense'

// Define Apollo client
const client = new ApolloClient({
  uri: "<SOMEURI>"
})

class Data extends React.Component {
  render() {
    const data = gqlsuspense(client.query, { query: listTodos })
    return data.data.listTodos.items.map((t, i) => <p key={i}>Yo! {t.name}</p>)
  }
}

const App = () => (
  <Suspense fallback={<div>loading single...</div>}>
    <Data />
  </Suspense> 
)

Usage (AWS Amplify)

import React, { Component, Suspense } from 'react'
import gqlsuspense from 'graphql-suspense'
import { API, graphqlOperation } from 'aws-amplify'

class Data extends React.Component {
  render() {
    const data = gqlsuspense(API.graphql(graphqlOperation(listTodos)))
    return data.data.listTodos.items.map((t, i) => <p key={i}>Yo! {t.name}</p>)
  }
}

const App = () => (
  <Suspense fallback={<div>loading single...</div>}>
    <Data />
  </Suspense> 
)
0.0.7

5 years ago

0.0.6

5 years ago

0.0.5

5 years ago

0.0.4

5 years ago

0.0.3

5 years ago

0.0.1

5 years ago