Hi! This is my first time using GraphQL on Prismic and as I mentioned on GraphiQL, syntax and retrieved data looks great but when I make the request from my NextJS code, I get an error of:
{"type":"api_validation_error","message":"Unable to parse fetch query Invalid fetch parsing Exception.\n\nInvalid input '(', expected AlphaNum, AlphaChar, '_', '-', WS or bracketed
The error basically says that my " ( " character can't be parsed, if I remove the part of the code that uses the parenthesis, everything works fine.
@Pau hello! Yes the first thing I did was validate the query and the results with the graphql explorer from my repo.
(I'm trying to upload a screenshot but the dialog box freeze)
I don't know if this is relevant or not but the request from my code it's been made tohttps://your-repo-name.cdn.prismic.io/api/v2/documents/search?graphQuery=.....
That's the issue. GraphQuery uses GraphQL syntax but is not GraphQL.
You need to send the GraphQL requests to: https://your-repo-name.prismic.io/graphql
And GraphQueries are sent to the REST API of your repo: https://your-repo-name.cdn.prismic.io/api/v2/
Ok... but for the GraphQueries sent to the REST API of my repo (https://your-repo-name.cdn.prismic.io/api/v2/). Is not possible to use arguments/parameters?
e.g.: I want the first 5 blog posts from a specific blog category.
Pau, yes, I've read those docs but I don't quite understand how I can retrieve the first "n" elements (in this case blog posts) without retrieving ALL posts.
How or where can I add the params in the REST API so I can accomplish to get for example the first (or last) 5 posts from a particular blog category?
1. getAllByType() with limit: getAllByType() will fetch all documents. Setting pageSize will decrease the page size, but the function will still query every page available. To limit the number of documents returned, the limit option can be passed. Once the function reaches that limit, it will stop requesting pages.
await client.getAllByType('blog', { limit: 3 })
2. getByType() with pageSize: getByType() with pageSize will also limit the results. You will receive pagination metadata along with the data using this method, however, so you’ll need to access the results using res.results .