2

我正在为 Prisma 服务器生成一个数据模型,使用graphql-cli. 但是,graphql-cli在没有的情况下继续生成 id 属性@unique,当我将其部署到 prisma 演示服务器时出现此错误。

该字段id是保留的,必须具有以下格式:id:ID!@独特的。

所以我的问题是如何让 graph-cli 生成@unique?

我的 prisma.graphql(aka datamodel.graphql) 有

type Comment implements Node {
  id: ID!
  content: String!
  userIdCommenBy: String!
  videoId: String!
  createdTime: String!
}

这种类型应该是

type Comment implements Node {
  id: ID! @unique
  content: String!
  userIdCommenBy: String!
  videoId: String!
  createdTime: String!
}

架构.graphql

type Query {
  feeds: [Video]
  users: [User]
  user: User
  videos: [Video]
  video: Video
  comments: [Comment]
  comment: Comment
  questions: [Question]
  question: Question
}

type Mutation {
  addUser(id: ID, firstName: String, lastName: String, companyId: String): User
  addComment(id: ID, content: String, userIdCommenBy: String): Comment
  addQuestion(id: ID, title: String, userIdAsekedBy: String, isAnonymous: String): Question
}

type User {
  id: ID
  email: String
  password: String
  firstName: String
  lastName: String
  companyId: String
  createdTime: String
}

type Video {
  id: ID
  questionId: String
  imgUrl: String
  videoUrl: String
  views: Int
  likes: Int
  isPrivate: Boolean
  comments: [Comment]
  createdTime: String
}

type Comment {
  id: ID
  content: String
  userIdCommenBy: String
  videoId: String
  createdTime: String
}

type Question {
  id: ID
  title: String
  userIdAsekedBy: String
  isAnonymous: Boolean
  countSkipped: Int
  views: Int
  createdTime: String
}

type Notification {
  isRead: Boolean
  isHidden: Boolean
  senderId: String
  recipientId: String
  typeOfNotification: String
  createdTime: String
}

.graphqlconfig.yml

projects:
    app:
        schemPath: src/schema.graphql
        extensions:
            endpoints:
            default: ${env:API_ENDPOINT}
    prisma:
        schemaPath: src/prisma/prisma.graphql
        extensions:
            prisma: src/prisma/prisma.yml

我运行的命令 graphql get-schema --project prisma --dotenv .env.dev

谢谢!

4

1 回答 1

4

您将数据模型(通常称为datamodel.graphql)与Prisma 数据库模式(通常称为prisma.graphql)混淆了。

Prisma 使用数据模型自动生成 Prisma 数据库模式:

@unique指令特定于 Prisma。因此,您只能在数据模型中使用它。Prisma 数据库模式不应再具有此指令。

我刚刚创建了一个小要点来更详细地解释两者之间的区别:https ://gist.github.com/nikolasburk/eef24cd0d907b4a3e073723054cf847d

于 2018-07-26T06:14:42.070 回答