followers   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 23
dl 0
loc 54
rs 10
c 0
b 0
f 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A followers_graph_model() 0 25 3
1
"""
2
Defines a function `followers_graph_model` that creates a graph model representing GitHub followers.
3
It recursively fetches followers of a given user up to a specified maximum depth.
4
The function yields edges between users in the graph.
5
"""
6
7
8
from _client import github_user  # see _client.py
9
10
import graphinate
11
12
DEPTH = 0
13
14
15
def followers_graph_model(max_depth: int = DEPTH):
16
    """
17
    Create a graph model representing GitHub followers.
18
19
    Args:
20
        max_depth (int): The maximum depth to fetch followers recursively (default is 0).
21
22
    Returns:
23
        GraphModel: A graph model representing GitHub followers.
24
    """
25
26
    graph_model = graphinate.model(name='Github Followers Graph')
27
28
    def _followers(user_id: str | None = None, depth: int = 0, **kwargs):
29
        user = github_user(user_id)
30
        for follower in user.get_followers():
31
            yield {'source': user.login, 'target': follower.login}
32
            if depth < max_depth:
33
                yield from _followers(follower.login, depth=depth + 1, **kwargs)
34
35
    @graph_model.edge()
36
    def followed_by(user_id: str | None = None, **kwargs):
37
        yield from _followers(user_id, **kwargs)
38
39
    return graph_model
40
41
42
if __name__ == '__main__':
43
    followers_model = followers_graph_model(max_depth=1)
44
45
    params = {
46
        'user_id': 'erivlis'
47
        # 'user_id': 'andybrewer'
48
        # 'user_id' "strawberry-graphql"
49
    }
50
51
    builder = graphinate.builders.GraphQLBuilder(followers_model, graph_type=graphinate.GraphType.DiGraph)
52
    schema = builder.build(default_node_attributes={'type': 'user'}, **params)
53
    graphinate.graphql.server(schema)
54