(node, fragments)
return field
Recursively collects fields from the AST

    Args:
        node (dict): A node in the AST
        fragments (dict): Fragment definitions

    Returns:
        A dict mapping each field found, along with their sub fields.
        {
            'name': {},
            'image': {
                        'id': {},
                        'name': {},
                        'description': {}
                    },
            'slug': {}
        }
Recursively collects fields from the AST
Recursively collects fields from the AST
def collect_query_fields(node, fragments):
    """Recursively collects fields from the AST

    Args:
        node (dict): A node in the AST
        fragments (dict): Fragment definitions

    Returns:
        A dict mapping each field found, along with their sub fields.
        {
            'name': {},
            'image': {
                        'id': {},
                        'name': {},
                        'description': {}
                    },
            'slug': {}
        }
    """

    field = {}
    selection_set = None
    if type(node) == dict:
        selection_set = node.get('selection_set')
    else:
        selection_set = node.selection_set
    if selection_set:
        for leaf in selection_set.selections:
            if leaf.kind == 'field':
                field.update({
                    leaf.name.value: collect_query_fields(leaf, fragments)
                })
            elif leaf.kind == 'fragment_spread':
                field.update(collect_query_fields(fragments[leaf['name']['value']],
                                                  fragments))
            elif leaf.kind == 'inline_fragment':
                field.update({
                    leaf.type_condition.name.value: collect_query_fields(leaf, fragments)
                })

    return field
def collect_query_fields ( node , fragments ) : field = { } selection_set = None if type ( node ) == dict : selection_set = node . get ( 'selection_set' ) else : selection_set = node . selection_set if selection_set : for leaf in selection_set . selections : if leaf . kind == 'field' : field . update ( { leaf . name . value : collect_query_fields ( leaf , fragments ) } ) elif leaf . kind == 'fragment_spread' : field . update ( collect_query_fields ( fragments [ leaf [ 'name' ] [ 'value' ] ] , fragments ) ) elif leaf . kind == 'inline_fragment' : field . update ( { leaf . type_condition . name . value : collect_query_fields ( leaf , fragments ) } ) return field