File: test_720.py

package info (click to toggle)
python-graphene 3.4.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,120 kB
  • sloc: python: 8,935; makefile: 214; sh: 18
file content (44 lines) | stat: -rw-r--r-- 1,197 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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# https://github.com/graphql-python/graphene/issues/720
# InputObjectTypes overwrite the "fields" attribute of the provided
# _meta object, so even if dynamic fields are provided with a standard
# InputObjectTypeOptions, they are ignored.

import graphene


class MyInputClass(graphene.InputObjectType):
    @classmethod
    def __init_subclass_with_meta__(
        cls, container=None, _meta=None, fields=None, **options
    ):
        if _meta is None:
            _meta = graphene.types.inputobjecttype.InputObjectTypeOptions(cls)
        _meta.fields = fields
        super(MyInputClass, cls).__init_subclass_with_meta__(
            container=container, _meta=_meta, **options
        )


class MyInput(MyInputClass):
    class Meta:
        fields = dict(x=graphene.Field(graphene.Int))


class Query(graphene.ObjectType):
    myField = graphene.Field(graphene.String, input=graphene.Argument(MyInput))

    def resolve_myField(parent, info, input):
        return "ok"


def test_issue():
    query_string = """
    query myQuery {
      myField(input: {x: 1})
    }
    """

    schema = graphene.Schema(query=Query)
    result = schema.execute(query_string)

    assert not result.errors