/graphql-directive-auth

GraphQL directive for handling auth :tada:

Primary LanguageJavaScriptMIT LicenseMIT

graphql-directive-auth

Version downloads PRs Welcome MIT License

Introduction

TODO

Table of Contents

Installation

yarn add graphql-directive-auth

Usage

  • set appSecret parameter with your secret to decode JWT token example:
const schema = makeExecutableSchema({
  typeDefs,
  resolvers,
  schemaDirectives: {
    isAuthenticated: isAuthenticated('your_secret_token'),
    hasRole: hasRole('your_secret_token'),
  },
});

Example queries:

TODO

Directive Parameters

  • '@isAuthenticated' - check if user is authenticated
  • '@hasRole(role: "user, admin")' - check if user is authenticated

TODO

if you use graphql-import then you need to add this definition on top of the schema:

directive @isAuthenticated on FIELD | FIELD_DEFINITION
directive @hasRole(role: String) on FIELD | FIELD_DEFINITION

Contributing

I would love to see your contribution. ❤️

For local development (and testing), all you have to do is to run yarn and then yarn dev. This will start the Apollo server and you are ready to contribute 🎉

Run yarn test (try --watch flag) for unit tests (we are using Jest)

LICENSE

The MIT License (MIT) 2018 - Luke Czyszczonik - mailto:lukasz.czyszczonik@gmail.com