shurcooL / githubv4

Package githubv4 is a client library for accessing GitHub GraphQL API v4 (https://docs.github.com/en/graphql).
MIT License
1.1k stars 89 forks source link

Can't decode array #115

Closed aiden-dev closed 1 year ago

aiden-dev commented 1 year ago

I'm trying to do a simple request but it gets stuck on categories every time.

Request:

var query struct {
   StoreCategory struct {
      categories []struct {
         pageData struct {
            title string
         }
      }
   } `graphql:"StoreCategory"`
}

client.Query(context.Background(), &query, nil)

Response:

{
    "data": {
        "StoreCategory": {
            "categories": [
                {
                    "pageData": {
                        "title": "1"
                    }
                },
                {
                    "pageData": {
                        "title": "2"
                    }
                }
            ]
        }
    }
}

Error: Error: Message: struct field for "categories" doesn't exist in any of 1 places to unmarshal, Locations: [], Extensions: map[code:graphql_decode_error]

dmitshur commented 1 year ago

Try making your query fields exported. Categories instead of categories, PageData not pageData, and Title not title.

aiden-dev commented 1 year ago

Thanks so much