Python 如何在石墨烯中写入嵌套GraphQL突变?

Python 如何在石墨烯中写入嵌套GraphQL突变?,python,graphql,graphene-python,Python,Graphql,Graphene Python,我试图在石墨烯中编写嵌套突变,但在将一个突变的输出传递给另一个突变时遇到了麻烦。我希望WriteImage解析器能够从ReadImage解析器接受其输入图像。最后,WriteImage也应该能够接受来自其他解析器的映像,以便用户可以编写管道脚本 架构如下所示: import SimpleITK as sitk import graphene from graphql.execution.executors.asyncio import AsyncioExecutor class Image(g

我试图在石墨烯中编写嵌套突变,但在将一个突变的输出传递给另一个突变时遇到了麻烦。我希望
WriteImage
解析器能够从
ReadImage
解析器接受其输入图像。最后,
WriteImage
也应该能够接受来自其他解析器的映像,以便用户可以编写管道脚本

架构如下所示:

import SimpleITK as sitk
import graphene
from graphql.execution.executors.asyncio import AsyncioExecutor

class Image(graphene.Scalar):
    '''SimpleITK Image Type'''

    @staticmethod
    def serialize(Image):
        return Image

    @staticmethod
    def parse_literal(node):
        if isinstance(node, sitk.Image):
            return node

    @staticmethod
    def parse_value(value):
        return value

class ReadImage(graphene.Mutation):
    class Input:
        path = graphene.String()

    image = Image()

    @staticmethod
    async def mutate(cls, args, context, info):
        image = sitk.ReadImage(args.get('path'))
        return ReadImage(image=image)


class WriteImage(graphene.Mutation):
    class Input:
        image = Image()
        path = graphene.String()

    image = Image()

    @staticmethod
    async def mutate(cls, args, context, info):
        image = args.get('image')
        sitk.WriteImage(image, args.get('path'))
        return WriteImage(image=image)


class Mutation(graphene.ObjectType):
    readImage = ReadImage.Field()
    writeImage = WriteImage.Field()


schema = graphene.Schema(
    query=Query,
    mutation=Mutation,
)

executed = schema.execute(
    """
        mutation {
            writeImage(
                image: {
                    readImage(
                        path: "/path/to/image.nii"
                    ) {
                        image
                    }
                },
                path: "/Users/kasper/Desktop"
            ) {
                image
            }
        }
    """, executor=AsyncioExecutor())

print(executed.data)
print(executed.errors)
这个输出

>>> None
>>> [GraphQLError('Argument "image" has invalid value ReadImageInput.\nExpected "ReadImageInput", found not an object.',)]
这个错误消息是什么意思?为什么它不是一个对象?模式应该如何构造,以便我可以使用一个解析器的输出作为另一个解析器的输入

附加信息:执行
ReadImage
生成以下输出,并允许您查看图像类型:

executed = schema.execute(
    """
        mutation {
            readImage(
                path: "/path/to/image.nii"
            ) {
                image
            }
        }
    """, executor=AsyncioExecutor())

print(executed.data)
print(executed.errors)

>>> OrderedDict([('readImage', OrderedDict([('image', <SimpleITK.SimpleITK.Image; proxy of <Swig Object of type 'std::vector< itk::simple::Image >::value_type *' at 0x1087b5030> >)]))])
>>> None
executed=schema.execute(
"""
突变{
readImage(
路径:“/path/to/image.nii”
) {
形象
}
}
“”,executor=AsyncioExecutor())
打印(已执行。数据)
打印(已执行。错误)
>>>OrderedDict([('readImage',OrderedDict([('image',>)])))]
>>>没有