是否可以将动态类型的数据发送到 GraphQL,或修改现有模式?

Is it possible to send data of dynamic types to GraphQL, or to modify an existing schema?

我正在使用 KeystoneJS 的自定义字段构建一个下拉列表,该下拉列表由 API 中的数据填充。构建自定义字段工作正常,但是当我尝试将数据保存到服务器时(即,当我让 KeystoneJS 通过其 GraphQL API 将数据保存到服务器时),我得到

[GraphQL error]: Message: Variable "$data" got invalid value "another" at "data.sploof"; Expected type TodoSploofType., Location: [object Object], Path: undefined

我是 GraphQL 的新手,但我认为问题在于我传递的数据 another 在字段 sploof 中不在架构中。

相反,它具有 pendingprocessed,这是我设置 KeystoneJS 时产生的——在这里您可以看到字段 sploof 具有自定义类型 MySelect schemaDoc 包含 options:

keystone.createList('Todo', {
    schemaDoc: 'A list of things which need to be done',
    fields: {
        name: {type: Text, schemaDoc: 'This is the thing you need to do'},
        blip: {type: Text, schemaDoc: 'This is another thing'},
        status: {type: Select, options: 'pending, processed'},
        sploof: {type: MySelect, options: 'pending, processed'},

    },
});

一般来说,有没有一种方法可以在创建 GraphQL 架构后对其进行修改?也就是说,如果我想发送其形状将在 运行 时间确定的数据?

Keystone Select 是已定义的类型,您不能为此发送动态值。

如果您想将新项目添加到字段中,您可以创建一个 RelationShip 类型字段并随机添加新项目,但由于仅存储 mongo ref objedct 的 id,这可能不会一直有效.

我看到您正在编写一个自定义字段,如果您可以让您的自定义字段从列表中加载数据并让用户 select(基本类型仍然是文本),那么您就可以使用动态那里的选项。您还可以创建自定义字段以列出同一列表中字段的值。一种基于现有值的提前输入

创建工作代码可能需要一些时间。