Shopify, GraphQL and Node (library)

Solved
Highlighted
New Member
2 0 0

Hello Guys, 

 

I want to know if there's some official library/component to help us in the implementation of GraphQL with Node. Currently we are using "shopify-api-node" and we are looking for something similar for GraphQL.

 

Thanks!

 

Lucas

0 Likes
Shopify Partner
4 1 6

This is an accepted solution.

I don't know of any official ones, but we use axios for our node-based GraphQL queries. Took me a while to figure out the right syntax, but now it's easy. I'm including a sample of the code below to give you a head start if you choose to use axios:

 

const token = ...
const url = ...
const variables = {
  cursor: ...,
  range: ...
}
axios({
  headers: {
    'Content-Type': 'application/json',
    'X-Shopify-Access-Token': token
  },
  method: 'post',
  data: {
    query: `
      query($range: String!, $cursor: String) {
        tenderTransactions(first: 50, after: $cursor, query: $range) {
          edges {
            node {
              id
            }
            cursor
          }
        }
      }
    `,
    variables: variables
  },
  url: url
}).then(result => {
  console.log(result.data)
}).catch(error => {
  console.log(error)
})
3 Likes
Highlighted
New Member
2 0 0

hi Joe,

 

Thank you for your response, it will be useful for us. In this moment we decided to not use GraphQL in our application but probably in the future. We can follow your example, we have been working with axios before and it is really simple and useful. Thanks!

 

Lucas.

0 Likes
Highlighted
Shopify Partner
14 2 1

I know you selected a solution already but just in case someone else finds this:

https://www.npmjs.com/package/shopify-graphql-node

1 Like
Highlighted
New Member
1 0 0

Hi Joe, When I use Axios to send a graphql query, I get an error due to CORS not allowing me to make a request to the store, but can successfully use CURL to send a request from my terminal. Do you have any idea as to how I can get past the CORS rejection? 

0 Likes