NextJs app reached GraphQL 'grammar' token limit

Enonic version: 7.14.4
OS: MacOS

Hi,

We want to build our existing enonic app as a nextJs app. We have gotten quite a bit done allready, but have hit a wall. It seems that we have reached the size limit of our graphql query. It needs to be said that we have quite a few parts and macros in our current enonic app. Since the graphql query being sent (from the nextjs app) to enonic is the same regardless of the content on the page (made in content studio), it gets really big. In fact so big that we get the following error:

{
errorType: ‘InvalidSyntax’,
message: “More than 15,000 ‘grammar’ tokens have been presented. To prevent Denial Of Service attacks, parsing has been cancelled.”,
locations: [ { line: 1, column: 69605 } ]
}

I don’t consider this a bug, as this is (as i understand) a limitation set by graphql and can be overridden in configuration. However, I believe this is something we do not have access to change. So my question is; Is there a way we can work around this issue without increasing the token-limit? Or is increasing the token-limit the way to go and how do we go about doing that?

Hi Geir. Are you using our nextJS integration, or do you define the queries yourself? Next.xp will automatically optimize the query based on the current page you are rendering.

If you are using this, and still reaching the limit, I guess the limit must be increased.

Hi Thomas. We have based our code on the next-js-adapter so we are not building the query entirely our selves. We use configQuery to fetch fields for parts and macros which are not fetched by the common query (if that answers your question).

Ok. Do you know if it is the config query, or the component query that exceeds the limit?

The adapter normally performs two queries per page

I’m pretty sure it’s the config query since that is the one we mainly use.

We have based our code on the next-js-adapter so we are not building the query entirely our selves.

Can you explain what this means in practice? Are you using fetchContent method from next-js-adapter? In that case query will be generated and optimised automatically using gqlmin.

Ok. Seems there is no way to configure max size of query ATM. Configuration options - Enonic Developer Portal

I guess you should create a support ticket so we can figure out a :sun_with_face:lution

@Alan We have based our project on the nextxp demo (GitHub - enonic/nextxp-demo) and have just followed the same way of doing stuff as the demo project.

Still, it would be nice to be able to set the query size in a configuration file. I’ll make a ticket on it.