忽略了 Apollo 类型定义
Apollo type defs ignored
我已经完成了 ApolloClient
的基本实现:
const gqlClient = new ApolloClient({
connectToDevTools: true,
link: new HttpLink({
uri: "/api",
}),
cache: new InMemoryCache(),
resolvers: {
Group: {
icon: () => "noIcon",
},
},
typeDefs: gql`
extend type Group {
icon: String!
}
`,
});
唯一有趣的是一个解析器和类型定义 - 两者都支持组的 icon
字段(即将推出的功能)。
然后我尝试使用以下内容查询服务器:
gqlClient.query({
query: gql`{
groups {
name
icon
}
}`,
})
.then(console.log);
并得到一个大错误:
bundle.esm.js:63 Uncaught (in promise) Error: GraphQL error: Cannot query field `icon' on type `Group'.
at new ApolloError (bundle.esm.js:63)
at bundle.esm.js:1247
at bundle.esm.js:1559
at Set.forEach (<anonymous>)
at bundle.esm.js:1557
at Map.forEach (<anonymous>)
at QueryManager../node_modules/apollo-client/bundle.esm.js.QueryManager.broadcastQueries (bundle.esm.js:1555)
at bundle.esm.js:1646
at Object.next (Observable.js:322)
at notifySubscription (Observable.js:135)
运行 不要求 icon
的相同查询完美运行。我不太确定我做错了什么。 如何模拟 icon
并修复此错误?
我只是 运行ing Apollo Client - 我需要 运行 Apollo Server 才能获得所有功能吗?传出请求似乎没有我的任何类型定义信息,所以我不确定拥有 Apollo 服务器会有什么不同。
Handling @client fields with resolvers
gqlClient.query({
query: gql`
{
groups {
name
icon @client
}
}
`,
});
我已经完成了 ApolloClient
的基本实现:
const gqlClient = new ApolloClient({
connectToDevTools: true,
link: new HttpLink({
uri: "/api",
}),
cache: new InMemoryCache(),
resolvers: {
Group: {
icon: () => "noIcon",
},
},
typeDefs: gql`
extend type Group {
icon: String!
}
`,
});
唯一有趣的是一个解析器和类型定义 - 两者都支持组的 icon
字段(即将推出的功能)。
然后我尝试使用以下内容查询服务器:
gqlClient.query({
query: gql`{
groups {
name
icon
}
}`,
})
.then(console.log);
并得到一个大错误:
bundle.esm.js:63 Uncaught (in promise) Error: GraphQL error: Cannot query field `icon' on type `Group'.
at new ApolloError (bundle.esm.js:63)
at bundle.esm.js:1247
at bundle.esm.js:1559
at Set.forEach (<anonymous>)
at bundle.esm.js:1557
at Map.forEach (<anonymous>)
at QueryManager../node_modules/apollo-client/bundle.esm.js.QueryManager.broadcastQueries (bundle.esm.js:1555)
at bundle.esm.js:1646
at Object.next (Observable.js:322)
at notifySubscription (Observable.js:135)
运行 不要求 icon
的相同查询完美运行。我不太确定我做错了什么。 如何模拟 icon
并修复此错误?
我只是 运行ing Apollo Client - 我需要 运行 Apollo Server 才能获得所有功能吗?传出请求似乎没有我的任何类型定义信息,所以我不确定拥有 Apollo 服务器会有什么不同。
Handling @client fields with resolvers
gqlClient.query({
query: gql`
{
groups {
name
icon @client
}
}
`,
});