gpt4 book ai didi

caching - 如何在 apollo-server-hapi graphql 上实现缓存

转载 作者:行者123 更新时间:2023-12-02 13:08:15 24 4
gpt4 key购买 nike

我有带有 apollo-server-hapi 的 graphql。我尝试添加缓存控制,如下所示:

const graphqlOptions = {
schema,
tracing: true,
cacheControl: true,
};

但是当我尝试在架构基础上添加缓存选项时:

type Author @cacheControl(maxAge: 60) {
id: Int
firstName: String
lastName: String
posts: [Post]
}

我收到此错误消息:

Error: Unknown directive "cacheControl".

您能帮忙吗,在架构上应用缓存控制的正确方法是什么?

我按照下面的说明进行操作,但似乎不起作用。

apollo-cache-control

最佳答案

了解有关 apollo graphql 缓存的更多信息后,基本上,问题出在 apollo-server-hapimakeExecutableSchema 上,不包含 @ 指令cacheControl,因此要使其工作,我们只需在 graphql 文件中定义我们自己的 @cacheControl 指令,如下所示:

enum CacheControlScope {
PUBLIC
PRIVATE
}

directive @cacheControl (
maxAge: Int
scope: CacheControlScope
) on FIELD_DEFINITION | OBJECT | INTERFACE

type Author @cacheControl(maxAge: 60) {
id: Int
firstName: String
lastName: String
posts: [Post]
}

关于caching - 如何在 apollo-server-hapi graphql 上实现缓存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52922080/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com