Skip to content

Returning a uint in a Resolve function for a GraphQLNonNull(GraphQLInt) field responds with 0 #22

@bbuck

Description

@bbuck

I have a simple test server set up to run off todos in a database. I'm using the gorm ORM and it's default gorm.Model that defines common fields for models. One of which happens to be the ID field which is of type uint.

todoType := graphql.NewObject(graphql.ObjectConfig{
        Name: "Todo",
        Fields: types.Fields{
                "id": &types.Field{
                        Type: graphql.NewNonNull(graphql.Int),
                        Resolve: func(params graphql.ResolveParams) (interface{}, error) {
                                todo := params.Source.(*data.Todo)

                                return todo.ID
                        },
                },
                // Shortened for brevity
        },
})

When I make a query to this, I get back "id": 0 for all records. If I change the return to int(todo.ID) then I get back the expected ID value.

It appears the reason is that coerceInt does not support the uint type. Also missing are int8, int16, int32, int64, and the uint series as well. When I get the opportunity I'll see about making a pull request to address this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions