-
I struggle to find any information about it in documentation. disclaimer: this is pseudo-code, I didn't run it but it bases on my production code from ariadne import ObjectType, QueryType, make_executable_schema
from graphql import GraphQLResolveInfo
# Schema
schema_definition = """
schema {
query: Query
}
type Query {
user: User
}
type Organization {
name: String
dailyIncome: Int
isBigCompany: Boolean
}
type User {
fullName: String
organization: Organization
}
"""
# Data
class Organization:
def __init__(self, name: str, daily_income: int):
self.name = name
self.daily_income = daily_income
class User:
def __init__(self):
self.full_name = "John Novak"
self.organization = Organization(name="Empik", daily_income=420)
# Schema binding
query = QueryType()
user = ObjectType("User")
@query.field("user")
def resolve_user_query(obj: None, info: GraphQLResolveInfo) -> User:
# Issue: How do I know how's returned `User()` resolved? How is it mapped to JSON?
return User()
@user.field("organization")
def resolve_organization_type(obj: User, info: GraphQLResolveInfo) -> dict:
return {
"name": obj.organization.name,
"dailyIncome": obj.organization.daily_income,
"isBigCompany": True if obj.organization.name == "Empik" else False,
}
schema = make_executable_schema(schema_definition, query, user) 🎯 Check out the |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Neither. When there's no resolver set on field on GraphQL schema, query executor falls back to default resolver which (AFAIR) checks if object is dict and then tries either If you pass
GraphQL spec says that resolver functions should be called with return value of parent field's resolver recursively until parent field's return value is scalar. Consider this schema: type Query {
user: User
version: String
}
type User {
id: ID!
} When you query for When you query for |
Beta Was this translation helpful? Give feedback.
Neither. When there's no resolver set on field on GraphQL schema, query executor falls back to default resolver which (AFAIR) checks if object is dict and then tries either
obj.getattr(field_name)
orobj.get(field_name)
. Whatsnake_case_fallback_resolvers
andfallback_resolvers
do is they scan schema for fields without set resolvers and set custom resolver for them. Ariadne's custom default resolvers are different in behavior than default one provided by graphql-core.If you pass
snake_case_fallback_resolvers
beforeuser
tomake_execut…