最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

How to set timeout for GraphQL client generated by aws-amplify? - Stack Overflow

programmeradmin2浏览0评论

I'm getting a following timeout error when execution within the graphql query handler takes longer than 3.01 sec.

{
    "data": {
        "service_call": null
    },
    "errors": [
        {
            "path": [
                "service_call"
            ],
            "data": null,
            "errorType": "Lambda:Unhandled",
            "errorInfo": null,
            "locations": [
                {
                    "line": 2,
                    "column": 3,
                    "sourceName": null
                }
            ],
            "message": "2025-03-30T16:09:56.670Z 7b781466-266a-4c34-95ba-70c1e34e4756 Task timed out after 3.01 seconds"
        }
    ]
}

Here is my dummy code that represents the issue:

const schema = a.schema({
   ...
   service_call: a
    .query()
    .arguments({ content: a.string() })
    .returns(a.ref('ServiceResponse'))
    .authorization(allow => [allow.publicApiKey()])
    .handler(a.handler.function(serviceHandler)),
   ...
});

const client = generateClient<Schema>()

const {data, errors} = await client.queries.service_call({
      content: "some input"
    })

const serviceHandler = defineFunction({
  entry: './service_call/handler.ts'
})

// handler in handler.ts
export const handler: Schema["service_call"]["functionHandler"] = async (event, context) => {

  await new Promise(f => setTimeout(f, 4000));   <===== here I'm intentionally setting 4 sec > 3.01 sec highlight the problem
  const res = "service response";

  return {
    content: `Model response: ${res}`
  };
};

I found somewhat relevant question here on SO but in my case I'm using aws-amplify's generateClient method and I don't see a way how to specify a custom timeout.

发布评论

评论列表(0)

  1. 暂无评论