Skip to content

bent/build-your-own-graphql-server

Repository files navigation

Demo project for the 'Build Your Own GraphQL Server In 10 Minutes' talk

  1. Run: yarn install node setup.js

Open server.js

  1. Add: const typeDefs = gql(schema)

     const server = new ApolloServer({
       typeDefs,
       resolvers
     })
    
     server.listen().then(() => console.log("Ready"))
    
  2. Open getAllTodos.gql

  3. Add to resolvers.js:

    getAllTodos() {
      return Todo.findAll();
    }
    
  4. Run yarn start

  5. Reload http://localhost:3000

  6. Open getTodo.gql

  7. Add to resolvers.js:

    getTodo(_, args) {
      return Todo.findById(args.id)
    }
    
  8. Reload http://localhost:3000, watch it die

  9. Add to resolvers.js:

    Todo: {
      subtasks(todo) {
        return todo.getSubtasks();
      }
    }
    
  10. Reload http://localhost:3000, watch it work

  11. Open createTodo.gql

  12. Add to resolvers.js:

    Mutation: {
      createTodo(_, {description}) {
        return Todo.create({description})
      }
    }
    
  13. Reload http://localhost:3000, add a todo

  14. Add to resolvers.js:

    deleteTodo(_, {id}) {
      return Todo.destroy({where: {id}}).then(() => {id})
    }
    
  15. Remove a todo

  16. Add to resolvers.js:

    createSubtask(_, {todoId, description}) {
      return Subtask.create({todoId, description})
    },
    deleteSubtask(_, {id}) {
      return Subtask.destroy({where: {id}}).then(() => {id})
    }
    

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published