✨Discover storytelling in the AI age with Pixar's Matthew Luhn at Sanity Connect, May 8th—register now

Issue with `allDocument` GraphQL query causing errors for multiple brands using different Sanity accounts.

2 replies
Last updated: Apr 27, 2023
Hello everybody,we are experiencing some issues for the last 2 days with an
allDocument
GraphQL query.This is the original, very basic query:

query getRelated {
	allDocument {
		_id
		_type
	}
}
POSTing this query to
https://[project].<http://api.sanity.io/v1/graphql/[dataset]/default|api.sanity.io/v1/graphql/[dataset]/default>
works just fine.
When we pass it to our bff the query gets rewritten by our GraphQL client (as it always has been in the last months) as follows:

query getRelated {
  allDocument {
    ... on Document {
      _id
      _type
    }
  }
}
This query results in the following error, both if we call our bff or if we call directly Sanity’s GraphQL endpoint:

{
    "errors": [
        {
            "message": "Cannot read properties of undefined (reading 'length')",
            "locations": [
                {
                    "line": 2,
                    "column": 3
                }
            ],
            "path": [
                "allDocument"
            ]
        }
    ],
    "data": null
}
The strange thing is that we didn’t change anything our side, and we haven’t experienced any issue since the last Tuesday (when suddenly this errors started). We have multiple brands with shared code but different Sanity accounts, and everyone of them has the same exact problem on all datasets. We tried with a different GraphQL client (Apollo client instead of
graphql-js
+
cross-fetch
) but with no luck (same error).Anybody experiencing the same issue?
Apr 14, 2023, 8:53 AM
Nice. I didn’t know you could use
... on Document {
…I’ll have to try that for handling related content to our various page types.
I use
createSchemaCustomization
and
actions.createTypes
and
schema.buildObjectType
to attach related content of each type, and then access them in the template query like…

relatedPosts {
  ...cardNode
}
relatedAssets {
  ...cardNodeAsset
}
relatedPlaybooks {
  ...cardNodePlaybook
}
The error says the list is empty. You didn’t change the filter conditions?
Apr 26, 2023, 6:05 PM
Hey Josh, thanks for your reply. In fact I didn’t write that query, it was the GraphQL client rewriting our plain query (without
… on Document
) to that one. We investigated further and we found out that it was a single package (
@graphql-codegen/fragment-matcher
) that got updated to v4 and changed the Document Typescript type automatically generated by the codegen - and that broke the
allDocument
query.
We locked the package version to v3 and now everything is back to normal, I honestly found it a bit scary (that library is widely used) but no one else seemed to have any problem so maybe we are overreacting
🙂.
Apr 27, 2023, 1:02 PM

Sanity– build remarkable experiences at scale

Sanity is a modern headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Was this answer helpful?