AWS Amplify (GraphQL) - 使用 "graphqlOperation" 与普通查询?
AWS Amplify (GraphQL) - Using "graphqlOperation" vs Normal Query?
可能是一个简单的问题,但我最初一直在 AWS Amplify 中使用 graphqlOperation
进行 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
class?它们似乎 return 相同的有效载荷。大多数文档似乎都使用 graphqlOperation
进行引用。我只是不确定它带来了什么好处。
谢谢!
T
您不能将 graphqlOperation 与 authMode 一起使用。仅使用 API.graphql() 代替。
“前面的示例使用 graphqlOperation 函数。该函数仅创建一个具有两个属性查询和变量的对象。为了使用 authMode,您需要像前面示例中提到的那样传递该对象。”
使用 graphqlOperation 的原因之一是如果您的方法 listMessages 有任何参数,您可以在 graphqlOperation(listMessages, {...params}) 的调用中传递这些参数
可能是一个简单的问题,但我最初一直在 AWS Amplify 中使用 graphqlOperation
进行 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
class?它们似乎 return 相同的有效载荷。大多数文档似乎都使用 graphqlOperation
进行引用。我只是不确定它带来了什么好处。
谢谢! T
您不能将 graphqlOperation 与 authMode 一起使用。仅使用 API.graphql() 代替。
“前面的示例使用 graphqlOperation 函数。该函数仅创建一个具有两个属性查询和变量的对象。为了使用 authMode,您需要像前面示例中提到的那样传递该对象。”
使用 graphqlOperation 的原因之一是如果您的方法 listMessages 有任何参数,您可以在 graphqlOperation(listMessages, {...params}) 的调用中传递这些参数