无法在 Apollo GraphQL 的查询中使用@client @export 变量
Unable to use @client @export variable in query in Apollo GraphQL
我只是想使用@client(本地缓存)变量作为我的 apollo 服务器的查询参数。文档引用了 @export 指令 (https://www.apollographql.com/docs/react/data/local-state/#querying-local-state)
出于某种原因,我无法执行类似
的操作
export const GET_COMPANY_DATA = gql`
query GetCompanyData($id: ID!, $name: STRING!) {
group @client @export(as: "name")
getCompanyData(id: $id) {
company {
groups(name: $name) {
data
}
}
}
}
;
两个查询单独工作,例如:
{
group @client
}
returns 本地缓存中的字符串
export const GET_COMPANY_DATA = gql`
query GetCompanyData($id: ID!, $name: STRING!) {
getCompanyData(id: $id) {
company {
groups(name: $name) {
data
}
}
}
}
;
returns 正确的对象类型
在文档中,他们展示了这个没有引用模式的例子:
const query = gql`
query currentAuthorPostCount($authorId: Int!) {
currentAuthorId @client @export(as: "authorId")
postCount(authorId: $authorId) @client
}
`;
我做错了什么?我觉得我缺少一些基本概念...
我明白了;设置 apollo 客户端时,您必须添加解析器 属性 即使您没有任何解析器:
const client = new ApolloClient({
cache,
link: authLink.concat(httpLink),
**resolvers: {}**
});
我只是想使用@client(本地缓存)变量作为我的 apollo 服务器的查询参数。文档引用了 @export 指令 (https://www.apollographql.com/docs/react/data/local-state/#querying-local-state)
出于某种原因,我无法执行类似
的操作export const GET_COMPANY_DATA = gql`
query GetCompanyData($id: ID!, $name: STRING!) {
group @client @export(as: "name")
getCompanyData(id: $id) {
company {
groups(name: $name) {
data
}
}
}
}
;
两个查询单独工作,例如:
{
group @client
}
returns 本地缓存中的字符串
export const GET_COMPANY_DATA = gql`
query GetCompanyData($id: ID!, $name: STRING!) {
getCompanyData(id: $id) {
company {
groups(name: $name) {
data
}
}
}
}
;
returns 正确的对象类型
在文档中,他们展示了这个没有引用模式的例子:
const query = gql`
query currentAuthorPostCount($authorId: Int!) {
currentAuthorId @client @export(as: "authorId")
postCount(authorId: $authorId) @client
}
`;
我做错了什么?我觉得我缺少一些基本概念...
我明白了;设置 apollo 客户端时,您必须添加解析器 属性 即使您没有任何解析器:
const client = new ApolloClient({
cache,
link: authLink.concat(httpLink),
**resolvers: {}**
});