我正在使用graphql-cli
为Prisma服务器生成数据模型。但是,graphql-cli
在没有@unique
的情况下仍会继续产生ID属性,并且在将其部署到pyramida演示服务器时会出现此错误。
字段
id
被保留,并且必须具有以下格式:id:ID! @unique。
所以我的问题是如何使graph-cli生成@unique?
我的pyramida.graphql(又名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!
}
schema.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
谢谢!
答案 0 :(得分:4)
您将数据模型(通常称为datamodel.graphql
)与 Prisma数据库模式(通常称为prisma.graphql
)相混淆。
Prisma使用数据模型自动生成Prisma数据库架构:
@unique
指令特定于Prisma。因此,您只能在数据模型中使用它。 Prisma数据库架构不应再具有此指令。
我刚刚创建了一个要点,以更详细地说明两者之间的区别:https://gist.github.com/nikolasburk/eef24cd0d907b4a3e073723054cf847d