GraphQL: Unable to interface with endpoint
See original GitHub issueI’m following the documentation (https://www.ghostwriter.wiki/features/graphql-api) and trying to interface with the GraphQL endpoint
Using the example request:
import json
import requests
headers = {"Content-Type": "application/json", }
def prepare_query(query, operation):
return json.dumps({
"query": query,
"operationName": operation
})
def post_query(headers, data):
return requests.post(
"https://127.0.0.1/v1/graphql",
headers=headers,
data=data
)
# Stacked query with `Login` and `Whoami` operations
query = """
mutation Login {
login(password:"<redacted>", username:"<redacted>") {
token expires
}
}
query Whoami {
whoami {
username role expires
}
}
"""
# Send query and set `Login` as the `operationName`
response = post_query(headers, prepare_query(query, "Login"))
# Get the JWT from the response and add it to the headers
token = response.json()["data"]["login"]["token"]
headers["Authorization"] = f"Bearer {token}"
# Send the query again but execute the `Whoami` operation this time
response = post_query(headers, prepare_query(query, "Whoami"))
# Print our JWT's whoami informaiton
print(response.json())
When using the example request, I receive the following response as part of a 200:
{'errors': [{'extensions': {'path': '$', 'code': 'unexpected'}, 'message': 'Invalid response from authorization hook'}]}
I created an API key and used that directly as the Bearer
token, but receive the same Invalid response from authorization hook
error as above.
I enabled Hasura, and similarly receive an error when attempting to perform the login query (Hasura POST’s to https://127.0.0.1/v1/graphql):
However, I can perform ‘other’ types of queries (when authenticated with the x-hasura-admin-secret
) without an issue:
Can someone please assist with the issue and let me know how I can interface with the API via python without relying on Hasura?
Does the documentation need to be updated
Issue Analytics
- State:
- Created a year ago
- Comments:19
Top GitHub Comments
@zachfey Thanks for confirming that helped! I appreciate the offer, but I think I’ve got everything I need right now. If new certificates help the others that will confirm the certificates are the root cause. I’ll leave this open for a while to collect feedback.
I was having the same issue and generating a new self-signed certificate worked! Thanks @chrismaddalena