【问题标题】:Apollo type defs ignoredApollo 类型定义被忽略
【发布时间】: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


    【解决方案1】:

    Handling @client fields with resolvers

    gqlClient.query({
        query: gql`
            {
                groups {
                    name
                    icon @client
                }
            }
        `,
    });
    

    【讨论】:

      猜你喜欢
      • 2020-08-29
      • 2020-08-21
      • 2020-11-24
      • 2023-03-14
      • 2010-09-10
      • 2020-07-11
      • 1970-01-01
      • 2019-11-25
      • 1970-01-01
      相关资源
      最近更新 更多