Skip to content

Commit 646309f

Browse files
committed
Add GitHub Loader TypeScript type, update usage docs
1 parent 21050ae commit 646309f

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
lines changed

.changeset/breezy-rice-retire.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@graphql-codegen/plugin-helpers': patch
3+
---
4+
5+
Update GitHub loader TypeScript type and usage docs

packages/utils/plugins-helpers/src/types.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,10 @@ export namespace Types {
183183
'apollo-engine': ApolloEngineOptions;
184184
}
185185

186+
export interface GitHubSchemaOptions {
187+
[githubProtocol: string]: { token: string };
188+
}
189+
186190
export type SchemaGlobPath = string;
187191
/**
188192
* @description A URL to your GraphQL endpoint, a local path to `.graphql` file, a glob pattern to your GraphQL schema files, or a JavaScript file that exports the schema to generate code from. This can also be an array which specifies multiple schemas to generate code from. You can read more about the supported formats [here](schema-field#available-formats).
@@ -191,6 +195,7 @@ export namespace Types {
191195
| string
192196
| UrlSchemaWithOptions
193197
| ApolloEngineSchemaOptions
198+
| GitHubSchemaOptions
194199
| LocalSchemaPathWithOptions
195200
| SchemaGlobPath
196201
| SchemaWithLoader

website/src/pages/docs/config-reference/schema-field.mdx

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,33 @@ export default config;
445445

446446
### GitHub
447447

448-
You can load your schema file from a remote GitHub file, using the following syntax:
448+
You can load your schema file from a remote GitHub file using one of the following approaches:
449+
450+
#### Provide GitHub token in Codegen Config
451+
452+
Provide the GitHub path to your schema and token using the following syntax:
453+
454+
```ts {4,5,6}
455+
import { CodegenConfig } from '@graphql-codegen/cli';
456+
457+
const config: CodegenConfig = {
458+
schema: {
459+
'github:user/repo#branchName:path/to/file.graphql':
460+
{ token: "<YOUR GITHUB TOKEN>" }
461+
}
462+
};
463+
export default config;
464+
```
465+
466+
Then, run codegen:
467+
468+
```bash
469+
yarn graphql-codegen
470+
```
471+
472+
#### Provide GitHub token via Codegen CLI
473+
474+
Alternatively, you can provide just the GitHub path to your schema:
449475

450476
```ts {4}
451477
import { CodegenConfig } from '@graphql-codegen/cli';
@@ -456,6 +482,11 @@ const config: CodegenConfig = {
456482
export default config;
457483
```
458484

485+
Then, provide your GitHub token using the `GITHU_TOKEN` environment variable when running codegen:
486+
487+
```bash
488+
GITHUB_TOKEN=<YOUR GITHUB TOKEN> yarn graphql-codegen
489+
```
459490

460491
<Callout>You can load from a JSON file, `.graphql` file, or from a code file containing `gql` tag syntax.</Callout>
461492

0 commit comments

Comments
 (0)