我需要保存DECIMAL(10,2)
在数据库中。里面MySQL
有DECIMAL
类型。
MySQL 文档:
https://dev.mysql.com/doc/refman/8.0/en/fixed-point-types.html
Prisma 2.0 文档:
https://www.prisma.io/docs/reference/database-connectors/mysql
可能的 Prisma 2.0 流程:
https://www.prisma.io/docs/understand-prisma/introduction#典型-prisma-workflows
Prisma Migrate
流程并发现映射受到限制。Introspection
。DECIMAL(10,2)
类型Prisma Migrate
?在架构中保持嵌套对象顺序的最佳方法是什么。
我的架构:
type Article {
id: ID! @id
pages: [Page!]!
}
type Page {
id: ID! @id
}
Run Code Online (Sandbox Code Playgroud)
这就是我试图对页面进行排序的方法(不成功):
updateArticle({
variables: {
aricle.id,
data: {
pages: {
connect: reorderPages(aricle.pages)
}
}
}
Run Code Online (Sandbox Code Playgroud)
解析器:
t.field("updateArticle", {
type: "Article",
args: {
id: idArg(),
data: t.prismaType.updateArticle.args.data
},
resolve: (_, { id, data }) => {
return ctx.prisma.updateArticle({
where: { id },
data
});
}
});
Run Code Online (Sandbox Code Playgroud)
我了解为什么这种方法是错误的。我想应该通过连接表中的订单索引将订单写入数据库。我不知道如何通过GraphQL / Nexus / Prisma / MySQL处理该问题。
我想创建一个带有附加标签列表的帖子。这些模型是多对多连接的(一个帖子可以有多个标签,一个标签可以有多个帖子)。
这是我的棱镜模型:
model Post {
id String @id @default(cuid())
slug String @unique
title String
body String
tags Tag[]
}
model Tag {
id String @id @default(cuid())
posts Post[]
name String
slug String @unique
}
Run Code Online (Sandbox Code Playgroud)
这是一个突变,我试图创建一个帖子,并为其附加标签:
t.field('createPost', {
type: 'Post',
args: {
title: nonNull(stringArg()),
body: stringArg(),
tags: list(arg({ type: 'TagInput' }))
},
resolve: async (_, args, context: Context) => {
// Create tags if they don't exist
const tags = await Promise.all(
args.tags.map((tag) =>
context.prisma.tag.upsert({
create: omit(tag, "id"),
update: tag,
where: …
Run Code Online (Sandbox Code Playgroud) Nexus 的订阅没有记录,但我搜索了 Github 并尝试了书中的每个示例。这对我来说不起作用。
我已经克隆了Prisma2 GraphQL 样板项目,我的文件如下:
datasource db {
provider = "sqlite"
url = "file:dev.db"
default = true
}
generator photon {
provider = "photonjs"
}
generator nexus_prisma {
provider = "nexus-prisma"
}
model Pokemon {
id String @default(cuid()) @id @unique
number Int @unique
name String
attacks PokemonAttack?
}
model PokemonAttack {
id Int @id
special Attack[]
}
model Attack {
id Int @id
name String
damage String
}
Run Code Online (Sandbox Code Playgroud)
const { GraphQLServer } = require('graphql-yoga') …
Run Code Online (Sandbox Code Playgroud) 这更像是一个设计问题,而不是一个编码问题。假设有以下架构:
// schema.prisma
// Solution 1
model Entity {
id Int @id @default(autoincrement())
attrs EntityAttr[]
}
model EntityAttr {
id Int @id @default(autoincrement())
value Json // or String, doesnt matter much here
// the point is I need to attach info on the
// join table of this relation
attr Attr @relation(fields: [attrId], references: [id])
entity Entity @relation(fields: [entityId], references: [id])
entityId Int
attrId Int
@@unique([entityId, attrId])
}
model Attr {
id Int @id @default(autoincrement())
entities EntityAttr[]
}
Run Code Online (Sandbox Code Playgroud)
// Solution …
Run Code Online (Sandbox Code Playgroud) 我有以下数据模型:
type Job {
// ...
example: String
selections: [Selection!]
// ...
}
type Selection {
...
question: String
...
}
Run Code Online (Sandbox Code Playgroud)
我这样定义我的对象类型:
export const Job = prismaObjectType({
name: 'Job',
definition(t) {
t.prismaFields([
// ...
'example',
{
name: 'selections',
},
// ...
])
},
})
Run Code Online (Sandbox Code Playgroud)
我这样做我的解析器:
t.field('createJob', {
type: 'Job',
args: {
// ...
example: stringArg(),
selections: stringArg(),
// ...
},
resolve: (parent, {
example,
selections
}, ctx) => {
// The resolver where I do a ctx.prisma.createJob and connect/create with …
Run Code Online (Sandbox Code Playgroud) 我正在尝试将文件从前端应用程序上传到服务器,但我不断收到这个奇怪的错误,并且不知道为什么会发生这种情况。
错误是前端:
Variable "$file" got invalid value {}; Expected type Upload. Upload value invalid.
Run Code Online (Sandbox Code Playgroud)
后台报错:
GraphQLError: Upload value invalid.
at GraphQLScalarType.parseValue (/app/backend/node_modules/graphql-upload/lib/GraphQLUpload.js:66:11)
Run Code Online (Sandbox Code Playgroud)
这就是我添加上传标量的方法
Variable "$file" got invalid value {}; Expected type Upload. Upload value invalid.
Run Code Online (Sandbox Code Playgroud)
这就是我在 React/NextJS 应用程序中制作 uplaod 客户端的方法
GraphQLError: Upload value invalid.
at GraphQLScalarType.parseValue (/app/backend/node_modules/graphql-upload/lib/GraphQLUpload.js:66:11)
Run Code Online (Sandbox Code Playgroud)
即使当尝试使用前端应用程序以外的其他东西运行突变时,我也会遇到相同的错误,所以我猜问题出在我的后端设置上,尽管我搜索了很多方法来做到这一点似乎都不起作用。
我正在使用prisma2 + typescript + nexus + graphql-yoga 构建后端应用程序。我现在已经定义了我的架构,同时尝试通过运行命令Prisma2 migrate save --name "init" --experimental来保存迁移
得到以下错误。
错误:数据库中的迁移比本地多。这绝不能发生。本地迁移 ID: . 远程迁移 ID:20200312230215-init、20200312232858-init2