Issue accessing models via Sanity GraphQL API
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 fieldallModel - Document type
models→ query fieldallModels - Document type
product→ query fieldallProduct
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.
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.