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: - node (
Union
[IntValue
,FloatValue
,StringValue
,BooleanValue
]) – Parse node - variables (
Optional
[Any
]) – Raw, JSON decoded variables parsed from the request
Return type: Returns: Python level value
Raises: ScalarParsingError
– when the type’s parser fail with ValueError or TypeError (other exceptions bubble up).- node (
-
-
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:
-
py_gql.exts.scalars.
UUID
= StringType(UUID)# The
UUID
scalar type represents a UUID as specified in RFC 4122 using Python’suuid
module.
-
py_gql.exts.scalars.
JSONString
= StringType(JSONString)# The
JSONString
scalar type represents any value serializable as JSON using Python’sjson
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 asdatetime.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 asdatetime.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 asdatetime.time
objects.