Conversation

uriyay

What kind of change does this PR introduce?

Added support in requests.Session in order to solve #54

What is the current behavior?

client.execute() calls to requests.post(), using a session object is not available.

What is the new behavior?

client.execute() gets a new parameter named session that holds a Session object that will be used for making the POST request.
The new parameter is None by default, if its None a new session is created and will be used for making the POST request.

Does this PR introduce a breaking change?

No, you can still skip passing session parameter and the code will act the same as before.

Other information

This feature allows users to:

  1. Log in with a complex flow such as oidc, that sets an authorization cookies for the session
  2. Prevent requests from using .netrc file by default, by setting session.trust_env to False:
    Don't override Authorization header when contents are bearer token (or any other token) psf/requests#3929

@xkludge

@uriyay thanks for the contribution, however this change as you can see breaks tests on the existing functionality.

We should potentially introduce checking if session is the instance of Session. If it is not then we perform the default requests.post.

If session is the instance of Session then we can produce a session.post.

Note please include tests to cover these scenarios.

…n. added tests for testing client.execute() with a given session object

Choose a reason for hiding this comment

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

Thanks for the update. I left some feedback on the changes.

**kwargs: Any,
):
"""Make synchronous request to graphQL server."""
request_body = self.__request_body(
query=query, variables=variables, operation_name=operation_name
)

result = requests.post(
post_method = requests.post
if session:
Copy link
Contributor

Choose a reason for hiding this comment

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

We should validate the type that session is a Session to prevent injection.

Suggested change
if session:
if isinstance(session, Session):

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

Successfully merging this pull request may close these issues.