Common utilities used to transform GraphQL schemas.

py_gql.schema.transforms.transform_schema(schema, *transforms)[source]#

Apply one or more transformations to a schema instance.

To prevent accidental side effects, this functions creates a deep clone of the schema before applying any transformer.

Return type:Schema
class py_gql.schema.transforms.VisibilitySchemaTransform[source]#

Bases: py_gql.schema.schema_visitor.SchemaVisitor

Remove elements from a schema.

User should subclass this and override the various visibility hooks.

The following elements are affected directly:

  • Named types (is_type_visible)
  • Object and interface fields (is_field_visible)
  • Directives (is_directive_visible)
  • Input type fields (is_input_field_visible)

The following elements are affected indirectly:

  • Object fields of a type that is now hidden
  • Input fields of a type that is now hidden
  • Arguments of a type that is now hidden


Mandatory input fields and arguments being removed could break resolvers if they were not built anticipating this (e.g. expected an argument as a mandatory keyword argument).

This should not allow modifying a schema to be off-spec and as such the following elements (or their children) cannot be hidden:

  • The query type
  • Specified scalar types
  • Introspection types
  • Specified directives

Users should use this transform before using the schema to make sure that validation, execution and introspection take the modifications into account.

class py_gql.schema.transforms.CamelCaseSchemaTransform[source]#

Bases: py_gql.schema.schema_visitor.SchemaVisitor

Rename schema elements to camel case from Python’s snake case convention.

This is a common convention in GraphQL projects which are usually consumed by web clients written in Javascript where camel case is the standard convention.

This transform will rename field and directive argument names, field names, and input field names. It won’t touch any enum value or type name and won’t replace the values in the description.