File: context.py

package info (click to toggle)
python-graphene 3.4.3-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,124 kB
  • sloc: python: 8,935; makefile: 212; sh: 18
file content (25 lines) | stat: -rw-r--r-- 791 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
class Context:
    """
    Context can be used to make a convenient container for attributes to provide
    for execution for resolvers of a GraphQL operation like a query.

    .. code:: python

        from graphene import Context

        context = Context(loaders=build_dataloaders(), request=my_web_request)
        schema.execute('{ hello(name: "world") }', context=context)

        def resolve_hello(parent, info, name):
            info.context.request  # value set in Context
            info.context.loaders  # value set in Context
            # ...

    args:
        **params (Dict[str, Any]): values to make available on Context instance as attributes.

    """

    def __init__(self, **params):
        for key, value in params.items():
            setattr(self, key, value)