我如何使用 `selectGraphQLResultFromTable` 在 post-graphile 解析器中加载 Sequelize 查询的关系?

问题描述

我的数据库中有几个相关的表:

<?xml version="1.0" encoding="UTF-8"?> <configuration> <include resource="org/springframework/boot/logging/logback/base.xml"/> <logger name="your.name" level="INFO" additivity="false"> <appender-ref ref="CONSOLE"/> <appender-ref ref="FILE"/> </logger> </configuration> 表:

rooms

"id" SERIAL PRIMARY KEY,"details" jsonb,"Metadata" jsonb,"region" character varying(255) NOT NULL DEFAULT 'uk'::character varying,"createdAt" timestamp with time zone NOT NULL,"updatedAt" timestamp with time zone NOT NULL,"houseId" integer REFERENCES houses(id) ON DELETE SET NULL ON UPDATE CASCADE 表:

houses

在我的项目中,我使用 PostGraphile (graphile-utils) 作为我的 GraphQL 提供程序。

我创建了一个自定义解析器,用于使用 Sequelize 在 "id" SERIAL PRIMARY KEY,"coordinates" jsonb,"type" jsonb NOT NULL,"blockId" integer REFERENCES blocks(id) ON DELETE SET NULL ON UPDATE CASCADE,CONSTRAINT "houses_originalProdId_region_key" UNIQUE ("originalProdId",region) 上执行动态构建的复杂查询。 我选择通过 Sequelize 而不是直接通过 PostGraphile 查询数据库,因为查询对象的各个部分都是动态构建的(rooms 对象和 where 数组)。

解析器如下所示:

include

查询有效,但现在无法为房间加载关系,因此我无法通过相关过滤的房间查询 async (_query,args) => { const { input,pagination } = args; const filteredRooms = await roomrepository.findRoomsUsingDynamicFilters( pagination,input,); return filteredRooms || null; }

house

结果

{
  filterRooms(input: { filterByAttributes: ["large","white"] },pagination: {}) {
    house{
      id
    }
  }
}

在 PostGraphile 文档中,我发现方法 { "data": { "filterRooms": [ { "house": null },{ "house": null },] } } 似乎加载关系,但我不确定如何将它与 Sequelize 查询结合使用;也就是说,我的解析器如何仅返回我通过 Sequelize 过滤的房间,以能够查询其关系的格式(如上例所示)?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)