How to set timeout to graphql-client

How to set timeout to graphql-client


7

I’m trying to set timeout with prisma-labs/graphql-request. I’ve tried the way described here – https://github.com/prisma-labs/graphql-request/issues/103.

const client = new GraphQLClient(config.url, {
  timeout: 30000,
  headers: {
    Authorization: `Bearer ${token}`
  }
})

My compiler complains as timeout is not directly present in Options interface – https://github.com/prisma-labs/graphql-request/blob/master/src/types.ts#L7.

Should I need to extend the Options interface to use timeout field?

6

  • You could extend it, might be worthwhile doing a setTimeout() if you're just wanting to wait 30 seconds before initializing the client/GraphQLClient.

    – Arthur Weborg

    Nov 14, 2019 at 21:44

  • At that, I find it interesting that you were doing the exact syntax in the issue that was supposed to work!

    – Arthur Weborg

    Nov 14, 2019 at 21:44

  • 1

    Its not a wait before initializing client. I meant the timeout while fetching the API call result. Ex: if it takes more than 5 secs, I might want to stop the execution and free resources and show error page to user.

    – unknown_boundaries

    Nov 14, 2019 at 22:19

  • Ahh gotcha, makes sense, thanks for the clarity!

    – Arthur Weborg

    Nov 14, 2019 at 22:20

  • 1

    Yes, it's compile time error as well.

    – unknown_boundaries

    Nov 14, 2019 at 22:33

1 Answer
1


0

if you calling this thru regular api for your service remember it might also timing out on your webserver like express or fastify, try to increase all timeouts there as well e.g

fastify: {
  trustProxy: true,
  connectionTimeout: 15000,
},



Leave a Reply

Your email address will not be published. Required fields are marked *