小编Pav*_*kov的帖子

嵌套对象的变异

我正在尝试为"复杂"对象实现GrapgQL变异.比方说,我们有一个Contact带有三个字段:firstName,lastName并且address,这是一个字段对象street:

这是我的python方案实现:

class Address(graphene.ObjectType):
    street = graphene.String(description='Street Name')


class AddressInput(graphene.InputObjectType):
    street = graphene.String(description='Street Name', required=True)


class Contact(graphene.ObjectType):
    first_name = graphene.String(description='First Name')
    last_name = graphene.String(description='Last Name')
    address = graphene.Field(Address, description='Contact address')


class ContactInput(graphene.InputObjectType):
    first_name = graphene.String(description='First Name', required=True)
    last_name = graphene.String(description='Last Name', required=True)
    address = AddressInput(description='Contact address', required=True)


class CreateContact(graphene.Mutation):
    class Input:
        contact = ContactInput()

    contact = graphene.Field(Contact, description='Created Contact object')

    @staticmethod
    def mutate(instance, args, context, info):
        contact = Contact(**args['contact'])
        return …
Run Code Online (Sandbox Code Playgroud)

python graphql graphene-python

7
推荐指数
1
解决办法
555
查看次数

标签 统计

graphene-python ×1

graphql ×1

python ×1