Combine product name variables for REST and GraphQL API base URLs (#50521)
This commit is contained in:
@@ -44,7 +44,7 @@ To authenticate with an OAuth token from an {% data variables.product.prodname_o
|
||||
|
||||
The REST API has numerous endpoints; the GraphQL API has a single endpoint:
|
||||
|
||||
<pre>{% data variables.product.graphql_url_pre %}</pre>
|
||||
<pre>{% data variables.product.graphql_url %}</pre>
|
||||
|
||||
The endpoint remains constant no matter what operation you perform.
|
||||
|
||||
@@ -61,7 +61,7 @@ curl -H "Authorization: bearer TOKEN" -X POST -d " \
|
||||
{ \
|
||||
\"query\": \"query { viewer { login }}\" \
|
||||
} \
|
||||
" {% data variables.product.graphql_url_code %}
|
||||
" {% data variables.product.graphql_url %}
|
||||
```
|
||||
|
||||
{% tip %}
|
||||
|
||||
@@ -115,7 +115,7 @@ GraphQL is [introspective](https://graphql.org/learn/introspection/). This means
|
||||
- You can also run an _introspection query_ of the schema via a `GET` request:
|
||||
|
||||
```shell
|
||||
curl -H "Authorization: bearer TOKEN" {% data variables.product.graphql_url_pre %}
|
||||
curl -H "Authorization: bearer TOKEN" {% data variables.product.graphql_url %}
|
||||
```
|
||||
|
||||
{% note %}
|
||||
@@ -130,7 +130,7 @@ GraphQL is [introspective](https://graphql.org/learn/introspection/). This means
|
||||
|
||||
```shell
|
||||
$ curl -H "Authorization: bearer TOKEN" -H "Accept: application/vnd.github.v4.idl" \
|
||||
{% data variables.product.graphql_url_pre %}
|
||||
{% data variables.product.graphql_url %}
|
||||
```
|
||||
|
||||
{% note %}
|
||||
|
||||
@@ -39,7 +39,7 @@ Here are examples of each.
|
||||
A single REST API call retrieves a list of your organization's members:
|
||||
|
||||
```shell
|
||||
curl -v {% data variables.product.api_url_pre %}/orgs/:org/members
|
||||
curl -v {% data variables.product.rest_url %}/orgs/:org/members
|
||||
```
|
||||
|
||||
The REST payload contains excessive data if your goal is to retrieve only member names and links to avatars. However, a GraphQL query returns only what you specify:
|
||||
@@ -62,13 +62,13 @@ query {
|
||||
Consider another example: retrieving a list of pull requests and checking if each one is mergeable. A call to the REST API retrieves a list of pull requests and their [summary representations](/rest#summary-representations):
|
||||
|
||||
```shell
|
||||
curl -v {% data variables.product.api_url_pre %}/repos/:owner/:repo/pulls
|
||||
curl -v {% data variables.product.rest_url %}/repos/:owner/:repo/pulls
|
||||
```
|
||||
|
||||
Determining if a pull request is mergeable requires retrieving each pull request individually for its [detailed representation](/rest#detailed-representations) (a large payload) and checking whether its `mergeable` attribute is true or false:
|
||||
|
||||
```shell
|
||||
curl -v {% data variables.product.api_url_pre %}/repos/:owner/:repo/pulls/:number
|
||||
curl -v {% data variables.product.rest_url %}/repos/:owner/:repo/pulls/:number
|
||||
```
|
||||
|
||||
With GraphQL, you could retrieve only the `number` and `mergeable` attributes for each pull request:
|
||||
@@ -93,10 +93,10 @@ query {
|
||||
Querying with nested fields lets you replace multiple REST calls with fewer GraphQL queries. For example, retrieving a pull request along with its commits, non-review comments, and reviews using the **REST API** requires four separate calls:
|
||||
|
||||
```shell
|
||||
curl -v {% data variables.product.api_url_pre %}/repos/:owner/:repo/pulls/:number
|
||||
curl -v {% data variables.product.api_url_pre %}/repos/:owner/:repo/pulls/:number/commits
|
||||
curl -v {% data variables.product.api_url_pre %}/repos/:owner/:repo/issues/:number/comments
|
||||
curl -v {% data variables.product.api_url_pre %}/repos/:owner/:repo/pulls/:number/reviews
|
||||
curl -v {% data variables.product.rest_url %}/repos/:owner/:repo/pulls/:number
|
||||
curl -v {% data variables.product.rest_url %}/repos/:owner/:repo/pulls/:number/commits
|
||||
curl -v {% data variables.product.rest_url %}/repos/:owner/:repo/issues/:number/comments
|
||||
curl -v {% data variables.product.rest_url %}/repos/:owner/:repo/pulls/:number/reviews
|
||||
```
|
||||
|
||||
Using the **GraphQL API**, you can retrieve the data with a single query using nested fields:
|
||||
|
||||
@@ -34,7 +34,7 @@ Let's walk through an example.
|
||||
If you [request the authenticated user](/rest/users/users#get-the-authenticated-user):
|
||||
|
||||
```shell
|
||||
curl -i --header "Authorization: Bearer YOUR-TOKEN" {% data variables.product.api_url_pre %}/user
|
||||
curl -i --header "Authorization: Bearer YOUR-TOKEN" {% data variables.product.rest_url %}/user
|
||||
```
|
||||
|
||||
you'll get a response that includes the `node_id` of the authenticated user:
|
||||
|
||||
@@ -87,7 +87,7 @@ There are many open source GraphQL client IDEs. For example, you can use Altair
|
||||
1. In the "Header key" field, enter `Authorization`.
|
||||
1. In the "Header value" field, enter `Bearer TOKEN`, replacing `TOKEN` with your token from the first step.
|
||||
1. Click **Save** in the bottom right corner of the window to save your authorization header.
|
||||
1. In the "GraphQL Endpoint" field, enter `{% data variables.product.graphql_url_pre %}`.
|
||||
1. In the "GraphQL Endpoint" field, enter `{% data variables.product.graphql_url %}`.
|
||||
1. To load the {% data variables.product.company_short %} GraphQL schema, download the [public schema](/graphql/overview/public-schema).
|
||||
1. In Altair, click on **Docs** on the top right, then the three dots and **Load Schema...**
|
||||
1. Select the file public schema that you downloaded in an earlier step.
|
||||
|
||||
Reference in New Issue
Block a user