Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# Coercers
self.input_coercer = partial(
input_directives_coercer,
coercer=partial(input_enum_coercer, enum_type=self),
directives=post_input_coercion_directives,
)
self.literal_coercer = partial(
literal_directives_coercer,
coercer=partial(literal_enum_coercer, enum_type=self),
directives=post_input_coercion_directives,
)
self.output_coercer = partial(
output_directives_coercer,
coercer=partial(enum_coercer, enum_type=self),
directives=wraps_with_directives(
directives_definition=directives_definition,
directive_hook="on_pre_output_coercion",
with_default=True,
),
:type schema: GraphQLSchema
"""
# Directives
directives_definition = compute_directive_nodes(
schema, self.directives
)
self.introspection_directives = wraps_with_directives(
directives_definition=directives_definition,
directive_hook="on_introspection",
)
# Coercers
self.output_coercer = partial(
output_directives_coercer,
coercer=partial(abstract_coercer, abstract_type=self),
directives=wraps_with_directives(
directives_definition=directives_definition,
directive_hook="on_pre_output_coercion",
with_default=True,
),
directives_definition=directives_definition,
directive_hook="on_post_bake",
with_default=True,
),
self,
)
self.introspection_directives = wraps_with_directives(
directives_definition=directives_definition,
directive_hook="on_introspection",
)
# Resolvers
self.resolver = partial(
resolve_field,
field_definition=self,
resolver=wraps_with_directives(
directives_definition=directives_definition,
directive_hook="on_field_execution",
func=(
self.raw_resolver
or custom_default_resolver
or default_field_resolver
),
is_resolver=True,
with_default=True,
),
output_coercer=get_output_coercer(self.graphql_type),
)
for argument in self.arguments.values():
argument.bake(schema)
self.args.append(argument)
def bake_execute(self, func_query, func_subscription):
directives = compute_directive_nodes(self, self._schema_directives)
func_query = wraps_with_directives(
directives, "on_schema_execution", func_query, is_resolver=True
)
func_subscription = wraps_with_directives(
directives,
"on_schema_subscription",
func_subscription,
is_async_generator=True,
)
return func_query, func_subscription
Bakes the GraphQLField and computes all the necessary stuff for
execution.
:param schema: the GraphQLSchema instance linked to the engine
:param custom_default_resolver: callable that will replace the builtin
default_resolver
:type schema: GraphQLSchema
:type custom_default_resolver: Optional[Callable]
"""
self.graphql_type = get_graphql_type(schema, self.gql_type)
# Directives
directives_definition = compute_directive_nodes(
schema, self.directives
)
self.on_post_bake = partial(
wraps_with_directives(
directives_definition=directives_definition,
directive_hook="on_post_bake",
with_default=True,
),
self,
)
self.introspection_directives = wraps_with_directives(
directives_definition=directives_definition,
directive_hook="on_introspection",
)
# Resolvers
self.resolver = partial(
resolve_field,
field_definition=self,
resolver=wraps_with_directives(
def bake_execute(self, func_query, func_subscription):
directives = compute_directive_nodes(self, self._schema_directives)
func_query = wraps_with_directives(
directives, "on_schema_execution", func_query, is_resolver=True
)
func_subscription = wraps_with_directives(
directives,
"on_schema_subscription",
func_subscription,
is_async_generator=True,
)
return func_query, func_subscription
def bake(self, schema: "GraphQLSchema") -> None:
"""
Bakes the GraphQLEnumValue and computes all the necessary stuff for
execution.
:param schema: the GraphQLSchema instance linked to the engine
:type schema: GraphQLSchema
"""
# Directives
directives_definition = compute_directive_nodes(
schema, self.directives
)
self.on_post_bake = partial(
wraps_with_directives(
directives_definition=directives_definition,
directive_hook="on_post_bake",
with_default=True,
),
self,
)
self.introspection_directives = wraps_with_directives(
directives_definition=directives_definition,
directive_hook="on_introspection",
)
post_input_coercion_directives = wraps_with_directives(
directives_definition=directives_definition,
directive_hook="on_post_input_coercion",
with_default=True,
)
Bakes the GraphQLObjectType and computes all the necessary stuff for
execution.
:param schema: the GraphQLSchema instance linked to the engine
:type schema: GraphQLSchema
"""
if self.interfaces_names:
for interface_name in self.interfaces_names:
interface = schema.find_type(interface_name)
self.interfaces.append(interface)
interface.add_possible_type(self)
# Directives
directives_definition = compute_directive_nodes(
schema, self.directives
)
self.introspection_directives = wraps_with_directives(
directives_definition=directives_definition,
directive_hook="on_introspection",
)
# Coercers
self.output_coercer = partial(
output_directives_coercer,
coercer=partial(object_coercer, object_type=self),
directives=wraps_with_directives(
directives_definition=directives_definition,
directive_hook="on_pre_output_coercion",
with_default=True,
),
self.type["name"] = self.gql_type
self.type["kind"] = self.graphql_type.kind
self.defaultValue = (
str(self.default_value) if self.default_value is not None else None
)
# Directives
directives_definition = compute_directive_nodes(
schema, self.directives
)
self.introspection_directives = wraps_with_directives(
directives_definition=directives_definition,
directive_hook="on_introspection",
)
post_input_coercion_directives = wraps_with_directives(
directives_definition=directives_definition,
directive_hook="on_post_input_coercion",
)
# Coercers
self.input_coercer = partial(
input_directives_coercer,
coercer=get_input_coercer(self.graphql_type),
directives=post_input_coercion_directives,
)
self.literal_coercer = partial(
literal_directives_coercer,
coercer=get_literal_coercer(self.graphql_type),
directives=post_input_coercion_directives,
is_input_field=True,
)
def bake(self, schema: "GraphQLSchema") -> None:
"""
Bakes the GraphQLInputObject and computes all the necessary stuff for execution.
:param schema: the GraphQLSchema schema instance linked to the engine
:type schema: GraphQLSchema
"""
# Directives
directives_definition = compute_directive_nodes(
schema, self.directives
)
self.introspection_directives = wraps_with_directives(
directives_definition=directives_definition,
directive_hook="on_introspection",
)
post_input_coercion_directives = wraps_with_directives(
directives_definition=directives_definition,
directive_hook="on_post_input_coercion",
)
# Coercers
self.input_coercer = partial(
input_directives_coercer,
coercer=partial(
input_input_object_coercer, input_object_type=self
),
directives=post_input_coercion_directives,
)