简体   繁体   English

Gatsby 是否按操作名称缓存 graphQL 查询?

[英]Does Gatsby cache graphQL queries by Operation Name?

I've read this question which is more general: What is the point of naming queries and mutations in GraphQL?我读过这个更笼统的问题: What is the point of naming queries and mutations in GraphQL? . . The top answer indicates that Operation Name is meaningless, but a particular implementation can give it meaning.最上面的答案表明 Operation Name 没有意义,但特定的实现可以赋予它意义。

My team lead and I are working refactoring some data into new static queries which might be repeated many times across the app.我和我的团队领导正在努力将一些数据重构为新的 static 查询,这些查询可能会在整个应用程序中重复多次。 We think that naming the queries will allow Gatsby to cache the results, which would be great.我们认为命名查询将允许 Gatsby 缓存结果,这会很棒。 But I can't actually find anything saying that in the Gatsby docs and now neither of us know where that idea came from.但实际上我在 Gatsby 文档中找不到任何这样的说法,现在我们都不知道这个想法从何而来。 All I have found is this rather unhelpful description.我所发现的只是这个毫无帮助的描述。 So, does giving these queries names actually help us here, or is it pointless?那么,给这些查询命名实际上对我们有帮助吗,还是毫无意义?

The operation name is irrelevant as Gatsby generates its own unique name internally (you can add it so that it makes it into that generation).操作名称是无关紧要的,因为 Gatsby 在内部生成了自己的唯一名称(您可以添加它以使其进入该代)。 If you eg create a custom hook with a useStaticQuery and then use that throughout your app, it'll only use that (so it's "cached").例如,如果您使用useStaticQuery创建自定义挂钩,然后在整个应用程序中使用它,它只会使用它(因此它被“缓存”)。

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

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