Slide 49
Slide 49 text
@syrusakbary github.com/syrusakbary graphene-python.org 49
• Affect the evaluation of fields in the query in
runtime
Middleware
{
me {
name
talks {
title
time
}
}
}
GraphQL Query
context = {
'counters': defaultdict(int)
}
class CounterResolutionMiddleware(object):
def resolve(self, next, root, args, context, info):
key = '{}:{}'.format(
info.parent_type.name,
info.field_name
)
context['counters'][key] += 1
return next(root, args, context, info)
1
1
1
5
5
Query:me
User:name
User:talks
Talk:title
Talk:time