Skip to main content

Ariadne Codegen 0.6

· 2 min read

Ariadne Codegen 0.6 has been released!

This release brings further improvements and fixes to issues reported to us by our amazing community. It also adds process_name plugin hook as an escape hatch for developers not happy with Python names created for GraphQL schema items.

Changed scalars setting

In previous versions of Codegen custom scalars were configured using two callables and a a module to import them from:

serialize = "serialize_datetime"
parse = "parse_datetime"
import = "datetime_scalar"

Codegen 0.6 simplifies this to two full paths to callables:

serialize = "datetime_scalar.serialize_datetime"
parse = "datetime_scalar.parse_datetime"

Old approach is still supported but is considered deprecated and will stop working in future release.

Support for GraphQL names that are Python keywords

Ariadne Codegen 0.6 will append _ to generated Python names that would be valid Python keywords otherwise.

For example, given following type:

type Example {
in: String
}

The in field will be represented as following declaration in generated Python code:

class MyExampleResult:
in_: Optional[str] = Field(alias="in")

Unset and None

A lot of GraphQL servers differentiate between inputs fields not being set and them being set to empty value (None/null).

Ariadne Codegen 0.6 introduces new Unset type and defaults to not setting optional fields on inputs sent in queries variables.

process_name plugin hook

Plugins can now define process_name hook to customize the generation of Python names for schema items:

from typing import Optional

from graphql import Node, ObjectTypeDefinitionNode


class MyPlugin:
def process_name(self, name: str, node: Optional[Node] = None) -> str:
if isinstance(node, ObjectTypeDefinitionNode):
... # return custom name for object type

return name # return name generated by from Ariadne Codegen

Changelog

  • Changed logic how custom scalar imports are generated. Deprecated import_ key.
  • Added escaping of GraphQL names which are Python keywords by appending _ to them.
  • Fixed parsing of list variables.
  • Changed base clients to remove unset arguments and input fields from variables payload.
  • Added process_name plugin hook.