【问题标题】:GraphQLError: Syntax Error: Expected Name, found @GraphQLError:语法错误:预期名称,找到@
【发布时间】:2021-12-09 08:02:42
【问题描述】:

您好,我是 GraphQL 的新用户,正在尝试创建我将使用的架构。 我看到here 当您有多对多关系时,建议使用以下结构。

type UserCommunity
  @auth
  @model(queries: null)
  @key(name: "byUser", fields: ["userID", "communityID"]
  @key(name: "byCommunity", fields: ["communityID","userID"]{
  id: ID!
  userID: ID!
  communityID: ID!
  user: User! @connection(fields: ["userID"])
  community: Community! @connection(fields: ["communityID"])
  }

但是,当我使用 AWS Amplify 进行部署时,我收到以下错误消息:

GraphQLError: Syntax Error: Expected Name, found @

它也告诉我它在这条线上失败了:

@key(name: "byCommunity", fields: ["communityID","userID"]{

我已尝试查找所有文档并查看了其他堆栈溢出问题,但尚未解决语法问题。

任何帮助将不胜感激!

【问题讨论】:

    标签: graphql schema aws-amplify


    【解决方案1】:

    您在某些行缺少关闭 )s:

    -@key(name: "byUser", fields: ["userID", "communityID"]
    +@key(name: "byUser", fields: ["userID", "communityID"])
    

    -@key(name: "byCommunity", fields: ["communityID","userID"]{
    +@key(name: "byCommunity", fields: ["communityID","userID"]){
    

    【讨论】:

    • 所以应该添加一个手掌表情符号,因为我现在会使用它...感谢您指出有时您需要的只是另一双眼睛!
    【解决方案2】:

    实际上,@key 行的两行都缺少右括号。更新到这个,你应该很高兴。

    type UserCommunity
      @auth
      @model(queries: null)
      @key(name: "byUser", fields: ["userID", "communityID"])
      @key(name: "byCommunity", fields: ["communityID","userID"]){
      id: ID!
      userID: ID!
      communityID: ID!
      user: User! @connection(fields: ["userID"])
      community: Community! @connection(fields: ["communityID"])
    }
    

    旁注:如果您没有,我建议为您的文本编辑器准备一个 GraphQL 荧光笔。当您遇到语法问题时,关键字会改变颜色。这只是您需要注意的另一件事。

    【讨论】:

    • 我想我应该在发帖前刷新页面;唉
    • 无论如何我都感谢您的帮助!我使用 VSCode 作为我的主要 IDE,有没有你推荐的荧光笔?
    • 我个人使用“GraphQL Foundation”中的“GraphQL”
    • 太棒了,我去看看,谢谢!
    猜你喜欢
    • 2019-04-05
    • 2019-11-12
    • 2020-04-18
    • 2022-01-15
    • 2019-01-23
    • 2019-10-09
    • 2021-11-10
    • 2023-03-31
    • 2022-11-15
    相关资源
    最近更新 更多