Update middleware example to support introspection

In the `timing_middleware` example, introspection queries will fail due to `Schema` and others not having `_meta` attributes. API will work and tests pass but introspection will fail, which can be quite confusing to the developer. Simple update makes sure the `root` variable has a `_meta` attribute before accessing it.
This commit is contained in:
Dean Kleissas 2018-01-24 16:48:14 -05:00
parent a0fc843513
commit 035ff7ef88

View File

@ -57,7 +57,7 @@ logs the time it takes to resolve each field
return_value = next(root, info, **args)
duration = timer() - start
logger.debug("{parent_type}.{field_name}: {duration} ms".format(
parent_type=root._meta.name if root else '',
parent_type=root._meta.name if root and hasattr(root, '_meta') else '',
field_name=info.field_name,
duration=round(duration * 1000, 2)
))