Demo project for the 'Build Your Own GraphQL Server In 10 Minutes' talk
- Run: yarn install node setup.js
Open server.js
-
Add: const typeDefs = gql(schema)
const server = new ApolloServer({ typeDefs, resolvers }) server.listen().then(() => console.log("Ready"))
-
Open
getAllTodos.gql
-
Add to
resolvers.js
:getAllTodos() { return Todo.findAll(); }
-
Run
yarn start
-
Reload http://localhost:3000
-
Open
getTodo.gql
-
Add to
resolvers.js
:getTodo(_, args) { return Todo.findById(args.id) }
-
Reload http://localhost:3000, watch it die
-
Add to
resolvers.js
:Todo: { subtasks(todo) { return todo.getSubtasks(); } }
-
Reload http://localhost:3000, watch it work
-
Open
createTodo.gql
-
Add to
resolvers.js
:Mutation: { createTodo(_, {description}) { return Todo.create({description}) } }
-
Reload http://localhost:3000, add a todo
-
Add to
resolvers.js
:deleteTodo(_, {id}) { return Todo.destroy({where: {id}}).then(() => {id}) }
-
Remove a todo
-
Add to
resolvers.js
:createSubtask(_, {todoId, description}) { return Subtask.create({todoId, description}) }, deleteSubtask(_, {id}) { return Subtask.destroy({where: {id}}).then(() => {id}) }