{"id":37088346,"url":"https://github.com/cli/shurcool-graphql","last_synced_at":"2026-01-14T10:51:29.388Z","repository":{"id":46049097,"uuid":"277852757","full_name":"cli/shurcooL-graphql","owner":"cli","description":"Package graphql provides a GraphQL client implementation.","archived":false,"fork":true,"pushed_at":"2023-10-06T08:34:23.000Z","size":89,"stargazers_count":25,"open_issues_count":0,"forks_count":13,"subscribers_count":1,"default_branch":"trunk","last_synced_at":"2026-01-12T05:18:27.651Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"shurcooL/graphql","license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cli.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2020-07-07T15:22:20.000Z","updated_at":"2025-10-25T15:53:02.000Z","dependencies_parsed_at":"2023-09-09T04:38:57.419Z","dependency_job_id":null,"html_url":"https://github.com/cli/shurcooL-graphql","commit_stats":null,"previous_names":["cli/graphql"],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/cli/shurcooL-graphql","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cli%2FshurcooL-graphql","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cli%2FshurcooL-graphql/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cli%2FshurcooL-graphql/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cli%2FshurcooL-graphql/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cli","download_url":"https://codeload.github.com/cli/shurcooL-graphql/tar.gz/refs/heads/trunk","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cli%2FshurcooL-graphql/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28417716,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T10:47:48.104Z","status":"ssl_error","status_checked_at":"2026-01-14T10:46:19.031Z","response_time":107,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2026-01-14T10:51:28.583Z","updated_at":"2026-01-14T10:51:29.374Z","avatar_url":"https://github.com/cli.png","language":"Go","readme":"graphql\n=======\n\nPackage `graphql` provides a GraphQL client implementation, and is forked from `https://github.com/shurcooL/graphql`.\n\nInstallation\n------------\n\n```bash\ngo get -u github.com/cli/shurcooL-graphql\n```\n\nUsage\n-----\n\nConstruct a GraphQL client, specifying the GraphQL server URL. Then, you can use it to make GraphQL queries and mutations.\n\n```Go\nclient := graphql.NewClient(\"https://example.com/graphql\", nil)\n// Use client...\n```\n\n### Authentication\n\nSome GraphQL servers may require authentication. The `graphql` package does not directly handle authentication. Instead, when creating a new client, you're expected to pass an `http.Client` that performs authentication. The easiest and recommended way to do this is to use the [`golang.org/x/oauth2`](https://golang.org/x/oauth2) package. You'll need an OAuth token with the right scopes. Then:\n\n```Go\nimport \"golang.org/x/oauth2\"\n\nfunc main() {\n\tsrc := oauth2.StaticTokenSource(\n\t\t\u0026oauth2.Token{AccessToken: os.Getenv(\"GRAPHQL_TOKEN\")},\n\t)\n\thttpClient := oauth2.NewClient(context.Background(), src)\n\n\tclient := graphql.NewClient(\"https://example.com/graphql\", httpClient)\n\t// Use client...\n```\n\n### Simple Query\n\nTo make a GraphQL query, you need to define a corresponding Go type.\n\nFor example, to make the following GraphQL query:\n\n```GraphQL\nquery {\n\tme {\n\t\tname\n\t}\n}\n```\n\nYou can define this variable:\n\n```Go\nvar query struct {\n\tMe struct {\n\t\tName graphql.String\n\t}\n}\n```\n\nThen call `client.Query`, passing a pointer to it:\n\n```Go\nerr := client.Query(context.Background(), \u0026query, nil)\nif err != nil {\n\t// Handle error.\n}\nfmt.Println(query.Me.Name)\n\n// Output: Luke Skywalker\n```\n\n### Arguments and Variables\n\nOften, you'll want to specify arguments on some fields. You can use the `graphql` struct field tag for this.\n\nFor example, to make the following GraphQL query:\n\n```GraphQL\n{\n\thuman(id: \"1000\") {\n\t\tname\n\t\theight(unit: METER)\n\t}\n}\n```\n\nYou can define this variable:\n\n```Go\nvar q struct {\n\tHuman struct {\n\t\tName   graphql.String\n\t\tHeight graphql.Float `graphql:\"height(unit: METER)\"`\n\t} `graphql:\"human(id: \\\"1000\\\")\"`\n}\n```\n\nThen call `client.Query`:\n\n```Go\nerr := client.Query(context.Background(), \u0026q, nil)\nif err != nil {\n\t// Handle error.\n}\nfmt.Println(q.Human.Name)\nfmt.Println(q.Human.Height)\n\n// Output:\n// Luke Skywalker\n// 1.72\n```\n\nHowever, that'll only work if the arguments are constant and known in advance. Otherwise, you will need to make use of variables. Replace the constants in the struct field tag with variable names:\n\n```Go\nvar q struct {\n\tHuman struct {\n\t\tName   graphql.String\n\t\tHeight graphql.Float `graphql:\"height(unit: $unit)\"`\n\t} `graphql:\"human(id: $id)\"`\n}\n```\n\nThen, define a `variables` map with their values:\n\n```Go\nvariables := map[string]any{\n\t\"id\":   graphql.ID(id),\n\t\"unit\": starwars.LengthUnit(\"METER\"),\n}\n```\n\nFinally, call `client.Query` providing `variables`:\n\n```Go\nerr := client.Query(context.Background(), \u0026q, variables)\nif err != nil {\n\t// Handle error.\n}\n```\n\n### Inline Fragments\n\nSome GraphQL queries contain inline fragments. You can use the `graphql` struct field tag to express them.\n\nFor example, to make the following GraphQL query:\n\n```GraphQL\n{\n\thero(episode: \"JEDI\") {\n\t\tname\n\t\t... on Droid {\n\t\t\tprimaryFunction\n\t\t}\n\t\t... on Human {\n\t\t\theight\n\t\t}\n\t}\n}\n```\n\nYou can define this variable:\n\n```Go\nvar q struct {\n\tHero struct {\n\t\tName  graphql.String\n\t\tDroid struct {\n\t\t\tPrimaryFunction graphql.String\n\t\t} `graphql:\"... on Droid\"`\n\t\tHuman struct {\n\t\t\tHeight graphql.Float\n\t\t} `graphql:\"... on Human\"`\n\t} `graphql:\"hero(episode: \\\"JEDI\\\")\"`\n}\n```\n\nAlternatively, you can define the struct types corresponding to inline fragments, and use them as embedded fields in your query:\n\n```Go\ntype (\n\tDroidFragment struct {\n\t\tPrimaryFunction graphql.String\n\t}\n\tHumanFragment struct {\n\t\tHeight graphql.Float\n\t}\n)\n\nvar q struct {\n\tHero struct {\n\t\tName          graphql.String\n\t\tDroidFragment `graphql:\"... on Droid\"`\n\t\tHumanFragment `graphql:\"... on Human\"`\n\t} `graphql:\"hero(episode: \\\"JEDI\\\")\"`\n}\n```\n\nThen call `client.Query`:\n\n```Go\nerr := client.Query(context.Background(), \u0026q, nil)\nif err != nil {\n\t// Handle error.\n}\nfmt.Println(q.Hero.Name)\nfmt.Println(q.Hero.PrimaryFunction)\nfmt.Println(q.Hero.Height)\n\n// Output:\n// R2-D2\n// Astromech\n// 0\n```\n\n### Mutations\n\nMutations often require information that you can only find out by performing a query first. Let's suppose you've already done that.\n\nFor example, to make the following GraphQL mutation:\n\n```GraphQL\nmutation($ep: Episode!, $review: ReviewInput!) {\n\tcreateReview(episode: $ep, review: $review) {\n\t\tstars\n\t\tcommentary\n\t}\n}\nvariables {\n\t\"ep\": \"JEDI\",\n\t\"review\": {\n\t\t\"stars\": 5,\n\t\t\"commentary\": \"This is a great movie!\"\n\t}\n}\n```\n\nYou can define:\n\n```Go\nvar m struct {\n\tCreateReview struct {\n\t\tStars      graphql.Int\n\t\tCommentary graphql.String\n\t} `graphql:\"createReview(episode: $ep, review: $review)\"`\n}\nvariables := map[string]any{\n\t\"ep\": starwars.Episode(\"JEDI\"),\n\t\"review\": starwars.ReviewInput{\n\t\tStars:      graphql.Int(5),\n\t\tCommentary: graphql.String(\"This is a great movie!\"),\n\t},\n}\n```\n\nThen call `client.Mutate`:\n\n```Go\nerr := client.Mutate(context.Background(), \u0026m, variables)\nif err != nil {\n\t// Handle error.\n}\nfmt.Printf(\"Created a %v star review: %v\\n\", m.CreateReview.Stars, m.CreateReview.Commentary)\n\n// Output:\n// Created a 5 star review: This is a great movie!\n```\n\nLicense\n-------\n\n-\t[MIT License](LICENSE)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcli%2Fshurcool-graphql","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcli%2Fshurcool-graphql","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcli%2Fshurcool-graphql/lists"}