Skip to content

Scalar type error - Not supported #350

@rodbau

Description

@rodbau

Not support map[string]interface{} type.

example:

scalar Map
    schema {
        query: Query
    }
    
    type Query {
        run(data: Map): Map
    } 

I have this code:

type Map struct {
    value interface{}
}
// ImplementsGraphQLType i
func (Map) ImplementsGraphQLType(name string) bool {
    return name == “Map”
}
// UnmarshalGraphQL is
func (j *Map) UnmarshalGraphQL(input interface{}) error {
    j.value = input.(map[string]interface{})
    return nil
}
// MarshalJSON is
func (j Map) MarshalJSON() ([]byte, error) {
    return json.Marshal(j.value)
}

type Resolver struct{}
// Run is
func (r *Resolver) Run(ctx context.Context, args struct {
    Data *Map
}) *Map {
    return args.Data
}

The query is:

{
 run(data:{a:123456} )
}

The error is:

{
 “errors”: [
   {
     “message”: “Argument \“data\” has invalid value {a: 123456}.\nExpected type \“Map\“, found {a: 123456}.“,
     “locations”: [
       {
         “line”: 2,
         “column”: 12
       }
     ]
   }
 ]
}

And I expect this:

{
 “data”: {
   “run”: {
     “a”: 123456
   }
 }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions