【问题标题】:AWS Amplify (GraphQL) - Using "graphqlOperation" vs Normal Query?AWS Amplify (GraphQL) - 使用“graphqlOperation”与普通查询?
【发布时间】:2021-01-25 12:26:18
【问题描述】:

可能是一个简单的问题,但我最初一直在使用 graphqlOperation 在 AWS Amplify 中进行 API 查询。最近我开始使用 Cognito 用户池。在我的一生中,我无法将authMode 传递给它并最终使用了普通查询。

## normal query - works
await API.graphql({query: listForms, authMode: 'AMAZON_COGNITO_USER_POOLS'});

## using graphqlOperation - does not work (Unauthorized)
await API.graphql(graphqlOperation(listForms,  { authMode: 'AMAZON_COGNITO_USER_POOLS' }));

我可以使用普通查询,但我想知道如果普通查询似乎就足够了,你为什么还要使用 graphqlOperation 类?它们似乎都返回相同的有效载荷。大多数文档似乎都使用graphqlOperation 进行引用。我只是不确定它会带来什么好处。

谢谢! T

【问题讨论】:

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


    【解决方案1】:

    您不能将 graphqlOperation 与 authMode 一起使用。请改用 API.graphql()。

    “前面的例子使用了 graphqlOperation 函数。这个函数只创建一个有两个属性查询和变量的对象。为了使用 authMode,你需要像前面例子中提到的那样传递这个对象。”

    Configure authorization modes

    【讨论】:

      猜你喜欢
      • 2019-09-07
      • 2019-11-30
      • 2020-07-27
      • 2022-10-24
      • 2020-07-22
      • 2021-02-21
      • 2020-01-17
      • 2020-07-01
      • 1970-01-01
      相关资源
      最近更新 更多