【问题标题】:Prisma deploy: relations are expected for enums/expecting an interface, directive or definitionPrisma deploy:枚举期望关系/期望接口、指令或定义
【发布时间】:2020-05-22 16:11:52
【问题描述】:

我正在尝试部署我更新的datamodel.prisma 文件。但是,发生了一个错误,据我所知,它认为我正在尝试在上面定义的枚举与用户类型之间创建关系。

这是我的文件:

enum Permission {
  ADMIN
  USER
  ITEMCREATE
  ITEMUPDATE
  ITEMDELETE
  PERMISSIONUPDATE
}

type User {
  id: ID! @id
  name: String!
  email: String! @unique
  password: String!
  resetToken: String
  resetTokenExpiry: String
  permissions: [Permission]
}

type Item {
  id: ID! @id
  title: String!
  description: String!
  image: String
  largeImage: String
  price: Int!
  createdAt: DateTime! @createdAt
  updatedAt: DateTime! @updatedAt
}

运行 prisma deploy --env-file variables.env 在下面给我这个错误:

Errors:

  User
    ✖ Valid values for the strategy argument of `@scalarList` are: RELATION.

如果我将permissions: [Permission] 更改为permissions: Permission[],则会出现此错误(特别是expected ImplementsInterfaces, DirectivesConst or FieldDefinitions):

ERROR: Syntax error while parsing GraphQL query. Invalid input "{\n  id: ID! @id\n  name: String!\n  email: String! @unique\n  password: String!\n  resetToken: String\n  resetTokenExpiry: String\n  permissions: Permission[", expected ImplementsInterfaces, DirectivesConst or FieldDefinitions (line 10, column 11):
type User {
          ^

{
  "data": {
    "deploy": null
  },
  "errors": [
    {
      "locations": [
        {
          "line": 2,
          "column": 9
        }
      ],
      "path": [
        "deploy"
      ],
      "code": 3017,
      "message": "Syntax error while parsing GraphQL query. Invalid input \"{\\n  id: ID! @id\\n  name: String!\\n  email: String! @unique\\n  password: String!\\n  resetToken: String\\n  resetTokenExpiry: String\\n  permissions: Permission[\", expected ImplementsInterfaces, DirectivesConst or FieldDefinitions (line 10, column 11):\ntype User {\n          ^",
      "requestId": "us1:ck6au2sum8frx0b00fviv1dom"
    }
  ],
  "status": 200
}

我不确定该错误是什么意思,但我确实感觉它不理解电子邮件字段中的@unique 类型修饰符。它以前不存在,并且部署工作正常。非常感谢任何帮助!

【问题讨论】:

    标签: graphql prisma


    【解决方案1】:

    您需要指定策略和@scalarList 指令。

    这个@scalarList(strategy: STRATEGY!) 指令在任何情况下都是必需的 标量列表字段。策略论证的唯一有效论证 是关系。

    type Post {
      tags: [String!]! @scalarList(strategy: RELATION)
    }
    

    所有标量和枚举列表字段都需要它。

    见:https://www.prisma.io/docs/datamodel-and-migrations/datamodel-MYSQL-knul/#@scalarlist

    【讨论】:

    • 这对我有用。谢谢!文档对这个要求不是很直接,我不得不重新阅读它才能弄清楚。
    猜你喜欢
    • 1970-01-01
    • 2018-04-16
    • 1970-01-01
    • 2019-06-27
    • 1970-01-01
    • 2016-04-09
    • 2014-09-08
    • 1970-01-01
    • 2020-06-26
    相关资源
    最近更新 更多