【发布时间】:2020-09-27 12:43:44
【问题描述】:
我已经做了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!
}
`,
});
唯一奇特的是一个解析器和类型 def - 两者都支持组的 icon 字段(即将推出的功能)。
然后我尝试使用以下内容查询服务器:
gqlClient.query({
query: gql`{
groups {
name
icon
}
}`,
})
.then(console.log);
并得到一个很大的“ol”错误:
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 并修复此错误?
我只运行 Apollo Client - 我是否需要运行 Apollo Server 才能获得所有功能?传出的请求似乎没有任何我的类型定义信息,所以我不确定拥有 Apollo 服务器会有什么不同。
【问题讨论】:
标签: javascript apollo apollo-client