ardatan / ardatan/graphql-mesh

The rateLimit plugin is returning data when multiple queries or fragment are requested

Open
#5,232 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
3.5k
Forks
363
Avg merge
6h 10m
Merged PRs (30d)
19

Description

### Issue workflow progress

_Progress of the issue based on the
[Contributor Workflow](https://github.com/the-guild-org/Stack/blob/master/CONTRIBUTING.md#a-typical-contributor-workflow)_

- [ ] 1. The issue provides a reproduction available on
[Github](https://github.com/jmolivas/graphql-mesh-rate-limit)
[Cloudflare Deployment](https://graphql-mesh-rate-limit.octahedroid.workers.dev/graphql?query=fragment+Film+on+Film+%7B%0A++id%0A++title%0A%7D%0A%0Aquery+swapi+%7B%0A++%0A++film%28id%3A+%22ZmlsbXM6MQ%3D%3D%22%29+%7B%0A++++...Film%0A++%7D%0A++%0A++allFilms%28first%3A+3%29+%7B%0A++++films+%7B%0A++++++id%0A++++++title%0A++++%7D%0A++%7D%0A++%0A%7D%0A)

> Make sure to fork this template and run `yarn && yarn build && yarn start` in the terminal.
>
> Please make sure Mesh package versions under `package.json` matches yours.

- [ ] 2. A failing test has been provided
- [ ] 3. A local solution has been provided
- [ ] 4. A pull request is pending review

---

**Describe the bug**

The `rateLimit` plugin is returning query data of a query configured using the rateLimit plugin when multiple queries or fragment are requested.

The result contains the error message but also the data of the query.

Mesh config file: `.meshrc.yaml` contents
```
serve:
playground: true
browser: false

sources:
- name: SWAPI
handler:
graphql:
endpoint: https://swapi-graphql.netlify.app/.netlify/functions/index

plugins:
- rateLimit:
config:
# Add as many rules as you want
- type: Root
field: allFilms
max: 5 # requests limit for a time period
ttl: 30000 # time period
identifier: '{context.req.socket.remoteAddress}'
```

Dependencies at `package.json` file

```
{
"name": "graphql-mesh-rate-limit",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"build": "mesh build",
"clean": "rm -rf .mesh/",
"start": "mesh start",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"@graphql-mesh/cli": "^0.82.27",
"@graphql-mesh/graphql": "^0.34.10",
"@graphql-mesh/plugin-rate-limit": "^0.2.19",
"graphql": "^16.6.0"
}
}

```

Queries and fragment
```
fragment Film on Film {
id
title
}

query swapi {

film(id: "ZmlsbXM6MQ==") {
...Film
}

allFilms(first: 3) {
films {
id
title
}
}

}

```

**To Reproduce** Steps to reproduce the behavior:

**Expected behavior**

**Environment:**

- OS:
- `@graphql-mesh/...`:
- NodeJS:

**Additional context**

ERRORING WHEN:

- Two queries using fragment
![image](https://user-images.githubusercontent.com/366275/226145291-072fdcc5-385b-47ed-b799-c2c5b2935a3a.png)

- Two queries without fragment
![image](https://user-images.githubusercontent.com/366275/226145506-74d76cb5-cb2a-495a-8555-f6102acf2f5a.png)

- Two queries and one is commented using fragment
![image](https://user-images.githubusercontent.com/366275/226145396-65ccf069-9fe6-464f-99bd-142e39a5ee48.png)

- ERROR: One Query using fragment
![image](https://user-images.githubusercontent.com/366275/226145422-11523492-2a0a-4d9f-84fd-72ae3e0c0b50.png)

SUCCESS:
- Two queries and one is commented no fragments
![image](https://user-images.githubusercontent.com/366275/226145594-d0c76bd1-15cf-4199-8ed9-2c2fb5e229e9.png)

- One query no fragments
![image](https://user-images.githubusercontent.com/366275/226145451-0c2769ee-d83d-4d50-a78e-921dcc060394.png)

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the linked graphql-mesh-rate-limit reproduction, its .meshrc.yaml rateLimit configuration, and package.json; run yarn, yarn build, and yarn start as described. Compare the single-query and multiple-query or fragment cases against the reported result, and consider the issue done when rate-limited responses no longer include query data alongside the error.

Written by the indexing model from the issue text.

Assessment

Tech stack
graphql, typescript
Domain
api, security
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
28/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.