directus / directus

The flexible backend for all your projects 🐰 Turn your DB into a headless CMS, admin panels, or apps with a custom UI, instant APIs, auth & more.
https://directus.io
Other
27.12k stars 3.79k forks source link

GraphQL error when saving edits on Insights Dashboard #23287

Open DigNZ opened 1 month ago

DigNZ commented 1 month ago

Describe the Bug

Our implementation has a lot of dashboards (around 30) each containing a number of panels (around 6-8 each). There are some global variables that are shared between all the dashboards so that for example a time range can be specified on any dashboard and they are kept in sync.

When editing some dashboard, on save, we'll get a 'GraphQL error' popup, the dev tools show this response:

{
    "errors": [
        {
            "message": "GraphQL validation error.",
            "extensions": {
                "code": "GRAPHQL_VALIDATION",
                "errors": [
                    {
                        "message": "Syntax Error: Document contains more that 5000 tokens. Parsing aborted.",
                        "locations": [
                            {
                                "line": 1,
                                "column": 17867
                            }
                        ]
                    }
                ]
            }
        }
    ]
}

However refreshing the page or normal use of the dashboard never triggers this error. Looking at the request it appears to be running queries for all sorts of collections and filters that are not on the dashboard that is currently being edited - the queries are not in the graphql payload except after saving an edit. They push it over the limit and cause the error. Not all dashboards are affected, there are others that can still be edited. I think global variables are related to this but haven't pinned it down.

To Reproduce

Create a number of dashboards with a lot of panels on each. Include shared global variables and shared global relational variables across the dashboard. Note that the request to graphql endpoint is larger when saving an edit compared to using the dashboard without editing. Note that it includes filters or queries from dashboards other than the one being edited. When they get to a certain threshold they cause the graphSQL error.

Directus Version

v11.0.0

Hosting Strategy

Self-Hosted (Docker Image)

Database

PostgreSQL

hanneskuettner commented 1 month ago

The token limit of 5000 is a security precaution to not allow malicious actors to overwhelm your server.

It is configurable, however, see https://docs.directus.io/self-hosted/config-options.html#limits-optimizations and more specifically the GRAPHQL_QUERY_TOKEN_LIMIT option.

Still, a query that large for the situation you described sounds like there might be some room for optimization, that's why I'm leaving this open.

DigNZ commented 1 month ago

Thanks, I might need it as a work around, I'm more curious as to why the error is triggered on saving an edit, but not when using the dashboards normally. - Seems like an edit triggers other queries from other pages that may not be necessary.