Update to the latest version of @actions/github.

This commit is contained in:
Chris Gavin 2020-09-18 15:40:23 +01:00
parent 55458a1ab1
commit 9ed519fa12
No known key found for this signature in database
GPG key ID: 07F950B80C27E4DA
419 changed files with 56978 additions and 151535 deletions

View file

@ -3,8 +3,7 @@
> GitHub GraphQL API client for browsers and Node
[![@latest](https://img.shields.io/npm/v/@octokit/graphql.svg)](https://www.npmjs.com/package/@octokit/graphql)
[![Build Status](https://travis-ci.com/octokit/graphql.js.svg?branch=master)](https://travis-ci.com/octokit/graphql.js)
[![Greenkeeper](https://badges.greenkeeper.io/octokit/graphql.js.svg)](https://greenkeeper.io/)
[![Build Status](https://github.com/octokit/graphql.js/workflows/Test/badge.svg)](https://github.com/octokit/graphql.js/actions?query=workflow%3ATest+branch%3Amaster)
<!-- toc -->
@ -13,7 +12,8 @@
- [Authentication](#authentication)
- [Variables](#variables)
- [Pass query together with headers and variables](#pass-query-together-with-headers-and-variables)
- [Use your own `@octokit/request` instance](#)
- [Use with GitHub Enterprise](#use-with-github-enterprise)
- [Use custom `@octokit/request` instance](#use-custom-octokitrequest-instance)
- [Errors](#errors)
- [Partial responses](#partial-responses)
- [Writing tests](#writing-tests)
@ -72,8 +72,8 @@ const { repository } = await graphql(
`,
{
headers: {
authorization: `token secret123`
}
authorization: `token secret123`,
},
}
);
```
@ -85,8 +85,8 @@ The simplest way to authenticate a request is to set the `Authorization` header,
```js
const graphqlWithAuth = graphql.defaults({
headers: {
authorization: `token secret123`
}
authorization: `token secret123`,
},
});
const { repository } = await graphqlWithAuth(`
{
@ -110,12 +110,12 @@ const { createAppAuth } = require("@octokit/auth-app");
const auth = createAppAuth({
id: process.env.APP_ID,
privateKey: process.env.PRIVATE_KEY,
installationId: 123
installationId: 123,
});
const graphqlWithAuth = graphql.defaults({
request: {
hook: auth.hook
}
hook: auth.hook,
},
});
const { repository } = await graphqlWithAuth(
@ -138,30 +138,34 @@ const { repository } = await graphqlWithAuth(
⚠️ Do not use [template literals](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals) in the query strings as they make your code vulnerable to query injection attacks (see [#2](https://github.com/octokit/graphql.js/issues/2)). Use variables instead:
```js
const { lastIssues } = await graphql(`query lastIssues($owner: String!, $repo: String!, $num: Int = 3) {
repository(owner:$owner, name:$repo) {
issues(last:$num) {
edges {
node {
title
const { lastIssues } = await graphql(
`
query lastIssues($owner: String!, $repo: String!, $num: Int = 3) {
repository(owner: $owner, name: $repo) {
issues(last: $num) {
edges {
node {
title
}
}
}
}
}
}`, {
owner: 'octokit',
repo: 'graphql.js'
`,
{
owner: "octokit",
repo: "graphql.js",
headers: {
authorization: `token secret123`
}
authorization: `token secret123`,
},
}
})
);
```
### Pass query together with headers and variables
```js
const { graphql } = require('@octokit/graphql')
const { graphql } = require("@octokit/graphql");
const { lastIssues } = await graphql({
query: `query lastIssues($owner: String!, $repo: String!, $num: Int = 3) {
repository(owner:$owner, name:$repo) {
@ -174,12 +178,12 @@ const { lastIssues } = await graphql({
}
}
}`,
owner: 'octokit',
repo: 'graphql.js'
owner: "octokit",
repo: "graphql.js",
headers: {
authorization: `token secret123`
}
})
authorization: `token secret123`,
},
});
```
### Use with GitHub Enterprise
@ -189,8 +193,8 @@ let { graphql } = require("@octokit/graphql");
graphql = graphql.defaults({
baseUrl: "https://github-enterprise.acme-inc.com/api",
headers: {
authorization: `token secret123`
}
authorization: `token secret123`,
},
});
const { repository } = await graphql(`
{
@ -213,20 +217,20 @@ const { repository } = await graphql(`
const { request } = require("@octokit/request");
const { withCustomRequest } = require("@octokit/graphql");
let requestCounter = 0
let requestCounter = 0;
const myRequest = request.defaults({
headers: {
authentication: 'token secret123'
authentication: "token secret123",
},
request: {
hook(request, options) {
requestCounter++
return request(options)
}
}
})
const myGraphql = withCustomRequest(myRequest)
await request('/')
requestCounter++;
return request(options);
},
},
});
const myGraphql = withCustomRequest(myRequest);
await request("/");
await myGraphql(`
{
repository(owner: "acme-project", name: "acme-repo") {
@ -251,8 +255,8 @@ In case of a GraphQL error, `error.message` is set to the first error from the r
let { graphql } = require("@octokit/graphql");
graphqlt = graphql.defaults({
headers: {
authorization: `token secret123`
}
authorization: `token secret123`,
},
});
const query = `{
viewer {
@ -288,8 +292,8 @@ A GraphQL query may respond with partial data accompanied by errors. In this cas
let { graphql } = require("@octokit/graphql");
graphql = graphql.defaults({
headers: {
authorization: `token secret123`
}
authorization: `token secret123`,
},
});
const query = `{
repository(name: "probot", owner: "probot") {
@ -357,7 +361,7 @@ const { graphql } = require("@octokit/graphql");
graphql("{ viewer { login } }", {
headers: {
authorization: "token secret123"
authorization: "token secret123",
},
request: {
fetch: fetchMock
@ -370,8 +374,8 @@ graphql("{ viewer { login } }", {
"Sends correct query"
);
return { data: {} };
})
}
}),
},
});
```