Graphene自定义参数


class DictType(graphene.InputObjectType):
    name = graphene.InputField(graphene.String)

# 定义一个查询语句
class Query(ObjectType):
    all_user = graphene.List(UserType)
    # relay.Connection(UserType)
    user = relay.Node.Field(UserType)
    generic = GenericScalar(
        name=graphene.Argument(graphene.String, default_value=None),
        dict_test = DictType()
    )
    generic2 = graphene.String(
        name=graphene.Argument(graphene.String, default_value=None),
        dict_test = DictType()
    )
    all_users = DjangoFilterConnectionField(UserType)

    def resolve_generic(self, info, **kwargs):
        print(kwargs)
        return {
            "dict":kwargs.get("dict_test")
        }

 

GenericScalar和graphene.String都继承Scalar,
GenericScalar可以接受所有类型的参数,String同样可以自定义参数。
InputObjectType的定义里有这样的说明
fields (Dict[str, graphene.InputField]): Dictionary of field name to InputField. Not
recommended to use (prefer class attributes).
 

 

posted @ 2020-06-05 01:00  青花メ  阅读(363)  评论(0编辑  收藏  举报