graphql-go / graphql

An implementation of GraphQL for Go / Golang
MIT License
9.86k stars 838 forks source link

could not resolved all fields in input argument in ResolveParams.Args #644

Open ielyanov opened 2 years ago

ielyanov commented 2 years ago

When I request a mutation to my graphql server(using graphql-go) but i didn't get all the fields of the argument cart.

mutation($user_id: Int, $session_id: String, $product_id: Int!, $quantity: Int!, $cart: CartInput) {
       add_to_cart(user_id: $user_id, session_id: $session_id, product_id: $product_id, quantity: $quantity, cart: $cart) {

          ... some fields ...

       }
}

But graphql resolve 3 fields of the 12 fields.

func addToCart(params graphql.ResolveParams) (interface{}, error) {
    u_id, uOk := params.Args["user_id"].(int)
    s_id, _ := params.Args["session_id"].(string)
    p_id, _ := params.Args["product_id"].(int)
    quant, _ := params.Args["quantity"].(int)
    cartarg, cartOk := params.Args["cart"].(model.Cart)
       //cartOk - false !

        fmt.Println("cart Args:", params.Args["cart"]) 

       // -> cart Args:map[extra_large_cart:false items:[<nil>] not_selected:[]]
}

CartInput

var CartInputType = graphql.NewInputObject(graphql.InputObjectConfig{
    Name: "CartInput",
    Fields: graphql.InputObjectConfigFieldMap{
        "promo": &graphql.InputObjectFieldConfig{
            Type: CartPromoType,
        },
        "extra_large_cart": &graphql.InputObjectFieldConfig{
            Type: graphql.Boolean,
        },
        "items": &graphql.InputObjectFieldConfig{
            Type: graphql.NewList(ProductType),
        },
        "not_selected": &graphql.InputObjectFieldConfig{
            Type: graphql.NewList(ProductType),
        },
        "delivery_data": &graphql.InputObjectFieldConfig{
            Type: CartServiceType,
        },
        "bonuses": &graphql.InputObjectFieldConfig{
            Type: graphql.Float,
        },
        "date": &graphql.InputObjectFieldConfig{
            Type: graphql.String,
        },
        "name": &graphql.InputObjectFieldConfig{
            Type: graphql.String,
        },
        "surname": &graphql.InputObjectFieldConfig{
            Type: graphql.String,
        },
        "patronymic": &graphql.InputObjectFieldConfig{
            Type: graphql.String,
        },
        "phone": &graphql.InputObjectFieldConfig{
            Type: graphql.String,
        },
        "email": &graphql.InputObjectFieldConfig{
            Type: graphql.String,
        },
    },
},
)