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

hyperapp-apollo

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hyperapp-apollo

Apollo/GraphQL integration for Hyperapp

  • 0.4.0
  • latest
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

hyperapp-apollo

NPM version Maintainability

Hyperapp Apollo allows you to fetch data from your GraphQL server and use it in building complex and reactive UIs using the Hyperapp framework.

Demo

Installation

If your project is using npm, you can install hyperapp-apollo package by npm command:

# installing the preset package and hyperapp integration
npm install --save hyperapp-apollo apollo-client-preset graphql-tag graphql

# installing each piece independently
npm install --save hyperapp-apollo apollo-client apollo-cache-inmemory apollo-link-http graphql-tag graphql

Distribution files

  • dist/index.js - The CommonJS version of this package. (default)
  • dist/index.mjs - The ES Modules version of this package.
  • dist/hyperapp-apollo.js, dist/hyperapp-apollo.min.js - The UMD version of this package. This version exports itself to window.HyperappApollo.

Usage

Add the apollo module to your state and actions and start your application.

import { apollo } from "hyperapp-apollo"
import { ApolloClient } from "apollo-client-preset"

const state = {
  apollo: {
    ...apollo.state,
    client: new ApolloClient()
  }
}

const actions = {
  apollo: apollo.actions
}

app(
  state,
  actions,
  (state, actions) => <MyComponent />,
  document.body
)

To connect your GraphQL data to your Hyperapp module, use <Query/> component:

import { Query } from "hyperapp-apollo"
import gql from "graphql-tag"

const TODO_APP_QUERY = gql`
  query TodoAppQuery($userId: Int!) {
    todos(userId: $userId) {
      id
      text
    }
  }
`

export const TodoApp = ({ userId }) => (
  <Query
    key={`todoApp-${userId}`}
    query={TODO_APP_QUERY}
    variables={{
      userId
    }}
    render={({ data, loading, refetch }) => (
      <div>
        { loading ?
          <div>loading...</div>
        :
          <div>
            <button onclick={refetch}>Refresh</button>
            <ul>
              {data && data.todos && data.todos.map(todo =>
                <li key={todo.id}>{todo.text}</li>
              )}
            </ul>
          </div>
        }
      </div>
    )}
  />
}

Keywords

FAQs

Package last updated on 08 Apr 2018

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