【问题标题】:AWS Amplify Connect does not return dataAWS Amplify Connect 不返回数据
【发布时间】:2019-09-02 23:32:02
【问题描述】:

我有一个非常简单的 GraphQL 服务器,如果使用 { hello } 查询,它会返回 "Hello World"

我已经为 Amplify 配置了 GraphQL 端点和区域,并验证了连接与这个 sn-p 一起工作:

**THIS IS WORKING**

import {API, graphqlOperation} from 'aws-amplify'

const ListEvents = `query {
  hello
}`

async getNote() {
    try {
      const result = await API.graphql(graphqlOperation(ListEvents))
      console.log(result)
    } catch(e) {
      console.log("Unable to fetch hello")
      console.log(e.response)
    }
}

RETURNS:
{
  "data": {
    "hello": "Hello world!"
  }
}

我的问题

我想使用Connect中的Connect,如HERE所述

我使用了以下代码并将其包含在我的应用程序的返回中:

**THIS IS NOT WORKING**

import { Connect } from "aws-amplify-react";

const ListEvents = `query {
  hello
}`

<Connect query={graphqlOperation(ListEvents)}>
    {(obj, ...rest) => {
      console.log(obj);
      console.log(rest);
    }}
</Connect>

返回:

in another Stack Overflow question 讨论了两个空响应的原因,但这根本不会返回预期的数据。

你能帮我弄清楚吗?

【问题讨论】:

    标签: reactjs amazon-web-services graphql aws-sdk


    【解决方案1】:

    尝试使用以下语法:

    <Connect query={graphqlOperation(listEvents)}>
        {({ data , loading, error }) => {
            if (error) return (<h3>Error</h3>);
            if (!data) return (<h3>No events found</h3>);
            if (loading) return (<h3>Loading...</h3>);
            return (<h3>{data.hello}</h3> );
        }}
    </Connect>
    

    【讨论】:

      猜你喜欢
      • 2018-11-09
      • 2020-12-28
      • 2019-05-06
      • 2020-07-22
      • 2021-01-01
      • 2019-09-13
      • 1970-01-01
      • 2021-03-09
      • 1970-01-01
      相关资源
      最近更新 更多