我试图把我的注意力集中在GraphQL上,我想我可以使用PostGraphile轻松、快速地映射我的PostgreSQL数据库,并使用GraphQL公开它。然而,我在一些简单的SQL中花费了很长时间去做一些事情-
首先,我试图在定义日期后从数据库中获取所有记录,但到目前为止无法做到这一点,最后我得到了所有的记录,这是非常低效率的。
第二,我希望得到它们中的可空字段不为空的所有记录(这意味着,只有当其中包含某些内容时,它才会显示在GraphQL结果中)
如果有人能对如何做到这一点有所了解,或者向我介绍一个很好的教程,它可以简单地解释如何编写定制的过滤函数,这将是很棒的。
发布于 2018-04-26 12:26:22
PostGraphile有一个小但不断增长的社区插件列表;为了满足您的需要,您可能需要邮戳.插件-连接-过滤器,它为您所期望的PostGraphile连接添加了许多筛选器(小于,大于,在列表中,不在列表中,和/或/或,例如,包含,等等)。还可以实现自己的插件,或者通过自定义查询实现这个目标。
发布于 2018-10-30 11:08:32
要扩展@Benjie的答案,首先安装插件:
yarn add postgraphile-plugin-connection-filter然后您可以从控制台运行postgraphile:
postgraphile --append-plugins <plugin path> --connection <dbname>例如,在Linux上:
postgraphile --append-plugins `pwd`/node_modules/postgraphile-plugin-connection-filter/index.js --connection mydb或者在Windows上:
postgraphile --append-plugins /users/bburns/desktop/moveto/site/node_modules/postgraphile-plugin-connection-filter/index.js --connection mydb然后,您可以在http://localhost:5000/graphiql上使用graphiql端点尝试新的过滤器。您可以运行以下查询:
{
allProperties(first: 5, filter: {
appraisedValue: {lessThan: 100000}
}) {
nodes {
propertyId
appraisedValue
acres
}
}
}注意:https://www.graphile.org/postgraphile/extending/的文档说您可以只给出npm包的名称,但这在Windows上似乎不起作用。
https://stackoverflow.com/questions/49981885
复制相似问题