Skip to content

Instantly share code, notes, and snippets.

@youknowriad
Created January 7, 2017 10:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save youknowriad/040cc372cb4c134cfbe377e1ef73ec64 to your computer and use it in GitHub Desktop.
Save youknowriad/040cc372cb4c134cfbe377e1ef73ec64 to your computer and use it in GitHub Desktop.
GraphQL setup
const createGraph = store => {
// A GraphQL schema (used to validate the data)
const schema = `
type Todo {
id: Int,
text: String,
done: Boolean
}
type Query {
todos: [Todo]
}
`;
// The resolver of our todos tree node
const todosResolver = () => {
// Trigger the fetch action creator
const state = store.getState();
const todos = getTodos( state );
if ( ! todos ) store.dispatch( fetchTodos() );
// Return retrieved data from the store
return todos;
};
// The root of our GraphQL setup
const root = {
hello: () => 'hello world',
todos: todosResolver,
// Append any other todos here
};
return {
schema,
root
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment