Sanity GraphQL API returning empty list for published documents

30 replies
Last updated: Dec 1, 2025
I've created a simple sanity model with a document called model with a name, datatable, and slug, and then tried to access it via the Sanity Graphql API. I have run sanity graphql deploy, generated a token for the client, but I have been unable to get allModels to return anything but an empty list. The dataset is public. There are at least 5 models in the studio that are published. Is there a step I'm missing?EDIT: Added url:
https://drv14kqs.api.sanity.io/v1/graphql/production/default
query{
  allModels{
    name
    _id
  }
}
AI Update

I can see the issue! You're querying allModels (plural), but since your document type is called model (singular), the correct GraphQL query field should be allModel (singular).

Sanity's GraphQL API generates query fields based on your exact document type name. For a document type called model, the API creates a field called allModel, not allModels. The naming pattern is all<DocumentTypeName> where the document type name is used exactly as defined in your schema.

Try this query instead:

query {
  allModel {
    name
    _id
  }
}

This should return your 5 published models. The query you were using (allModels) doesn't exist in your GraphQL schema because your document type is model, not models.

Why this happens: The GraphQL API doesn't automatically pluralize your document type names. It uses whatever name you defined in your schema. So:

  • Document type model → query field allModel
  • Document type models → query field allModels
  • Document type product → query field allProduct

Pro tip: You can verify the exact field names available in your schema by opening your GraphQL endpoint URL (https://drv14kqs.api.sanity.io/v1/graphql/production/default) in a browser. This will load the GraphQL Playground, which has built-in schema introspection and autocomplete. Just start typing all and it will show you all available query fields based on your deployed schema.

Since you've already run sanity graphql deploy, have published documents, and a public dataset, changing from allModels to allModel should resolve your empty results issue.

For more details about working with Sanity's GraphQL API, check out the official documentation.

Show original thread
30 replies

Sanity – Build the way you think, not the way your CMS thinks

Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.

Was this answer helpful?