graphql - 反对使用带有 jsonSchema 的 virtualAttributes
问题描述
我想有一个附加列,其中包含另一列的修改值:现在我有下一个这样的代码,但它不起作用:
const { Model } = require("objection");
class TestModel extends Model {
static get tableName() {
return "testTable";
}
static get virtualAttributes() {
return ["someNewField"];
}
someNewField() {
return this.someField+'testString';
}
static get jsonSchema() {
return {
type: "object",
properties: {
someField:{ type: "string" },
},
};
}
}
module.exports = {
TestModel,
};
我得到了类似的错误
"message": "Cannot query field \"someNewField\" on type \"testTable\".",
我的 grapql 查询:
{TestModels{
someNewField,
}
解决方案
从数据库中获取数据后,在 javascript 端创建虚拟属性。所以没有这样的名为someNewField
生成到数据库的列。
因此,现在您正在尝试创建一个查询,该查询尝试从数据库中查找根本不存在的数据。
没有通用的解决方法如何使这项工作。如果您可以在这里解释您的用例,您可能会建议在该特定情况下做些什么。
推荐阅读
- linux - MongoDB 在 Ubuntu 18.04.2 LTS 上无法正常启动
- firebase - Firestore 颤振应用程序在 2 秒后出现错误?
- java - 在 RxJava / RxAndroid 中更新有关进度的 UI 时发出单个项目
- python - 在另一个类中调用类方法 - Tkinter
- mysql - 从 MySql 输入中删除 {}
- php - Codeigniter:使用查询字符串加载视图而不修改核心文件
- pyspark - 使用 spark 修改每个写入分区的输出文件数
- html - 我的图像不会通过 CSS 显示,只能在 HTML 中显示,而且我无法通过 CSS 对其进行缩放
- python - 如何使用 For 循环解决索引错误问题
- flutter - NosuchMethodError:在 null 上调用了方法“[]”。收件人:空