0
私は既存のアプリケーションにgraphQLを追加しようとしています。 私は現在、psql db呼び出しでExpressエンドポイントを取り戻しています。 私は自分のデータにアクセスするためにpsqlを使用し、次にこれらのクエリの結果をgraphQLの '解決'に使用することを目指します。ここでgraphqlのpsqlから返されたデータを解決する
は、私はpsqlデシベルコールの例である:ここで
'use strict';
const config = require('../../config');
const PostgresDAO = require('core/src/server/db/dao/postgres');
const postgresRW = new PostgresDAO(config.postgresRW);
function getById(id) {
postgresRW.queryOne(
`
SELECT id, email, create_date
FROM gamesDB.players
WHERE id = $1;
`,
[id],
function(err, result) {
console.log(result);
return result;
}
);
}
module.exports = {
getById: getById
}
は私のgraphQLスキーマです:
'use strict';
const graphql = require('graphql');
const Player = require('./types/player');
const db = require('../db');
const RootQueryType = new graphql.GraphQLObjectType({
name: 'RootQueryType',
fields: {
player: {
type: Player,
description: 'The current player identified by an ID.',
args: {
key: {
type: new graphql.GraphQLNonNull(graphql.GraphQLString)
}
},
resolve: (obj, args) => {
return db.players.getById(args.key);
}
}
}
});
const testSchema = new graphql.GraphQLSchema({
query: RootQueryType
});
module.exports = testSchema;
問題は、私はからプレイヤーを照会するたびとしての私の決意にあるように思われますgraphiqlインターフェイス内では、私のサーバーに正しいプレーヤーの情報が正しく記録されていますが、graphiqlインターフェイスの結果はnull
です。 ここで間違っていることは何ですか?
そのタイプ 'PostgresDAO'は本当に何ですか?たぶん、あなたはおそらく約束を返すように、 'queryOne'メソッドを使用していませんか? –