How to format GraphQL request for node

Hello,

I'm having trouble using request that works in the GraphQL Explorer to my Node.js code.

Here is my request successfully fetching data in my project :
{
allMechanicss {
edges {
node {
title
}
}
}
_allDocuments {
edges {
node {
__typename
}
}
}
}

When I want to feed my GraphQL client, I'm getting this error :
ApolloError: Network error: Unexpected token < in JSON at position 0

I'll use a variable to hold the request like this :

let allTown = gql`
  {
    allMechanicss {
      edges {
        node {
          title
        }
      }
    }
  }
`;

I don't know what to do anymore. I'm really lost

Hi Tristan,

Thanks for contributing to the Prismic community,
In order to help you troubleshoot the issue, I would need to have a look you are running.

Sharing a code snippet of the code that calls apolloGraphQl would be useful as well as the name of the repository that you are call (in a private message if necessary).

Looking forward to your response,
Fares

I found the solution and understood the problem, which came from the documentation.

The solution was to correct the GraphQL endpoint I should use for queries:
Incorrect value : https://vuetoystore.cdn.prismic.io/api/graphql
Correct value : https://vuetoystore.prismic.io/graphql

Apart from the fact that I added "api" by the end of the url, what really confounded me was the "cdn" keyword. The Prismic GraphQL doc at paragraph 3.1 says :

https://your-repository-name.cdn.prismic.io/graphql

It was not clear that "cdn" is not part of the url. I understood the problem outside of Prismic.

Please provide the link to our GraphQL endpoint to our API & Security settings page so we just have to copy paste.

1 Like

Hi Tristan,

Thanks for your feedback; I've done some tests about .cdn, and yes, it seems you are correct.

I will confirm with my team, and then I will apply a fix to the docs.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.