-
-
Save youknowriad/040cc372cb4c134cfbe377e1ef73ec64 to your computer and use it in GitHub Desktop.
GraphQL setup
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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