Skip to content

Support Connections in cost complexity calculation #761

@freshjsw

Description

@freshjsw

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.

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 this query should increase by a factor of the number of books requested

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

I have a PR that modifies the computeComplexity function in packages/plugins/cost-limit/src/index.ts/ to factor this in to the complexity cost algorithm.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions