validation
Type
External
Status
Published
Created
Mar 23, 2026
Updated
Mar 23, 2026

Client Side Query Validation#

Because we make use of GraphQL Core 3, client-side query validation is performed by default.

request = GraphQLRequest(
    query="""
        query {
          bad {
            login
          }
        }
    """
)
response: GraphQLResponse = await client.query(request=request)

This will raise aiographql.client.GraphQLClientValidationException. The message will also contain information about the error.

aiographql.client.exceptions.GraphQLClientValidationException: Query validation failed

Cannot query field 'bad' on type 'Query'.

GraphQL request:3:15
2 | query {
3 | bad {
  | ^
4 | login

Process finished with exit code 1

Server Side Query Validation#

You can skip the client side validation, forcing server side validation instead by setting the aiographql.client.GraphQLRequest.validate to False before making the request.

request = GraphQLRequest(
    query="""
        query {
          bad {
            login
          }
        }
    """,
    validate=False
)
response: GraphQLResponse = await client.query(request=request)

If you are working with a GraphQL server that has introspection disabled, you can disable validation globally when initializing the aiographql.client.GraphQLClient.

client = GraphQLClient(
    endpoint="https://api.github.com/graphql",
    validate=False
)
response: GraphQLResponse = await client.query("query { viewer { login } }")
>>> response.data
{}
>>> response.errors
[GraphQLError(extensions={'code': 'undefinedField', 'typeName': 'Query', 'fieldName': 'bad'}, locations=[{'line': 3, 'column': 15}], message="Field 'bad' doesn't exist on type 'Query'", path=['query', 'bad'])]

Introspection Caching#

The client introspects the server to get the schema for validation. This schema is cached internally. For long-running production services, if the server schema changes, you can force a refresh:

await client.get_schema(refresh=True)

This is particularly useful if your GraphQL server is updated with new fields or types without restarting the client application.