File: context.py

package info (click to toggle)
python-graphene 2.1.9-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,024 kB
  • sloc: python: 7,295; makefile: 196; sh: 4
file content (25 lines) | stat: -rw-r--r-- 799 bytes parent folder | download
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(object):
    """
    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)