我是graphql的新手。我正在尝试获取已存储在数据库中的OAuth令牌。在这里,我将OAuth令牌与邮递员标题中给出的标题相匹配。
App.js file----
const express = require('express');
const graphqlHTTP = require('express-graphql');
const bodyParser = require('body-parser')
const schema = require('./schema/contentSchema');
// const schema = require('./schema/ex');
const oauthDb = require('./model/oauth_registration');
const jwt = require('jsonwebtoken');
const cors = require('cors');
const mysql = require('mysql');
const app = express();
app.use(cors());
// bodyparser
app.use(bodyParser.json());
app.use(bodyParser.text({ type: 'application/graphql' }));
var con = mysql.createConnection({
host: "localhost",
user: "root",
password: "upasana123",
database: "edocentdb"
});
app.use(tokenAccess);
app.use('/graphql/api',bodyParser.json(),graphqlHTTP({
schema,
rootValue: root,
}));
var authToken = "";
function tokenAccess(req,res,next){
if(req.headers['authorization']=='undefined'){
res.sendStatus(403);
}
else{
authToken = req.headers['authorization'];
if(authToken){
//SQL query for oauth Token--------
con.query("SELECT oauth_token,studio_id FROM oauth_registration where oauth_token = '"+authToken +"'", function (err, result, fields) {
if (err) throw err;
console.log( result);
result = result;
return result;
});
next();
}
}
}
// const rr = abc(res);
// console.log(rr.res);
app.listen(6000, () => {
console.log('now listening for requests on port 7000');
});
----------------------------------------------------------------------
----------------------------------------------------------------------
schema file ---------------
const Query = new GraphQLObjectType({
name: 'Query',
description: 'parent query object',
fields: () => {
return {
getContentDetails : {
type: new GraphQLList(Film),
args: {
id: {
type: GraphQLID
},
permalink: {
type: new GraphQLNonNull(GraphQLString)
},
content_types_id: {
type: new GraphQLNonNull(GraphQLString)
},
aouthToken: {
type: new GraphQLNonNull(GraphQLString)
},
},
resolve (parent, args, context,info) {
resolve: (parent, args, context, resolveInfo) => {
return joinMonster.default(resolveInfo, {}, sql => {
// console.log(resolveInfo);
return FilmDb.query(sql).then(function(result) {
return result[0];
});
},{dialect: 'mysql'});
}
},
当我点击URL时,它将同时在控制台中运行令牌查询和架构查询(getContentDetails)。但是它没有正确显示数据。它与oauth令牌的数据不匹配。它仅根据该参数中的参数传递来显示数据。
我该如何纠正??
我错过了什么吗?请帮助.....