strawberry icon indicating copy to clipboard operation
strawberry copied to clipboard

Add support for extensions to the HTTP protocol

Open omarzouk opened this issue 3 months ago • 7 comments

Description

The GQL spec specifies a field called extensions as part of the request parameters spec in the HTTP protocol. We are missing support for this

Adding the field to be parsed and propagating it as part of the Info object. This is done by wrapping the entire context object in a temporary container, and then unwrapping it inside the Info context getter. A new function is also added to the Info class called input_extensions. It exposes the extensions data.

Example usage by the end-user:

@strawberry.field
def value_from_extensions(self, key: str, info: strawberry.Info) -> str:
    return info.input_extensions[key]

Types of Changes

  • [X] Core
  • [ ] Bugfix
  • [X] New feature
  • [ ] Enhancement/optimization
  • [X] Documentation

Issues Fixed or Closed by This PR

  • fixes https://github.com/strawberry-graphql/strawberry/issues/3224

Checklist

  • [x] My code follows the code style of this project.
  • [x] My change requires a change to the documentation.
  • [ ] I have updated the documentation accordingly.
  • [x] I have read the CONTRIBUTING document.
  • [x] I have added tests to cover my changes.
  • [x] I have tested the changes and verified that they work and don't break anything (as well as I can manage).

Summary by Sourcery

This pull request introduces support for the 'extensions' field in HTTP requests, allowing it to be parsed and included in the ExecutionContext. This change is accompanied by updates to the documentation and new tests to ensure proper functionality.

  • New Features:
    • Added support for the 'extensions' field in HTTP requests, allowing it to be parsed and propagated as part of the ExecutionContext.
  • Documentation:
    • Updated documentation to reflect the new support for the 'extensions' field in HTTP requests.
  • Tests:
    • Added tests to verify the correct handling and propagation of the 'extensions' field in both GET and POST HTTP requests.

omarzouk avatar Apr 19 '24 17:04 omarzouk

Hi, thanks for contributing to Strawberry 🍓!

We noticed that this PR is missing a RELEASE.md file. We use that to automatically do releases here on GitHub and, most importantly, to PyPI!

So as soon as this PR is merged, a release will be made 🚀.

Here's an example of RELEASE.md:

Release type: patch

Description of the changes, ideally with some examples, if adding a new feature.

Release type can be one of patch, minor or major. We use semver, so make sure to pick the appropriate type. If in doubt feel free to ask :)

Here's the tweet text:

🆕 Release (next) is out! Thanks to Omar Marzouk for the PR 👏

Get it here 👉 https://strawberry.rocks/release/(next)

botberry avatar Apr 19 '24 17:04 botberry

Hi, thanks for contributing to Strawberry 🍓!

We noticed that this PR is missing a RELEASE.md file. We use that to automatically do releases here on GitHub and, most importantly, to PyPI!

So as soon as this PR is merged, a release will be made 🚀.

Here's an example of RELEASE.md:

Release type: patch

Description of the changes, ideally with some examples, if adding a new feature.

Release type can be one of patch, minor or major. We use semver, so make sure to pick the appropriate type. If in doubt feel free to ask :)

Here's the tweet text:

🆕 Release (next) is out! Thanks to Omar Marzouk for the PR 👏

Get it here 👉 https://strawberry.rocks/release/(next)

botberry avatar Apr 19 '24 17:04 botberry

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 96.49%. Comparing base (d502cd7) to head (cbd138b). Report is 35 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3461   +/-   ##
=======================================
  Coverage   96.49%   96.49%           
=======================================
  Files         509      509           
  Lines       32862    32864    +2     
  Branches     5421     5421           
=======================================
+ Hits        31710    31713    +3     
+ Misses        941      940    -1     
  Partials      211      211           

codecov[bot] avatar Apr 19 '24 17:04 codecov[bot]

CodSpeed Performance Report

Merging #3461 will not alter performance

Comparing omarzouk:add_http_extensions (cbd138b) with main (d502cd7)

Summary

✅ 12 untouched benchmarks

codspeed-hq[bot] avatar Apr 19 '24 17:04 codspeed-hq[bot]