def dino_park_resolver(attname, default_value, root, info, *args): """Custom resolver for all the attributes in a profile.""" profile_attr = root.get(attname, default_value) # If we don't get a profile attribute back, probably it's a query from a different # source than the v2 profile. Let's try to resolve this from the mozillians db. if not hasattr(root, attname): username = root.get('usernames', {}).get('values', {}).get('mozilliansorg', default_value) # We missed that too. Just return root back if not username: return root # Top level username in GraphQL. We have one, let's return it if attname == 'username': return username user = retrieve_v2_profile(info.context, username, from_db=True) if user: profile = user.userprofile # We are looking for vouches! Let's return a few if attname == 'vouches': return Vouch.objects.filter(vouchee=profile) return profile if profile_attr and hasattr(profile_attr, 'get'): # If we don't have a value/values attrs and it is a dict then we # have nested attributes. Let's return them so that nested resolvers # can do the matching if 'value' not in profile_attr and 'values' not in profile_attr: return profile_attr # Get either the value or values from the v2 schema and return them # This allows us to avoid one level of nesting in our responses value = profile_attr.get('value') or profile_attr.get('values') # If we are here, we already have a match. Let's check if it's of DateTime type if attname in DATETIME_ATTRS: return parse_datetime_iso8601(value) return value return profile_attr
def resolve_created(self, info, **kwargs): """Resolver to return a datetime object.""" return parse_datetime_iso8601(self.get('created'))
def resolve_value(self, info, **kwargs): """Resolver to return a datetime object.""" return parse_datetime_iso8601(self.get('value'))