graphql-go / graphql-go/graphql

Help: Unable to Unmarshal from JSON to Struct

Open
#299 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
10.1k
Forks
845
PR merge metrics
No merged PRs in 30d

Description

I have this JSON:

```json
{
"myField": {
"name": "",
"type": {
"name": "String",
"description": "The `String` scalar type represents textual data, represented as UTF-8 character sequences. The String type is most often used by GraphQL to represent free-form human-readable text."
},
"args": {
"myFieldName": {
"type": {
"ofType": {
"name": "String",
"description": "The `String` scalar type represents textual data, represented as UTF-8 character sequences. The String type is most often used by GraphQL to represent free-form human-readable text."
}
},
"defaultValue": null,
"description": ""
},
},
"deprecationReason": "",
"description": "Test"
}
}
```

When I want to unmarshal:

```go
var fields graphql.Fields
var fieldsEncoded []byte

// fieldsEncoded = ...

if err := json.Unmarshal(fieldsEncoded, &fields); err != nil {
fmt.Println(err)
}
```

I have this result:

```shell
json: cannot unmarshal object into Go struct field Field.type of type graphql.Output
```

Do you have an idea @chris-ramon or @dvic?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.