Skip to content

A GraphQL server with JWT authentication and MongoDB implementation written in Go.

Notifications You must be signed in to change notification settings

jz222/go-graphql-api-template

Repository files navigation

Go GraphQL Server Template

Scalable web server written in Go that uses JWT's for authentication and MongoDB to persist data. The GraphQL endpoint is /graphql. The schemas for the implemented mutations and query can be found below. Since certain features like enforcing a certain password strength are not implemented yet, please use it with caution.

Usage

Add an .env file according to the .example.env file. Install dependencies with the command go get and start the server with go run main.go in the root folder.

SignUp Mutation

mutation {
  signUp(
    input: {
      email: "[email protected]"
      firstName: "Some"
      lastName: "User"
      password: "example"
    }
  ) {
    token
  }
}

Login Mutation

mutation {
  Login(
    input: {
      email: "[email protected]"
      password: "example"
    }
  ) {
    token
  }
}

Access Protected Resolvers

Add an Authorization header with a valid JWT as bearer token to the request. The following protected query can only be accessed if a valid JWT is provided.

query {
  protected {
    message
  }
}

About

A GraphQL server with JWT authentication and MongoDB implementation written in Go.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages