graphql-go ResolveParams cannot be casted to actual type

31 Views Asked by At

Graphql endpoint gets an array of ints, resource_ids. This is the whole resolve function:

"resourceFilterByIds": &graphql.Field{
            Type:        graphql.NewList(resourceType),
            Description: "List resources matching IDs.",
            Args: graphql.FieldConfigArgument{
                "ids": &graphql.ArgumentConfig{
                    Type: graphql.NewList(graphql.Int),
                },
            },
            Resolve: func(params graphql.ResolveParams) (interface{}, error) {
                idQueryInterface, isOk := params.Args["ids"].([]interface{})
                idQuery := make([]int, 0, len(idQueryInterface))
                for _, v := range idQueryInterface {
                    idQuery = append(idQuery, v.(int))
                }

                if isOk {
                    var resources []Resource
                    for _, resource := range ResourceList {

                        if slices.Contains(idQuery, resource.ID) {
                            resources = append(resources, resource)
                        }
                    }
                    return resources, nil
                }
                return []Resource{}, nil
            },

I'd expect that idQueryInterface, isOk := params.Args["ids"].([]int)

works, but it fails with isOk being false.

0

There are 0 best solutions below