Usually I want to use the custom method binded to GraphQLObjectType, such as:
# use strawberry for example
import strawberry
@strawberry.type
class User:
name: str
age: int
@strawberry.type
class Query:
@strawberry.field
def user(self, info) -> User:
return self.get_user()
def get_user(self):
return User(name="Patrick", age=100)
schema = strawberry.Schema(query=Query)
Unfortunately, the self would always be None cause the root_value in ExecutionContext.execute_operation would be setted to None if it is the root node Query. I think modifying it as below is fine:
def execute_operation(
self, operation: OperationDefinitionNode, root_value: Any
) -> Optional[AwaitableOrValue[Any]]:
"""Execute an operation.
Implements the "Evaluating operations" section of the spec.
"""
type_ = get_operation_root_type(self.schema, operation)
if not roo_value:
root_value = type_
Then we can use the custom method of GraphQLObjectType. And it not leads any problem I think.
Usually I want to use the custom method binded to
GraphQLObjectType, such as:Unfortunately, the
selfwould always beNonecause theroot_valueinExecutionContext.execute_operationwould be setted toNoneif it is the root node Query. I think modifying it as below is fine:Then we can use the custom method of
GraphQLObjectType. And it not leads any problem I think.