For more information on React Komposer, see here.
npm install --save react-komposer-query react-komposer apollo-client
react-komposer and apollo-client are peerDependencies of react-komposer-query
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);