fenos / graphql-thinky

GraphQL & Relay powered by thinky / RethinkDB. https://graphql-thinky.readme.io/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Authorization and Mutations

ARMGAMES opened this issue · comments

Hey, i am sorry for noob question, but can you please describe how can i validate authorization at resolve function? I use JWT tokens.

And how i must use mutation with graphql-thinky library?

Thank you for any reply.

@ARMGAMES no problem for the question,

You can handle Authorization/Authentication checks from the before function into the resolver option, or you can do the check into the resolver it self as following:

userQuery.js

import GT from './graphql-thinky';
const {resolve} = GT;

users: {
  type: new GraphQLList(UserType),
  resolve: (parent, args,context,info) => {
     
     // You should had passed a User object into the context
     // and in your resolver you can just make a check
     if (context.user) {
        return resolve('user')(parent, args,context,info);
     }
     return null;
  }
}

Regarding Mutations the library doesn't have any helper yet. So you would create a GraphQL mutation exactly how you would with the normal GraphQL implementation.