【问题标题】:How do I use GraphQL to query the options for a KeystoneJS select field如何使用 GraphQL 查询 KeystoneJS 选择字段的选项
【发布时间】:2021-05-07 18:58:14
【问题描述】:

我已经根据docs 在 KeystoneJS 中设置了一个select 字段:

const { Select } = require('@keystonejs/fields');

keystone.createList('Order', {
  fields: {
    status: { type: Select, options: 'pending, processed' },
  },
});

如何使用introspection 获取该字段的有效选项列表?

【问题讨论】:

    标签: graphql introspection keystonejs


    【解决方案1】:

    KeystoneJS 中的类型似乎使用以下格式命名:

    <list name><field name>Type
    

    另外,如果&lt;list name&gt;&lt;field name&gt; 的首字母为小写,则将其改为大写。因此,对于问题中给出的示例,字段 status 的类型名称将是:

    OrderStatusType
    

    然后可以使用以下方式查询可用选项:

    query {
      __type (name: "OrderStatusType") {
        enumValues {
          name
        }
      }
    }
    

    在使用 Postgres 数据库的标准 KeystoneJS 安装上测试。

    【讨论】:

      猜你喜欢
      • 2018-03-10
      • 2015-10-18
      • 1970-01-01
      • 1970-01-01
      • 2019-02-25
      • 2012-09-11
      • 2013-04-25
      • 1970-01-01
      • 2017-05-31
      相关资源
      最近更新 更多