我正在开发GraphQL Node教程,并完成第7步。
https://www.howtographql.com/graphql-js/7-subscriptions/
我在datamodel.prisma
文件中的此代码中收到许多语法错误:
directive @id on FIELD_DEFINITION
directive @unique on FIELD_DEFINITION
directive @createdAt on FIELD_DEFINITION
scalar DateTime
type Link {
id: ID! @id
createdAt: DateTime! @createdAt
description: String!
url: String!
postedBy: User
votes: [Vote!]!
}
type User {
id: ID! @id
name: String!
email: String! @unique
password: String!
links: [Link!]!
votes: [Vote!]!
}
type Vote {
id: ID! @id
link: Link!
user: User!
}
但是我仍然变得'User' type [@6:1] tried to redefine existing 'User' type [@15:5]
和'Link' type [@24:1] tried to redefine existing 'Link' type [@6:5]
。
我也不确定是否要声明directives
或scalars
正确,因为官方教程中缺少此内容。
任何人都可以就如何解决这些问题提供任何建议吗?
Schema.graphql:
type Query {
info: String!
feed(filter: String, skip: Int, first: Int, orderBy: LinkOrderByInput): Feed!
}
type Feed {
links: [Link!]!
count: Int!
}
type AuthPayload {
token: String
user: User
}
type User {
id: ID!
name: String!
email: String!
links: [Link!]!
}
type Vote {
id: ID!
link: Link!
user: User!
}
type Link {
id: ID!
description: String!
url: String!
postedBy: User
votes: [Vote!]!
}
type Subscription {
newLink: Link
newVote: Vote
}
type Mutation {
post(url: String!, description: String!): Link!
signup(email: String!, password: String!, name: String!): AuthPayload
login(email: String!, password: String!): AuthPayload
vote(linkId: ID!): Vote
}
enum LinkOrderByInput {
description_ASC
description_DESC
url_ASC
url_DESC
createdAt_ASC
createdAt_DESC
}
今天早上我遇到了同样的错误,我觉得这与缓存有关。当我重命名变量时,它消失了。根据您的情况,将所有“链接”定义/引用更改为“ LinkTwo”,然后查看错误是否消失。与“用户”相同...将其更改为“ UserTwo”。如果是这样,也许您之后可以重命名它们。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句