fenos / graphql-thinky

GraphQL & Relay powered by thinky / RethinkDB. https://graphql-thinky.readme.io/
MIT License
75 stars 10 forks source link

Authorization and Mutations #15

Closed ARMGAMES closed 7 years ago

ARMGAMES commented 7 years ago

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.

fenos commented 7 years ago

@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.