-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Calling GraphQL query with variables returns 400 #3001
Copy link
Copy link
Closed
Description
I'm trying to run a GraphQL query to retrieve branch protection rules. Running the query in GitHub's GraphQL Explorer works as expected but when I attempt to run it with the library, I'm getting back a 400.
This is the code:
BRANCH_PROTECTION_GRAPHQL_QUERY = '''query($owner: String!, $name: String!) {
repository(owner: $owner, name: $name) {
branchProtectionRules(first: 100) {
nodes {
id
pattern
matchingRefs(first: 10) {
totalCount
}
}
}'''
token = "my_gh_token"
auth = github.Auth.Token(token)
gh = Github(auth=auth)
res_header, data = gh._Github__requester.graphql_query(query=GET_BRANCH_PROTECTION_GRAPHQL_QUERY, variables={"owner": "kgal-pan", "name": "my_repo"})I printed out the actual payload sent to the GraphQL endpoint and found that the variables include an extra parent object input in the variables object:
{
"query": "query($owner: String!, $name: String!) {\\n repository(owner: $owner, name: $name) {\\n branchProtectionRules(first: 100) {\\n nodes {\\n id\\n pattern\\n matchingRefs(first: 10) {\\n totalCount\\n }\\n }\\n }\\n }\\n}",
"variables": {
"input": {
"owner": "kgal-pan",
"name": "my_repo"
}
}
}
This results in an error from GitHub service:
{"errors": [{"extensions": {"value": null, "problems": [{"path": [], "explanation": "Expected value to not be null"}]}, "locations": [{"line": 1, "column": 7}], "message": "Variable $owner of type String! was provided invalid value"}, {"extensions": {"value": null, "problems": [{"path": [], "explanation": "Expected value to not be null"}]}, "locations": [{"line": 1, "column": 24}], "message": "Variable $name of type String! was provided invalid value"}]}The input object is added in https://github.com/PyGithub/PyGithub/blob/main/github/Requester.py#L575.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels