查询 SQL 服务器 table 时,Apollo GraphQL returns 为空

Apollo GraphQL returns null when querying a SQL Server table

我在 SQL 服务器数据库中有这个 table: table 名称是 small_customer:

customerid| first_name | last_name | starting_date |
--------- | -----------| --------- | --------------|

这是 CustomerModel.js 中的代码,我在其中连接到 SQL 服务器数据库并对类型进行 Sequelize:

const CustomerModel= Conn.define('small_customer',{
    customerid: {type: Sequelize.INTEGER},
    first_name: {type: Sequelize.STRING},
    last_name: {type: Sequelize.STRING},
    starting_date: {type:Sequelize.DATEONLY},
});
const Customer= Conn.models.small_customers;
export default Customer;

这是Query.js:

import { CustomerModel, CustomerType, CustomerArgs} from './models/customer';
export default new GraphQLObjectType({
  name: 'Query',
  fields: () => {
    return {
      customer : {
        type: CustomerType,
        args: CustomerArgs,
        resolve(root,args){
          return new Promise((resolve, reject) => {
           return resolve(Customer.find({ where: args }));
            }); } }}}});

我定义了CustomerType.js:

export default new GraphQLObjectType({
  name: 'Customer',
  fields: () => {
    return {
      customerid: {type:GraphQLInt},
      first_name: {type: GraphQLString},
      last_name : {type: GraphQLString},
      starting_date: {type: GraphQLDate},
    }}});

当我编写查询以根据客户 ID 和名字 select 客户数据时,出现

错误

it Cannot read property 'find' of undefined

这是我的查询示例和 GraphiQL 中的结果:

Cannot read property 'find' of undefined

意味着客户有 undefined 类型并且您正在 undefined 上执行 find 操作作为 Customer.find({ where: args })

Query.js

中导入 CustomerModel
import { Customer } from './models/CustomerModel';

// i haven't used babel so require, if only schema is defined in CustomerModel
// const Customer = require('./models/CustomerModel');

import { CustomerModel, CustomerType, CustomerArgs } from './models/customer';

export default new GraphQLObjectType({
    name: 'Query',
    fields: () => {
        return {
            customer: {
                type: CustomerType,
                args: CustomerArgs,
                resolve(root, args) {
                    return new Promise((resolve, reject) => {
                        return resolve(Customer.find({ where: args }));
                    });
                }
            }
        }
    }
});