Skip to content

Missing gql schema query validation #408

Description

@ht-bx

Problem Summary

The graphql_codegen build runner does not validate GraphQL queries against the schema. Invalid queries that don't match the schema (missing required parameters, invalid fields, etc.) pass the build process successfully but will fail at runtime.

Concrete Example

The Schema Definition

# lib/schema.graphql
type Query {
  myItems(
    requiredParam: Boolean!  # This is a REQUIRED parameter
    optionalFilter: String
    skip: Int
    take: Int
  ): ItemsCollectionSegment
}

The Invalid Query

# lib/GetMyItems.graphql
query GetMyItems($filter: String, $skip: Int, $take: Int) {
    myItems(optionalFilter: $filter, skip: $skip, take: $take) {
        items {
            id
            name
            description
        }
        pageInfo {
            hasNextPage
            hasPreviousPage
        }
    }
}

The Problem

The query is missing the required requiredParam parameter, but:

  1. dart run build_runner build completes successfully
  2. ✅ No errors or warnings are generated
  3. ✅ Dart code is generated without issues
  4. ❌ The query will fail at runtime when executed

Question

Is there any existing mechanism or configuration option in graphql_codegen to enable schema validation?

If not, are there any recommended approaches such as:

  • Configuration options we're missing?
  • Alternative build_runner builders that provide validation?
  • Separate validation tools that integrate with Dart/Flutter projects?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions