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

Use the hostname and port for GraphQL connections #2878

Closed
wants to merge 7 commits into from

Conversation

shicholas
Copy link

Addresses #2870

@EnricoMi, I noticed that there are some ConnectionClasses, is that what you had envisioned? should the requestJsonAndCheck method be moved to those classes?

Thanks for this awesome lib!

@@ -540,7 +540,7 @@ def graphql_query(self, query: str, variables: Dict[str, Any]) -> Tuple[Dict[str
"""
input_ = {"query": query, "variables": {"input": variables}}

response_headers, data = self.requestJsonAndCheck("POST", "https://api.github.com/graphql", input=input_)
response_headers, data = self.requestJsonAndCheck("POST", f"https://{self.__hostname}:{self.__port}/graphql", input=input_)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Right, that is easier than I thought, but that should do it.

I'd suggest to construct the GraphQl URL in the __init__ method right after o = urllib.parse.urlparse(base_url) (line 397) like this:

o = urllib.parse.urlparse(base_url)
self.__graphql_url = f"{o.scheme}://{o.hostname}:{o.port}/graphql"

or maybe safer would be this

o = urllib.parse.urlparse(base_url)
self.__graphql_url = urlunparse(o._replace(path="graphql"))

And then use self.__graphql_url here instead:

Suggested change
response_headers, data = self.requestJsonAndCheck("POST", f"https://{self.__hostname}:{self.__port}/graphql", input=input_)
response_headers, data = self.requestJsonAndCheck("POST", self.__graphql_url, input=input_)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Above suggestion using urlunparse should also fix the test error ValueError: Port could not be cast to integer value as 'None'.

@EnricoMi
Copy link
Collaborator

We could use some test here.

@codecov-commenter
Copy link

codecov-commenter commented Jan 19, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (603896f) 96.69% compared to head (1f9f56c) 96.69%.
Report is 1 commits behind head on main.

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2878   +/-   ##
=======================================
  Coverage   96.69%   96.69%           
=======================================
  Files         142      142           
  Lines       14533    14537    +4     
=======================================
+ Hits        14053    14057    +4     
  Misses        480      480           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@EnricoMi
Copy link
Collaborator

I have fixed the imports...

@shicholas
Copy link
Author

@EnricoMi Where's a good place I can find a test using enterprise GitHub? Thanks!

@EnricoMi
Copy link
Collaborator

I have added a few tests. Please test the code against your enterprise server.

@@ -52,6 +52,8 @@
# Copyright 2023 Phillip Tran <phillip.qtr@gmail.com> #
# Copyright 2023 Trim21 <trim21.me@gmail.com> #
# Copyright 2023 adosibalo <94008816+adosibalo@users.noreply.github.com> #
# Copyright 2024 Enrico Minack <github@enrico.minack.dev> #
# Copyright 2024 nick <nick_shook@apple.com> #
Copy link
Author

@shicholas shicholas Jan 21, 2024

Choose a reason for hiding this comment

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

I don't need attribution here, thanks!

@shicholas
Copy link
Author

This is close, our enterprise server is at /api/graphql not /graphql, so had to configure that. Should the /api part be an extra optional parameter? Thanks!

@EnricoMi
Copy link
Collaborator

What is the path of your v3 REST API? Is it /api/v3?

@shicholas
Copy link
Author

yes, it's /api/v3

@EnricoMi
Copy link
Collaborator

If you don't want the attribution, I have to do this without your commits: #2880

@EnricoMi
Copy link
Collaborator

Fixed in #2880.

@EnricoMi EnricoMi closed this Jan 25, 2024
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.

None yet

3 participants