movio / bramble

A federated GraphQL API gateway
https://movio.github.io/bramble/
MIT License
497 stars 53 forks source link

Add a slow example service #220

Closed pkqk closed 1 year ago

pkqk commented 1 year ago

Add the ability to trigger the limits plugin by adding a slow-service to the examples.

It adds a delay field on the Gizmo that takes a duration to sleep for:

query {
  randomGizmo {
    id
    delay(duration: "500ms")
  }
}

which returns how long it took:

{
  "data": {
    "randomGizmo": {
      "id": "999",
      "delay": "503.987916ms"
    }
  }
}

and if you hit the timeout you get a response like:

{
  "errors": [
    {
      "message": "error during request: Post \"http://slow-service:8080/query\": context deadline exceeded (Client.Timeout exceeded while awaiting headers)",
      "path": [
        "randomGizmo"
      ],
      "locations": [
        {
          "line": 4,
          "column": 5
        }
      ],
      "extensions": {
        "selectionSet": "{ delay(duration: \"2s\") _bramble_id: id _bramble__typename: __typename }"
      }
    }
  ],
  "data": {
    "randomGizmo": {
      "id": "476",
      "delay": null
    }
  }
}