py_gql.exts.scalars#

Additional scalar types which are not part of the specification.

These types are provided for convenience as they are pretty common as well as to serve as examples for how to implement custom Scalar types.

They won’t always be supported by GraphQL servers and may not fit every purpose. They must be included in the schema manually either by providing them to build_schema() or including them in your type definitions.

class py_gql.exts.scalars.StringType(name, parse, serialize, description=None)[source]#

Helper class to define custom String type.

The resulting types will only accept String nodes.

parse_literal(node, variables=None)[source]#

Transform an AST node in a valid Python value

Parameters:
Return type:

Any

Returns:

Python level value

Raises:

ScalarParsingError – when the type’s parser fail with ValueError or TypeError (other exceptions bubble up).

class py_gql.exts.scalars.RegexType(name, regex, description=None)[source]#

ScalarType type class used to validate regex patterns.

This will accept either a string or a compiled Pattern and will match strings both on output and input values.

Parameters:
name#

Type name

Type:str
description#

Type description

Type:str
py_gql.exts.scalars.UUID = StringType(UUID)#

The UUID scalar type represents a UUID as specified in RFC 4122 using Python’s uuid module.

py_gql.exts.scalars.JSONString = StringType(JSONString)#

The JSONString scalar type represents any value serializable as JSON using Python’s json module. This allows opting out of GraphQL’s type safety and should be used sparingly.

py_gql.exts.scalars.DateTime = StringType(DateTime)#

The DateTime scalar type represents a datetime value as specified by the ISO 8601 standard. This expects and parses values as datetime.datetime objects.

py_gql.exts.scalars.Date = StringType(Date)#

The Date scalar type represents a date value as specified by the ISO 8601 standard. This expects and parses values as datetime.date objects.

py_gql.exts.scalars.Time = StringType(Time)#

The Time scalar type represents a time value as specified by the ISO 8601 standard. This expects and parses values as datetime.time objects.

py_gql.exts.scalars.Base64String = StringType(Base64String)#

Base64 encoded strings suitable to transmit binary data which cannot normally be encoded in a GraphQL String. This uses Python’s base64 module.