Skip to content

ViggoValfridsson/JavaScript-Backend-GraphQL-Apollo-Express

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Introduction

  • To start the server simply run the command "npm run start:dev"
  • The project includes dummy data
  • When performing update mutations you don't need to provide all arguments.

Query examples:

  • Query for all users and their posts:
query {
  users {
    name
    description
    id
    posts {
      title
      content
      id
    }
  }
}
  • Query for a specific user and their posts:
query {
  user(id: "1") {
    name
    id
    description
    posts {
      title
      content
      id
    }
  }
}
  • Query all posts and their authors:
query {
  posts {
    title
    content
    id
    user {
      name
      id
      description
    }
  }
}
  • Query a specific post and it's author:
query {
  post(id: "1") {
    title
    content
    id
    user {
      name
      id
      description
    }
  }
}

Mutation examples:

  • Create user:
mutation {
  userCreate(user: { name: "New user", description: "New description" }) {
    user {
      name
      id
      description
      posts {
        title
      }
    }
    userErrors {
      message
    }
  }
}
  • Update user:
mutation {
  userUpdate(id: "1", user: { name: "Viggo Updated", description: "Updated description" }) {
    userErrors {
      message
    }
    user {
      description
      id
      name
      posts {
        title
        content
      }
    }
  }
}
  • Delete user:
mutation {
  userDelete(id: "1") {
    user {
      name
      id
      description
      posts {
        title
        content
      }
    }
    userErrors {
      message
    }
  }
}
  • Create a new post:
mutation {
  postCreate(post: { title: "New post", content: "New content", authorId: "2" }) {
    post {
      title
      content
      id
      user {
        name
        description
        id
      }
    }
    userErrors {
      message
    }
  }
}
  • Update post:
mutation {
  postUpdate(post: { title: "New title", content: "New content", authorId: "2" }, id: "1") {
    userErrors {
      message
    }
    post {
      title
      id
      content
      user {
        name
        id
      }
    }
  }
}
  • Delete post:
mutation {
  postDelete(id: "1") {
    userErrors {
      message
    }
    post {
      title
      content
      id
      user {
        name
        id
      }
    }
  }
}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published