Giter Site home page Giter Site logo

graphql-auth's Introduction

GraphQL Authentication built with ApolloServer and SequelizeORM

Mutation for registering a user

mutation {
  registerUser(username: "johndoe", email: "[email protected]", password: "wizzyekpot" ){
    token
  }
}

We should get something like this:

{
  "data": {
    "registerUser": {
      "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MSwiZW1haWwiOiJzaW1peXV3aXJlQGdtYWlsLmNvbSIsImlhdCI6MTYwNjM3NjkzMSwiZXhwIjoxNjA2NDYzMzMxfQ.mJyxkUlDevOaS2Wy-GKlZrQPOVjOnippPwtXTDTfToI"
    }
  }
}

Mutation for login

Let’s now log in with the user details we just created:

mutation {
  login(email:"[email protected]" password:"123456"){
    token
  }
}

We should get something like this:

{
  "data": {
    "login": {
      "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MSwiZW1haWwiOiJzaW1peXV3aXJlQGdtYWlsLmNvbSIsImlhdCI6MTYwNjM3NjkzMSwiZXhwIjoxNjA2NDYzMzMxfQ.mJyxkUlDevOaS2Wy-GKlZrQPOVjOnippPwtXTDTfToI"
    }
  }
}

Query for a single user

For us to query a single user, we need to pass the user token as authorization header. Go to the HTTP Headers tab. …and paste this:

{
  "Authorization": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MSwiZW1haWwiOiJzaW1peXV3aXJlQGdtYWlsLmNvbSIsImlhdCI6MTYwNjM3NjkzMSwiZXhwIjoxNjA2NDYzMzMxfQ.mJyxkUlDevOaS2Wy-GKlZrQPOVjOnippPwtXTDTfToI"
}

Here’s the query:

query myself{
  me {
    id
    email
    username
  }
}

And we should get something like this:

{
  "data": {
    "me": {
      "id": 1,
      "email": "[email protected]",
      "username": "johndoe"
    }
  }
}

Get a user by ID

query singleUser{
  user(id:1){
    id
    email
    username
  }
}

The query to get all users

{
  allUsers{
    id
    username
    email
  }
}

graphql-auth's People

Contributors

raywire avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.