-
Notifications
You must be signed in to change notification settings - Fork 174
Description
What happened?
[5.x]: GraphQL schema validation error with hasProduct: {status} argument on variants query
What happened?
I'm experiencing a schema validation error when using the status field within the hasProduct argument on the variants GraphQL query. The query works in GraphiQL, but fails during code generation with GraphQL Code Generator.
Steps to reproduce
- Create a GraphQL query that filters variants by parent product status:
query ProductVariantsSearch($searchTerm: String = null, $limit: Int = 9) {
variants(
search: $searchTerm
hasProduct: {status: ["enabled"]}
orderBy: "score DESC"
limit: $limit
) {
__typename
id
title
status
product {
id
title
status
}
}
}-
The query executes successfully in GraphiQL (albeit very slowly on first run)
-
Run GraphQL Code Generator to generate TypeScript types:
pnpm graphql-codegen --require dotenv/config --config codegen.ts- Code generation fails with the following error:
✖ GraphQL Document Validation failed with 1 errors;
Error 0: Field "status" is not defined by type "ProductInput".
at /path/to/ProductVariantsSearch.gql:4:19
Expected behavior
The GraphQL schema should properly define the status field on the ProductInput type (or the appropriate input type used by hasProduct), allowing both GraphiQL execution and schema validation tools to work consistently.
Since the query works in GraphiQL, the runtime supports this field, but the schema introspection doesn't reflect this capability.
Actual behavior
- The query works in GraphiQL at runtime
- GraphQL Code Generator fails validation because
statusis not defined in the schema forProductInput - Removing
hasProduct: {status: ["enabled"]}allows code generation to succeed
This suggests a discrepancy between the actual GraphQL implementation and the published schema definition.
Additional context
- Using a headless Craft CMS installation with Nuxt.js frontend
- Using GraphQL Code Generator with the following plugins:
typescripttypescript-operationstypescript-graphql-request
The issue appears to be that the ProductInput type (or related input type) in the GraphQL schema is missing the status field definition, even though it's supported at runtime. This causes schema validation tools to fail while the actual query execution succeeds.
Workaround: Currently removing the status filter from the hasProduct argument, but this prevents filtering variants by their parent product's status, so we are filtering for products enabled on client side.
Craft CMS version
5.8.19
Craft Commerce version
5.4.9
PHP version
8.2.29
Operating system and version
Ubuntu 24
Database type and version
MySQL 8.0.43
Image driver and version
Imagick 3.8.0 (ImageMagick 6.9.12-98)