shurcooL / graphql

Package graphql provides a GraphQL client implementation.
MIT License
709 stars 282 forks source link

Query for Github Projects in an organization #119

Closed Kartikey-star closed 9 months ago

Kartikey-star commented 9 months ago

I am trying to query the projects present in my organization using https://github.com/shurcooL/graphql/. When i make a curl request i am able to generate a successul response:

curl --request POST --url https://api.github.com/graphql --header 'Authorization: Bearer TOKEN' --data '{"query":"{organization(login: \"containers\") {projectsV2(first: 20) {nodes {id title}}}}"}'

{"data":{"organization":{"projectsV2":{"nodes":[{"id":"SOMEVAL1","title":"SOMETITLE1"},{"id":"SOMEVAL1","title":"SOMETITLE2"}]}}}}

When i try to create a struct of the above query i do so with:

var listquery struct {
    Organization struct {
        Projectv2 struct {
            Nodes []struct {
                id    string
                title string
            }
        } `graphql:"projectsV2(first: 20)"`
    } `graphql:"organization(login: \"containers\")"`
}

The error which i get is: struct field for "id" doesn't exist in any of 1 places to unmarshal.

Can you point where i am going wrong here. Thanks.

dmitshur commented 9 months ago

The struct fields need to be exported, otherwise they can’t be written to via reflection from other packages. Try renaming id to ID and title to Title.

Kartikey-star commented 9 months ago

The struct fields need to be exported, otherwise they can’t be written to via reflection from other packages. Try renaming id to ID and title to Title.

Thanks. It's working now.