prismicio / gatsby-source-prismic-graphql

Gatsby source plugin for Prismic GraphQL
MIT License
17 stars 14 forks source link

Long uid slugs cause "Unexpected token < in JSON at position 0" errors #50

Open fitzgers opened 4 years ago

fitzgers commented 4 years ago

I ran across a strange error where pages with long url slugs would fail at build time with the following error:

 ERROR #85901  GRAPHQL

There was an error in your GraphQL query:

Unexpected token < in JSON at position 0

   1 | query SubpageQuery($uid: String!) {
   2 |   prismic {
>  3 |     allSubpages(uid: $uid) {
     |     ^
   4 |       edges {
   5 |         node {
   6 |           _meta {
   7 |             uid
   8 |             id
   9 |           }
  10 |           title
  11 |           meta_description
  12 |           meta_keywords
  13 |           meta_title

File path: /Documents/dev/npf-website/src/templates/Subpage.jsx
Url path: /step-therapy-guardrails-in-covid-19-relief-legislation/

The pages failed to build until I trimmed the UIDs used as URL slugs down to something shorter in Prismic and published.

What is most strange to me about this is these are pages that previously had been building successfully, until I added a new field to this page type in Prismic. If I removed any reference to this new field (just a rich text field, nothing fancy) in the graphql query, the pages would build. If I put it back in, they would not, until I trimmed the UID length.

MarcMcIntosh commented 4 years ago

Hi @fitzgers That's an interesting error, Have you tried the query in prismics graphql browser? [repo-name].prismic.io/graphql

fitzgers commented 4 years ago

@MarcMcIntosh I can get a pared down version of the query to work in the prismic graphql browser, when using one of the long slugs. When I try the full query (it is quite large) on that slug or any of the others, I get a "Request-URI Too Large" error.

MarcMcIntosh commented 4 years ago

Hi @fitzgers Yes, since our graphql api use get requests we do have a limit to how long a query can be.

What's the full query? we can take a look at trying to optimise it :)