[英]Cannot read property 'kind' of undefined at isDocumentNode while export makeExecutableSchema using Apollo Graphql on express js
I have created modular of schema like this: User.js 我已经创建了模块化的模式,如下所示:User.js
const gqTools = require('graphql-tools');
const user = `
type User {
emailId: String
name: String
type: Int
created_on: String
}
`;
module.exports = user
and this is the UserPayload that has related by the user type schema 这是与用户类型架构相关的UserPayload
const gqTools = require('graphql-tools');
const User = require('./User')
const userPayload = `
enum ErrorCodes {
UNAUTHORIZED
INTERNAL_ERROR
}
type Error {
code: ErrorCodes
msg: String
}
type UserPayload {
user: [User]
error: Error
}
`;
module.exports = () => [userPayload, User]
this is the Type Query of user that i created 这是我创建的用户的类型查询
const gqTools = require('graphql-tools');
const UserPayload = require('../UserPayload')
const query = `
type Query {
checkAuthorized: [UserPayload]
}
`;
module.exports = () => [query, UserPayload]
this is the resolver i created 这是我创建的解析器
const checkAuthorizedResolver = {
async checkAuthorized(root, data, context) {
if (context.user.length === 0) {
return {
user: null,
error: {
code: 'UNAUTHORIZED',
msg: 'UNAUTHORIZED'
}
}
}
let s = `
select email, name, usertype_id, created_at
from users
where id = ${context.user[0].id}
`
try {
let result = await context.db.run(s)
return {
user: {
emailId: result[0].email,
name: result[0].name,
type: result[0].usertype_id,
created_on: result[0].created_at
},
error: null
}
} catch (err) {
console.log(err)
return {
user: null,
error: {
code: 'UNAUTHORIZED',
msg: 'UNAUTHORIZED'
}
}
}
}
}
module.exports = checkAuthorizedResolver
after it i create the main.js on schema folder that will be import on server.js 之后,我在将要导入到server.js的架构文件夹上创建main.js
const gqTools = require('graphql-tools');
const jwt = require('jsonwebtoken')
const { makeExecutableSchema } = require('graphql-tools')
const moment = require('moment')
const {
checkAuthorized,
} = require('../schema/type_Query/type_Query')
const checkAuthorizedResolver = require ('../Controller/checkAuthorized')
module.exports = makeExecutableSchema({
typeDefs: [checkAuthorized],
resolvers:{
checkAuthorizedResolver
}
})
after i run the program it show the error msg, i dont understand what is mean of "kind" on the error msg because i never declare variable "kind", and i know it is from node module library. 在我运行程序后,它显示错误消息味精,我不理解错误消息味精的含义是什么,因为我从未声明变量“种类”,而且我知道它来自节点模块库。 may everyone help me what is mean of that error and how to write the syntax on "makeExecutableSchema", because i have follow the documentation from GrahQL Tools for modularization
可能每个人都可以帮助我说明该错误的含义以及如何在“ makeExecutableSchema”上编写语法,因为我已经遵循了GrahQL Tools的文档进行模块化
this is the error msg: 这是错误消息:
> TypeError: Cannot read property 'kind' of undefined
> at isDocumentNode (/home/hari/Documents/kerjaan/nest8gg/kpi/node_modules/graphql-tools/src/schemaGener
> ator.ts:134:42)
> at /home/hari/Documents/kerjaan/nest8gg/kpi/node_modules/graphql-tools/src/schemaGenerator.ts:151:9
> at Array.forEach (<anonymous>)
> at concatenateTypeDefs (/home/hari/Documents/kerjaan/nest8gg/kpi/node_modules/graphql-tools/src/schema
> Generator.ts:150:22)
> at buildSchemaFromTypeDefinitions (/home/hari/Documents/kerjaan/nest8gg/kpi/node_modules/graphql-tools
> /src/schemaGenerator.ts:190:21)
> at _generateSchema (/home/hari/Documents/kerjaan/nest8gg/kpi/node_modules/graphql-tools/src/schemaGene
> rator.ts:80:18)
> at makeExecutableSchema (/home/hari/Documents/kerjaan/nest8gg/kpi/node_modules/graphql-tools/src/schem
> aGenerator.ts:109:20)
> at Object.<anonymous> (/home/hari/Documents/kerjaan/nest8gg/kpi/server/schema/main.js:41:18)
> at Module._compile (module.js:643:30)
> at Module._compile (/home/hari/Documents/kerjaan/nest8gg/kpi/node_modules/source-map-support/source-ma
> p-support.js:492:25)
Most likely you pass a undefined
as type, for example, User
or UserPayload
: 您最有可能传递
undefined
类型,例如User
或UserPayload
:
module.exports = () => [userPayload, User]
module.exports = () => [query, UserPayload]
You can log them out and make sure they have valid values: 您可以注销它们并确保它们具有有效值:
console.log(User);
module.exports = () => [userPayload, User]
console.log(UserPayload);
module.exports = () => [query, UserPayload]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.