【问题标题】:Must provide Source with graphql API call in AWS amplify必须在 AWS amplify 中为 Source 提供 graphql API 调用
【发布时间】:2019-10-04 04:25:45
【问题描述】:

我在 AWS amplify 中调用 graphql API 时出错

我导入类似的查询(就像在带有 * 的文档中一样):

import * as queries from '../graphql/queries';

这是我收到错误的 API 请求(必须提供来源):

const data = await API.graphql(graphqlOperation(queries.nearbyZVL, {filter: filter}));

在同一个文件中,如下所示的另一个 API 请求正常工作:

const result = await API.graphql(graphqlOperation(queries.getProfile, { id: cognitoUserId }));

附近的 ZVL 是 AWS appsync 中的自定义查询和解析器。在 appsync 控制台中,查询工作正常!

感谢您的帮助! :)

【问题讨论】:

    标签: amazon-web-services graphql aws-amplify resolver amplifyjs


    【解决方案1】:

    不确定为什么它没有在 codegen 中生成 - 要创建自定义解析器,您是在 appsync 控制台上手动编辑,还是在 /amplify/backend 下添加文件?对于后者,它应该代码生成。如果你做了前者,考虑做后者。

    在您的情况下,您可以简单地执行以下操作:

    const GetNearbyZVL = `...` // the query that works in appsync console
    
    const data = await API.graphql(graphqlOperation(GetNearbyZVL, {filter: filter}));
    

    【讨论】:

      猜你喜欢
      • 2018-04-01
      • 2019-01-11
      • 2018-01-13
      • 2019-06-09
      • 2018-12-30
      • 2020-08-20
      • 2021-08-31
      • 2019-06-02
      • 2014-08-31
      相关资源
      最近更新 更多