【问题标题】:Marking fields as deprecated with graphql shorthand使用 graphql 速记将字段标记为已弃用
【发布时间】:2020-08-11 16:36:58
【问题描述】:

我使用GraphQL shorthand 来指定模式中的类型,例如

type Car {
  id: ID!
  make: String
  model: String
  description: String
}

使用这个速记,有没有办法将字段标记为已弃用?假设我想将描述标记为已弃用。这是我对如何做到这一点的疯狂猜测。

type Car {
  id: ID!
  make: String
  model: String
  @deprecated
  description: String
}

但没有骰子。是否可以在 GraphQL 速记中实现字段弃用?

谢谢!

【问题讨论】:

    标签: graphql


    【解决方案1】:

    是的,您可以像这样将字段标记为已弃用:

    type Car {
      id: ID!
      make: String
      model: String
      description: String @deprecated(reason: "Field is deprecated!")
    }
    

    【讨论】:

    • 太棒了!我需要一些特殊版本的工具来利用它吗?我正在使用来自graphql-toolsmakeExecutableSchema 来构建我的架构。 var executableSchema = makeExecutableSchema({ typeDefs: schema, resolvers: resolvers });
    • 看起来不像自省工具或 graphql intellij 插件能够捡起它。不确定是否有任何变化
    • 这里的 GraphQL 规范中有记录:spec.graphql.org/June2018/#sec--deprecated
    【解决方案2】:

    你可以这样弃用

    directive @deprecated(
      reason: String = "No longer supported"
    ) on FIELD_DEFINITION | ENUM_VALUE
    
    type ExampleType {
      newField: String
      oldField: String @deprecated(reason: "Use `newField`.")
    }
    

    更多信息请参考阿波罗服务器documentation

    【讨论】:

      猜你喜欢
      • 2014-08-20
      • 2010-09-22
      • 1970-01-01
      • 1970-01-01
      • 2022-09-22
      • 1970-01-01
      • 1970-01-01
      • 2011-07-21
      • 2021-12-27
      相关资源
      最近更新 更多