Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add optional extensions to GraphQLHTTPResponse #903

Merged
merged 4 commits into from
May 22, 2021
Merged

add optional extensions to GraphQLHTTPResponse #903

merged 4 commits into from
May 22, 2021

Conversation

lijok
Copy link
Member

@lijok lijok commented May 3, 2021

Description

Types of Changes

  • Core
  • Bugfix
  • New feature
  • Enhancement/optimization
  • Documentation

Issues Fixed or Closed by This PR

Checklist

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

@lijok
Copy link
Member Author

lijok commented May 3, 2021

Not sure of the best place to add tests for this?

@botberry
Copy link
Member

botberry commented May 3, 2021

Thanks for adding the RELEASE.md file!

Here's a preview of the changelog:


This release adds an extensions field to the GraphQLHTTPResponse type and also exposes it in the view's response.

This field gets populated by Strawberry extensions: https://strawberry.rocks/docs/guides/extensions#get-results

@codecov
Copy link

codecov bot commented May 3, 2021

Codecov Report

Merging #903 (7facfe0) into main (cb853ed) will increase coverage by 0.43%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main     #903      +/-   ##
==========================================
+ Coverage   97.07%   97.51%   +0.43%     
==========================================
  Files          72       76       +4     
  Lines        2430     2737     +307     
  Branches      345      382      +37     
==========================================
+ Hits         2359     2669     +310     
+ Misses         43       42       -1     
+ Partials       28       26       -2     

@patrick91
Copy link
Member

@lijok looks good to me! I think we should add test for all our integrations, what do you think? :)

@lijok
Copy link
Member Author

lijok commented May 4, 2021

@lijok looks good to me! I think we should add test for all our integrations, what do you think? :)

This is what I was wondering, where best would it be to add tests for these?
New ones or extend existing ones?

@patrick91
Copy link
Member

@lijok looks good to me! I think we should add test for all our integrations, what do you think? :)

This is what I was wondering, where best would it be to add tests for these?
New ones or extend existing ones?

new ones 😊

@lijok
Copy link
Member Author

lijok commented May 22, 2021

@patrick91 this should be ready now

@@ -10,12 +10,15 @@
class GraphQLHTTPResponse(TypedDict, total=False):
data: Optional[Dict[str, Any]]
errors: Optional[List[Any]]
extensions: Optional[Dict[str, Any]]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is marked Optional but can never be None. Should we be setting data["extensions"] = None if there aren't any? (this would apply to data and errors too.)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

data and errors already work like that, for extensions we always return a dict:

def get_extensions_results(self) -> Dict[str, Any]:
data = {}
for extension in self.extensions:
data.update(extension.get_results())
return data

I think we can keep them as optional, I'm not sure if we will change the dict to None at somepoint (for example if there's no extension). So I'd say this is fine :)

We can always update this in another PR :)

Copy link
Member

@patrick91 patrick91 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me 😊 I think we can merge it!

Feel free to request a sticker here: https://forms.gle/dmnfQUPoY5gZbVT67

RELEASE.md Outdated Show resolved Hide resolved
@@ -10,12 +10,15 @@
class GraphQLHTTPResponse(TypedDict, total=False):
data: Optional[Dict[str, Any]]
errors: Optional[List[Any]]
extensions: Optional[Dict[str, Any]]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

data and errors already work like that, for extensions we always return a dict:

def get_extensions_results(self) -> Dict[str, Any]:
data = {}
for extension in self.extensions:
data.update(extension.get_results())
return data

I think we can keep them as optional, I'm not sure if we will change the dict to None at somepoint (for example if there's no extension). So I'd say this is fine :)

We can always update this in another PR :)

@patrick91 patrick91 merged commit 77f1f50 into strawberry-graphql:main May 22, 2021
@DoctorJohn
Copy link
Member

@patrick91 I think #589 can be closed now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants