Skip to content

Commit c317eba

Browse files
committed
feat(action): add support for headers
1 parent 33a1eb9 commit c317eba

File tree

6 files changed

+51
-5
lines changed

6 files changed

+51
-5
lines changed

action.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@ inputs:
3030
An url to the GraphQL API. It should represent the "before" schema.
3131
3232
When using an endpoint, 'schema' should point to a file (without a reference - branch name for example)
33+
headers:
34+
description: |
35+
Pass headers when fetching the "before" schema.
36+
This only applies when `endpoint` is defined and only applies to the "before" schema.
37+
method:
38+
description: |
39+
Pass headers when fetching the "before" schema.
40+
This only applies when `endpoint` is defined and only applies to the "before" schema.
3341
github-token:
3442
default: '${{ github.token }}'
3543
required: false

packages/action/src/run.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
CheckConclusion,
88
createSummary,
99
diff,
10+
EndpointMethod,
1011
printSchemaFromEndpoint,
1112
produceSchema,
1213
} from '@graphql-inspector/github';
@@ -40,6 +41,8 @@ export async function run() {
4041
const useAnnotations = castToBoolean(core.getInput('annotations'));
4142
const failOnBreaking = castToBoolean(core.getInput('fail-on-breaking'));
4243
const endpoint: string = core.getInput('endpoint');
44+
const headers: string = core.getInput('headers');
45+
const method = core.getInput('method') as EndpointMethod;
4346
const approveLabel: string = core.getInput('approve-label') || 'approved-breaking-change';
4447
const rulesList = getInputAsArray('rules') || [];
4548
const onUsage = core.getInput('getUsage');
@@ -131,7 +134,14 @@ export async function run() {
131134

132135
const [oldFile, newFile] = await Promise.all([
133136
endpoint
134-
? printSchemaFromEndpoint(endpoint)
137+
? printSchemaFromEndpoint({
138+
url: endpoint,
139+
method,
140+
headers: headers
141+
? // Go from "name:value,name:value" to { name: value, name: value}
142+
Object.fromEntries(headers.split(',').map(header => header.split(':')))
143+
: undefined,
144+
})
135145
: loadFile({
136146
ref: schemaRef,
137147
path: schemaPath,

packages/github/src/helpers/config.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@ export type Endpoint =
55
| string
66
| {
77
url: string;
8-
method?: 'get' | 'GET' | 'post' | 'POST';
8+
method?: EndpointMethod;
99
headers?: {
1010
[name: string]: string;
1111
};
1212
};
1313

14+
export type EndpointMethod = 'get' | 'GET' | 'post' | 'POST';
15+
1416
export interface SchemaPointer {
1517
ref: string;
1618
path: string;

packages/github/src/helpers/utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Change, CriticalityLevel } from '@graphql-inspector/core';
2-
import { Endpoint } from './config';
2+
import { Endpoint, EndpointMethod } from './config';
33

44
export function bolderize(msg: string): string {
55
return quotesTransformer(msg, '**');
@@ -103,7 +103,7 @@ export function isNil(val: any): val is undefined | null {
103103

104104
export function parseEndpoint(endpoint: Endpoint): {
105105
url: string;
106-
method: 'GET' | 'get' | 'post' | 'POST';
106+
method: EndpointMethod;
107107
headers?: {
108108
[name: string]: string;
109109
};

packages/github/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export { default, default as app } from './app';
2-
export { createConfig, NormalizedConfig, SchemaPointer } from './helpers/config';
2+
export { createConfig, NormalizedConfig, SchemaPointer, EndpointMethod } from './helpers/config';
33
export { setDiagnostics } from './helpers/diagnostics';
44
export { diff } from './helpers/diff';
55
export { createFileLoader, printSchemaFromEndpoint } from './helpers/loaders';

website/src/pages/docs/products/action.mdx

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,32 @@ If you want to use GraphQL API endpoint as source of "after" schema:
117117
endpoint: 'https://my-app.com/graphql'
118118
```
119119

120+
### `headers`
121+
122+
Pass headers when fetching the "before" schema.
123+
This only applies when `endpoint` is defined and only applies to the "before" schema.
124+
125+
```yaml
126+
- uses: kamilkisiela/graphql-inspector@master
127+
with:
128+
schema: schema.graphql # important to define a path to schema file, without a branch
129+
endpoint: 'https://my-app.com/graphql'
130+
headers: 'Authorization: Bearer ${{ secrets.token }},X-My-Header:${{ secrets.secret_header_value }}'
131+
```
132+
133+
### `method`
134+
135+
Set a custom method to fetch the "before" schema with.
136+
This only applies when `endpoint` is defined and only applies to the "before" schema.
137+
138+
```yaml
139+
- uses: kamilkisiela/graphql-inspector@master
140+
with:
141+
schema: schema.graphql # important to define a path to schema file, without a branch
142+
endpoint: 'https://my-app.com/graphql'
143+
method: 'GET' # Can be any of [GET, get, POST, post]
144+
```
145+
120146
### `rules`
121147

122148
Apply [rules](../essentials/diff#rules) included with the Inspector as well as your own

0 commit comments

Comments
 (0)