#javascript #node.js #postgresql #graphql #digital-ocean
Вопрос:
мой очень простой API prisma GraphQL отлично работает в моей локальной базе данных PostgreSQL, размещенной в Docker. Как только я переключаюсь на свой PostgreSQL, размещенный на DigitalOcean, он перестает работать.
Вот мой код: мои типы:
const typeDefs = gql` type Book { id: ID! name: String content: String } type Query { books: [Book!]! } type Mutation { createBook(name: String, content: String): Book! } `
Вот мои решатели:
const resolvers = { Query: { books: (parent, args) =gt; { return prisma.book.findMany() }, }, Mutation: { createBook: (parent, args) =gt; { return prisma.book.create({ data: { name: args.name, content: args.content } }) } } }
А вот мой файл schema.prisma:
generator client { provider = "prisma-client-js" } datasource db { provider = "postgresql" url = env("DATABASE_URL") } model Book { id Int @id @default(autoincrement()) name String? content String? }
Я попытался сбросить базу данных и т. Д. и т. Д. Ничего не работает.
Вот ошибка, которую я получаю:
{ "errors": [ { "message": "Cannot read property 'create' of undefined", "locations": [ { "line": 2, "column": 3 } ], "path": [ "createBook" ], "extensions": { "code": "INTERNAL_SERVER_ERROR", "exception": { "stacktrace": [ "TypeError: Cannot read property 'create' of undefined", " at Object. createBook (/workspace/src/schema.js:38:26)", " at field.resolve (/workspace/node_modules/apollo-server-core/dist/utils/schemaInstrumentation.js:52:26)", " at resolveField (/workspace/node_modules/graphql/execution/execute.js:464:18)", " at /workspace/node_modules/graphql/execution/execute.js:261:18", " at /workspace/node_modules/graphql/jsutils/promiseReduce.js:23:10", " at Array.reduce (lt;anonymousgt;)", " at promiseReduce (/workspace/node_modules/graphql/jsutils/promiseReduce.js:20:17)", " at executeFieldsSerially (/workspace/node_modules/graphql/execution/execute.js:258:37)", " at executeOperation (/workspace/node_modules/graphql/execution/execute.js:236:55)", " at executeImpl (/workspace/node_modules/graphql/execution/execute.js:116:14)" ] } } } ], "data": null }