graphql-armor icon indicating copy to clipboard operation
graphql-armor copied to clipboard

feat/connectcost: Add support for connections in complexity calculation

Open freshjsw opened this issue 10 months ago • 2 comments

The cost complexity cost-limit plugin does not take into account how many entities are being returned when either the first or last argument are specified at the field level. This PR supports calculating complexity based on the number of records requested in the query.

This commit fixes #761

These two examples which have the same complexity cost (I have omitted edges and pageInfo to keep these examples simple)

query simpleQuery {
      books {
        title
        author
      }
}

query connectionQuery {
      books(first: 1) {
        title
        author
      }
}

The cost complexity of the query below should increase by a factor of the number of books requested

query connectionQuery {
      books(first: 3) {
        title
        author
      }
}

Note the PR does not currently handle VariableDefinitions but will handle the example above

freshjsw avatar Feb 08 '25 16:02 freshjsw

⚠️ No Changeset found

Latest commit: 8c0bd568826eedfab2ec03b3dfa1b952651ccc98

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

changeset-bot[bot] avatar Feb 08 '25 16:02 changeset-bot[bot]

I think this PR could be closed as it was merged and released here?

Urigo avatar Sep 17 '25 16:09 Urigo