|
| 1 | +--- |
| 2 | +title: Using GraphQL Clients |
| 3 | +intro: 'You can run queries on real {% data variables.product.prodname_dotcom %} data using various GraphQL clients and libraries.' |
| 4 | +redirect_from: |
| 5 | + - /v4/guides/using-the-explorer |
| 6 | + - /graphql/guides/using-the-explorer |
| 7 | +versions: |
| 8 | + fpt: '*' |
| 9 | + ghec: '*' |
| 10 | + ghes: '*' |
| 11 | +topics: |
| 12 | + - API |
| 13 | +--- |
| 14 | + |
| 15 | +## Using GraphQL client IDEs |
| 16 | + |
| 17 | +There are many open-source GraphQL client IDEs you can use to access {% data variables.product.company_short %}'s GraphQL API. |
| 18 | + |
| 19 | +See [AUTOTITLE](/graphql/guides/forming-calls-with-graphql) for extensive information on HTTP methods, authentication, and GraphQL call structure. |
| 20 | + |
| 21 | +First, choose a client. Common options include GraphiQL, Insomnia, and Altair (desktop/web/extension). You can see the full list of clients in the [GraphQL organization's tool directory](https://graphql.org/community/tools-and-libraries/?tags=services). |
| 22 | + |
| 23 | +The following generic instructions will work with most GraphQL clients: |
| 24 | +1. Point the client at the GraphQL endpoint: `{% data variables.product.graphql_url %}`. |
| 25 | +1. Add an `Authorization` header: `Authorization: Bearer TOKEN` (replace `TOKEN` with your {% data variables.product.company_short %} {% data variables.product.pat_generic %}. For more information, see [AUTOTITLE](/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens)). |
| 26 | +1. Set the request method to `POST` or if it's available, use the client-provided GraphQL mode. |
| 27 | +1. Enter your query or mutation in the editor and, if needed, provide variables in the "Variables" panel. |
| 28 | + |
| 29 | + Example: |
| 30 | + |
| 31 | + ```graphql |
| 32 | + query { |
| 33 | + viewer { |
| 34 | + login |
| 35 | + } |
| 36 | + } |
| 37 | + ``` |
| 38 | + |
| 39 | +1. If your client needs a schema for documentation rendering or autocomplete, fetch it via a GraphQL introspection query. Many clients can do this automatically from the "Docs" panel. |
| 40 | + |
| 41 | + Minimal introspection query: |
| 42 | + |
| 43 | + ```graphql |
| 44 | + query IntrospectionQuery { |
| 45 | + __schema { |
| 46 | + types { |
| 47 | + name |
| 48 | + } |
| 49 | + } |
| 50 | + } |
| 51 | + ``` |
| 52 | + |
| 53 | +1. Run the request and inspect the JSON response. Query from example should return the login associated with the {% data variables.product.company_short %} {% data variables.product.pat_generic %} you authenticated with. |
| 54 | + |
| 55 | +Use the client UI to explore docs, run queries, and save requests as needed. |
| 56 | + |
| 57 | +## {% data variables.product.prodname_cli %} |
| 58 | + |
| 59 | +You can also use the command line with {% data variables.product.prodname_cli %} to run GraphQL queries. |
| 60 | + |
| 61 | +1. Install and [authenticate with {% data variables.product.prodname_cli %}](https://cli.github.com/manual/gh_auth_login). |
| 62 | +1. Run a query against `{% data variables.product.graphql_url %}` using the GraphQL endpoint with the [`gh api` subcommand](https://cli.github.com/manual/gh_api). |
| 63 | + |
| 64 | +Example: |
| 65 | + |
| 66 | +```shell |
| 67 | +gh api graphql -f query='query { viewer { login } }' |
| 68 | +``` |
| 69 | + |
| 70 | +This should return the login associated with the {% data variables.product.company_short %} {% data variables.product.pat_generic %} you authenticated with. |
| 71 | + |
| 72 | +## Requesting support |
| 73 | + |
| 74 | +{% data reusables.support.help_resources %} |
0 commit comments