简体   繁体   English

在Express JS上使用Apollo Graphql导出makeExecutableSchema时,无法读取isDocumentNode上未定义的属性“种类”

[英]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类型,例如UserUserPayload

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.

相关问题 无法读取未定义的属性“地图”(ReactJS-Apollo-Graphql) - Cannot read property 'map' of undefined (ReactJS-Apollo-Graphql) 无法读取未定义的属性“findOne”- Vue.js,Apollo 服务器,GraphQL 错误 - Cannot read property 'findOne' of undefined - Vue.js, Apollo Server, GraphQL error Apollo GraphQL - 类型错误:无法读取未定义的属性“findOrCreateUser” - Apollo GraphQL - TypeError: Cannot read property 'findOrCreateUser' of undefined 无法读取 Express js 中未定义的属性“状态” - Cannot read property 'status' of undefined in Express js 无法读取未定义的属性“种类” - Cannot read property 'kind' of undefined ReactJS/Javascript/Graphql/React-apollo:无法读取未定义的属性“加载” - ReactJS/Javascript/Graphql/React-apollo: Cannot read property 'loading' of undefined ReactJS/Javascript/Graphql/React-apollo:无法读取未定义的属性“名称” - ReactJS/Javascript/Graphql/React-apollo: Cannot read property 'name' of undefined 导入exporting.js时出现错误“无法读取未定义的属性”文档”(以导出highchart图表) - Getting error 'Cannot read property 'document' of undefined' while importing exporting.js (to export highchart charts) Express.js 无法读取未定义的属性“req” - Express.js Cannot read property 'req' of undefined 如何解决无法读取express js中未定义的属性“名称”? - how to solve Cannot read property 'name' of undefined in express js?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM