How do I query the GraphQL endpoint with Axios/Got?

Hi,
If you didn’t succeed to do it with axios or got, it’s exactly the same as it’s done by fetch like the way @marcellothearcane did it.

Here’s a recap (in node):

const fetch = require('node-fetch');
const axios = require('axios').default;
const got = require('got').default;

const query = `query {
    allCss {
        totalCount
    }
}`

fetch('http://<YOUR_REPO>.prismic.io/graphql?query=' + encodeURIComponent(query), {
    headers: {
        'Prismic-ref': '<YOUR_MASTER_REF>',
        'Authorization': 'Token <YOUR_TOKEN>'
    }
}).then(r => r.json()).then(console.log)

axios.get('http://<YOUR_REPO>.prismic.io/graphql?query=' + encodeURIComponent(query), {
    headers: {
        'Prismic-ref': '<YOUR_MASTER_REF>',
        'Authorization': 'Token <YOUR_TOKEN>'
    }
}).then((response) => console.log(response.data))

got.get('http://<YOUR_REPO>.prismic.io/graphql?query=' + encodeURIComponent(query), {
    headers: {
        'Prismic-ref': '<YOUR_MASTER_REF>',
        'Authorization': 'Token <YOUR_TOKEN>'
    }
}).json().then(console.log)
2 Likes