标签: nexus-prisma

如何在 prisma 迁移工具中使用 DECIMAL(10,2)?

我需要保存DECIMAL(10,2)在数据库中。里面MySQLDECIMAL类型。

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

有没有计划支持像flow这样的mysql数据DECIMAL(10,2)类型Prisma Migrate

prisma prisma-graphql nexus-prisma

11
推荐指数
1
解决办法
1万
查看次数

Nexus-prisma:订购嵌套连接

在架构中保持嵌套对象顺序的最佳方法是什么。

我的架构:

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处理该问题。

javascript graphql prisma-graphql nexus-prisma

7
推荐指数
1
解决办法
288
查看次数

Prisma2 错误:“prisma.post.create()”调用无效:PostUncheckedCreateInput 类型的 data.tags 中的参数“tags”未知

我想创建一个带有附加标签列表的帖子。这些模型是多对多连接的(一个帖子可以有多个标签,一个标签可以有多个帖子)。

这是我的棱镜模型:

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 graphql prisma nexus-prisma prisma2

6
推荐指数
1
解决办法
7707
查看次数

订阅不适用于 Prisma 2 和 Nexus?

Nexus 的订阅没有记录,但我搜索了 Github 并尝试了书中的每个示例。这对我来说不起作用。

我已经克隆了Prisma2 GraphQL 样板项目,我的文件如下:

prisma/schema.prisma

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)

src/index.js

const { GraphQLServer } = require('graphql-yoga') …
Run Code Online (Sandbox Code Playgroud)

javascript graphql prisma prisma-graphql nexus-prisma

5
推荐指数
1
解决办法
3423
查看次数

Prisma Schema 中的多态性 - 最佳实践?

这更像是一个设计问题,而不是一个编码问题。假设有以下架构:

// 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)

nexus graphql prisma prisma-graphql nexus-prisma

5
推荐指数
1
解决办法
7303
查看次数

如何使用 nexus-prisma 制作嵌套突变解析器

我有以下数据模型:

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)

graphql prisma prisma-graphql nexus-prisma

4
推荐指数
1
解决办法
3326
查看次数

使用 nexus-prisma graphql 处理文件上传

我正在尝试将文件从前端应用程序上传到服务器,但我不断收到这个奇怪的错误,并且不知道为什么会发生这种情况。

错误是前端:

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)

即使当尝试使用前端应用程序以外的其他东西运行突变时,我也会遇到相同的错误,所以我猜问题出在我的后端设置上,尽管我搜索了很多方法来做到这一点似乎都不起作用。

apollo graphql prisma prisma-graphql nexus-prisma

4
推荐指数
1
解决办法
3093
查看次数

prisma2 迁移错误:数据库中的迁移比本地的多

我正在使用prisma2 + typescript + nexus + graphql-yoga 构建后端应用程序。我现在已经定义了我的架构,同时尝试通过运行命令Prisma2 migrate save --name "init" --experimental来保存迁移

得到以下错误。

错误:数据库中的迁移比本地多。这绝不能发生。本地迁移 ID: . 远程迁移 ID:20200312230215-init、20200312232858-init2

prisma nexus-prisma prisma2

3
推荐指数
1
解决办法
2583
查看次数