question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

GraphQL client not taking available credentials

See original GitHub issue

Hi there,

I was playing with the brand new GraphQL client embedded in the lib but I noticed that it was not taking the credentials.

Even the Readme suggest that to use the GraphQL step 1-5 are required (getting a token with oath) to work, the doc says otherwise : https://shopify.dev/docs/admin-api/graphql/getting-started

Include the access token as a X-Shopify-Access-Token header in all GraphQL queries and mutations

Non working example:


import shopify

API_KEY = "mykey"
PASSWORD = "mypassword"
website = "mywebsite"

shopify.ShopifyResource.set_site("https://%s:%s@%s.myshopify.com/admin/api/2020-01" % ( API_KEY, PASSWORD, website))

# returns HTTPError: HTTP Error 401: Unauthorized
shopify.GraphQL().execute("{ shop { name id } }")

A simple fix outside of the lib is the following :

# manual fix . shopify.ShopifyResource.password is set by the set_url previous call
shopify.ShopifyResource.headers.update({'X-Shopify-Access-Token': shopify.ShopifyResource.password })

# returns expected data
shopify.GraphQL().execute("{ shop { name id } }")

This does not happen if we create a shopify session and use it :

session = shopify.Session("%s.myshopify.com" % website, "2020-01", PASSWORD)
shopify.ShopifyResource.activate_session(session)

I believe this should be patched in the lib itself at is an easy one. Adding the line :

self.headers.update({'X-Shopify-Access-Token': shopify.ShopifyResource.password })

after https://github.com/Shopify/shopify_python_api/blob/master/shopify/resources/graphql.py#L10 seems to be enough.

I can do the PR if you want even if I believe it might take longer to wait for my PR than committing the fix 😉

Regards

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:7
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
tanemacommented, Oct 1, 2020

Okay, I am going to update the readme. Basically you should not have to use set_site and you should definitely not need to set headers yourself. You should just be able to setup your sessions and use them, both temporary and not.

0reactions
jmath222commented, Sep 25, 2020

Just wanted to comment that this is still an issue as of today. The tutorial is broken for GraphQL + private apps.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Authentication - Apollo GraphQL Docs
Apollo Client uses the ultra flexible Apollo Link that includes several options for authentication. Cookie. If your app is browser based and you...
Read more >
Amplify GraphQL No Credentials Error in NextJs Application
I'm using API key authentication by default. I'm not using amplify add auth because I've a requirement to use custom auth. I know...
Read more >
GraphQL returns a "success" response when invalid ... - GitLab
We are validating that the user is who they say they are. When the request contains an invalid token, it means that the...
Read more >
Build a GraphQL client application to consume protected ...
Part 1: Externalized authorization for GraphQL using the Cloudentity ... If an accessToken is not available in the local storage, ...
Read more >
Resolve unauth errors for GraphQL requests in AWS AppSync
401 Unauthorized response · The Authorization or x-api-key header is present and contains the correct credentials for the authorization mode that ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found