react-komposer-query

0.0.5 • Public • Published

Apollo Query for React Komposer

For more information on React Komposer, see here.

Installation

npm install --save react-komposer-query react-komposer apollo-client

react-komposer and apollo-client are peerDependencies of react-komposer-query

Usage

In configs/context.js:

import * as Collections from '../../lib/collections';
import { Meteor } from 'meteor/meteor';
import { FlowRouter } from 'meteor/kadira:flow-router-ssr';
import { Tracker } from 'meteor/tracker';
import { configureGraphQLClient } from 'apollo-tools';

export default function () {
  const Client = configureGraphQLClient({
    url: '/graphql',
  });

  return {
    Meteor,
    FlowRouter,
    Collections,
    Tracker,
    Client, // make sure to supply this
  };
}

Here's an example of a Mantra container:

import TodoList from '../../components/todo-list';
import composeWithQuery from 'react-komposer-query';
import { useDeps, composeAll } from 'mantra-core';

const options = {
  query: `
    query todos($type: TodoType) {
      allTodos(type: $type) {
        _id
        todo
        createdAt
      }
    }
  `,
  variables: {
    type: 'ACTIVE'
  }
};

const resultMapper = ({
  data,
  errors,
}) => {
  const {
    allTodos,
  } = data;

  return {
    todos: allTodos,
    errors,
  };
};


export default composeAll(
  composeWithQuery(options, resultMapper),
  useDeps()
)(TodoList);

Readme

Keywords

none

Package Sidebar

Install

npm i react-komposer-query

Weekly Downloads

3

Version

0.0.5

License

MIT

Last publish

Collaborators

  • sammkj