Ecmascript 6 TypeError:无法读取属性';创建产品&x27;未定义的?(来自graphql.js文件)
当我为面向公共的API(localhost)编写相同的查询时 我得到一个错误:Ecmascript 6 TypeError:无法读取属性';创建产品&x27;未定义的?(来自graphql.js文件),ecmascript-6,graphql,es6-promise,prisma,prisma-graphql,Ecmascript 6,Graphql,Es6 Promise,Prisma,Prisma Graphql,当我为面向公共的API(localhost)编写相同的查询时 我得到一个错误: TypeError: Cannot read property 'createProduct' of undefined at createProduct (/Users/gavish/Desktop/Final Beta/sick-fits/backend/src/resolvers/Mutation.js:5:42) at field.resolve (/Users/gavish/Desktop/
TypeError: Cannot read property 'createProduct' of undefined
at createProduct (/Users/gavish/Desktop/Final Beta/sick-fits/backend/src/resolvers/Mutation.js:5:42)
at field.resolve (/Users/gavish/Desktop/Final Beta/sick-fits/backend/node_modules/graphql-extensions/lib/index.js:119:77)
at resolveFieldValueOrError (/Users/gavish/Desktop/Final Beta/sick-fits/backend/node_modules/graphql/execution/execute.js:531:18)
at resolveField (/Users/gavish/Desktop/Final Beta/sick-fits/backend/node_modules/graphql/execution/execute.js:495:16)
at /Users/gavish/Desktop/Final Beta/sick-fits/backend/node_modules/graphql/execution/execute.js:339:18
at /Users/gavish/Desktop/Final Beta/sick-fits/backend/node_modules/graphql/jsutils/promiseReduce.js:25:10
at Array.reduce (<anonymous>)
at promiseReduce (/Users/gavish/Desktop/Final Beta/sick-fits/backend/node_modules/graphql/jsutils/promiseReduce.js:22:17)
at executeFieldsSerially (/Users/gavish/Desktop/Final Beta/sick-fits/backend/node_modules/graphql/execution/execute.js:336:38)
at executeOperation (/Users/gavish/Desktop/Final Beta/sick-fits/backend/node_modules/graphql/execution/execute.js:289:55)
这也是我的schema.graphql文件
# import * from './generated/prisma.graphql'
type Mutation {
createProduct(
id:ID
name: String
description: String
price: Int
colors: String
quantity: Int ): Product!
}
type Query {
products:[Product]!
}
我认为我使用的语法有问题。
还有什么是ES6格式写的变异函数 是
ctx.db.突变
不是ctx.db.突变
您可能想切换到prisma客户端而不是prisma绑定,因为它更安全,所以可以避免类似这样的错误
它是
ctx.db.突变
不是ctx.db.突变
您可能想切换到prisma客户端而不是prisma绑定,因为它更安全,所以可以避免类似这样的错误
什么是
ctx.db.突变
?在ctx.db
中似乎没有mutation
这是为了在数据库(db)上使用mutation,我提供给上下文回调(ctx)ok,ctx.db
也有一个名为mutation
的对象,其中包含一个名为createProduct
的函数。这就是我的问题ctx.db将我连接到prisma数据库,我在该数据库上调用了突变,是的,我在schema.graphql文件中提供了createProduct突变。我同意@Amir Mousavi,请尝试ctx.db.createProduct
?或者console.log(ctx.db)
检查它是否有名为translations
的对象。什么是ctx.db.translations
?在ctx.db
中似乎没有mutation
这是为了在数据库(db)上使用mutation,我提供给上下文回调(ctx)ok,ctx.db
也有一个名为mutation
的对象,其中包含一个名为createProduct
的函数。这就是我的问题ctx.db将我连接到prisma数据库,我在该数据库上调用了突变,是的,我在schema.graphql文件中提供了createProduct突变。我同意@Amir Mousavi,请尝试ctx.db.createProduct
?或者console.log(ctx.db)
来检查它是否有一个名为的对象。
# import * from './generated/prisma.graphql'
type Mutation {
createProduct(
id:ID
name: String
description: String
price: Int
colors: String
quantity: Int ): Product!
}
type Query {
products:[Product]!
}