Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/elixir/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ecmascript 6 TypeError:无法读取属性';创建产品&x27;未定义的?(来自graphql.js文件)_Ecmascript 6_Graphql_Es6 Promise_Prisma_Prisma Graphql - Fatal编程技术网

Ecmascript 6 TypeError:无法读取属性';创建产品&x27;未定义的?(来自graphql.js文件)

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/

当我为面向公共的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/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]!
}