如何使用graphql-go获取嵌套对象的p.Args?

时间:2019-02-15 14:56:52

标签: go graphql mutation graphql-go

我正在尝试使用graphql-go创建突变。 我需要获取对象的嵌套元素的args,但是它是空的。如何解决?

var mutationKittensType = graphql.NewObject(
    graphql.ObjectConfig{
        Name: "kittens",
        Fields: graphql.Fields{
            "littleName": &graphql.Field{
                Type: graphql.String,
            },
            "age": &graphql.Field{
                Type: graphql.Float,
            },
        },
    },
)

var mutationPropertiesType = graphql.NewObject(
    graphql.ObjectConfig{
        Name: "properties",
        Fields: graphql.Fields{
            "name": &graphql.Field{
                Type: graphql.String,
            },
            "kittens": &graphql.Field{
                Type: mutationKittensType,
            },
        },
    },
)

var mutationType = graphql.NewObject(
    graphql.ObjectConfig{
        Name: "create_cat",
        Fields: graphql.Fields{

            "type": &graphql.Field{
                Type: graphql.String,
            },
            "properties": &graphql.Field{
                Type: mutationPropertiesType,                  
            },

                Resolve: func(params graphql.ResolveParams) (interface{}, error) {


                    log.Println("params.Args ", params.Args)

我的卷发是:

      curl -XPOST http://localhost/graphql -H 'Content-Type: application/graphql' -d'mutation{create_cat(type:"persian", properties:{name: "alice", kittens:{littleName: "little alice", age: 1}}){type, properties{name, kittens:{littleName, age}}}}'

终端给我这个: params.Args map []

为什么我的params.Args为空以及如何解决?

0 个答案:

没有答案