出现PERSISTED_QUERY_NOT_FOUND错误通常是由于Apollo客户端和服务器中的自动持久化查询配置不正确引起的。以下是一些可能的解决方法:
apollo.config.js
文件,确保配置了persistedQueries
选项,并设置为true
:module.exports = {
// 其他配置...
client: {
service: {
// 其他配置...
persistedQueries: true
}
}
// 其他配置...
};
在Apollo服务器的配置文件中,通常是apollo-server
的配置文件,确保配置了persistedQueries
选项,并设置为true
:
const { ApolloServer } = require('apollo-server');
const server = new ApolloServer({
// 其他配置...
persistedQueries: true,
// 其他配置...
});
确保Apollo客户端和服务器使用相同的持久化查询存储方式。自动持久化查询可以使用不同的存储方式,例如文件系统、数据库等。确保客户端和服务器都使用相同的存储方式,并配置正确的存储路径或连接信息。
检查Apollo客户端代码中是否正确使用了Apollo提供的工具函数来处理持久化查询。在客户端代码中,确保使用了apollo-link-persisted-queries
提供的createPersistedQueryLink
函数来创建Apollo链接,并将其添加到Apollo客户端中。
import { ApolloLink } from 'apollo-link';
import { createPersistedQueryLink } from 'apollo-link-persisted-queries';
const persistedQueryLink = createPersistedQueryLink();
const client = new ApolloClient({
// 其他配置...
link: ApolloLink.from([
persistedQueryLink,
// 其他链接...
]),
// 其他配置...
});
这些解决方法可以帮助您解决Apollo客户端和服务器中自动持久化查询不起作用,并出现PERSISTED_QUERY_NOT_FOUND错误的问题。请根据您的具体情况进行调整和测试。
上一篇:Apollo客户端和DGS服务器在2个schema上的集成冲突。
下一篇:Apollo客户端和GraphQL查询错误:变量“$where”期望的值为类型“OrganizationWhereUniqueInput”。