I am trying to return a authentication token in response to a graphql query with username and password as arguments, but somehow graphql is always returning null
. I am able to print the token just before returning it.
var {
GraphQLObjectType,
GraphQLInt,
GraphQLList,
GraphQLString,
GraphQLSchema
} = require('graphql');
let MyUser = require('./modules/user/user');
const Query = new GraphQLObjectType({
name: 'Query',
description : 'UserQuery',
fields: function(){
return {
Token :{
type: GraphQLString,
description : "Authentication token",
args: {
user_name: { type: GraphQLString },
password: { type: GraphQLString },
},
resolve(root, args){
let user = new MyUser();
user.authenticateUser(args.user_name, args.password, function(result){
console.log("token :"+result);
return result;
})
}
}
}
}
});
const Schema = new GraphQLSchema({
query: Query
});
module.exports = Schema;
Query look like
query{
Token(user_name: "Thurman.Cassin@hotmail.com"
password: "abc123")
}
Result
{
"data": {
"Token": null
}
}
what I am doing wrong here ?