简体   繁体   English

Strapi graphql 插件:如何获取所有记录

[英]strapi graphql plugin: how to get all records

Intent:意图:

I need graphql to return all records我需要 graphql 来返回所有记录

Issue:问题:

amountLimit is implemented differently on the strapi plugin amountLimit在 Strapi 插件上的实现方式不同

Question:题:

Can somebody tell me why graphql amountLimit was implemented like this?有人能告诉我为什么 graphql amountLimit是这样实现的吗?

  amountLimiting: (params = {}) => {
    const { amountLimit } = strapi.plugins.graphql.config;
    if(!amountLimit) return params;
    if (!params.limit || params.limit === -1 || params.limit > amountLimit) {
      params.limit = amountLimit;
    } else if (params.limit < 0) {
      params.limit = 0;
    } 
    return params;
  },

Explanation:解释:

strapi has a _limit = 0 for all records, but on graphql plugin they're adding a default limit of 100. If I am to give limit: -1 or limit: 0 to the graphql query, it will put the default limit of 100 .对于所有记录,trapi 有一个_limit = 0 ,但是在 graphql 插件上,他们添加了 100 的默认限制。如果我要为 graphql 查询提供limit: -1limit: 0 ,它会将默认limit100 . If I am to give ( else if (params.limit < 0) ) any other nr lower than 0 , but it's not -1 , the plugin queries strapi with limit: 0 (all records)如果我要给( else if (params.limit < 0) )任何其他低于0 nr ,但它不是-1 ,则插件使用limit: 0 (所有记录)查询trapi

Workaround解决方法

I need a way of querying graphql for all records, yet setting the limit to -2 seems a bit random to me (as setting the limit to any -(2^31) < nr < -1 number)我需要一种查询所有记录的 graphql 的方法,但将限制设置为-2对我来说似乎有点随机(因为将限制设置为任何-(2^31) < nr < -1数字)

Solution !?解决方案 !?

Any thoughts?有什么想法吗?

DMehaffy (Not Strapi Employee) 12:35 PM Strapi doesn't use the typical version system right now (it will when it goes stable) unable to get all entries yes. DMehaffy (Not Strapi Employee) 12:35 PM Strapi 现在不使用典型的版本系统(它会在稳定时使用)无法获取所有条目是的。 To prevent massive queries from basically locking up your server, aka DDoS.为了防止大规模查询基本上锁定您的服务器,也就是 DDoS。 Strapi being nodejs (basically single threaded) massive one off queries is not the most effective way to pull all the data, especially in a load balancing setup grab a count, divide it up, and make multiple smaller requests at the same time or asynchronously then merge the records together client side Sure you are injecting a bit more round trip time, but in the long run it is quite a bit faster (especially when load balancing multiple strapi instances) Strapi 是 nodejs(基本上是单线程的)大规模一次性查询并不是提取所有数据的最有效方法,尤其是在负载平衡设置中,抓取一个计数,将其拆分,然后同时或异步发出多个较小的请求将记录合并在一起 客户端确保您注入了更多的往返时间,但从长远来看,它要快得多(尤其是在负载平衡多个 Strapi 实例时)

Apparently, in strapi version beta.17.5 the negative limit will be removed completely, thus rendering this question obsolete.显然,在 Strapi 版本beta.17.5 ,负限制将被完全删除,从而使这个问题变得过时。

As from the Strapi response up above, they are working on a solution, but at this time, for Strapi 3.0.0-beta.14 which is my current version, the negative look-up is still available, but it will be removed, with a new solution being provided.从上面的 Strapi 响应来看,他们正在研究解决方案,但此时,对于我当前版本的Strapi 3.0.0-beta.14 ,否定查找仍然可用,但将被删除,提供了新的解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM