Skip to content

Commit f46803a

Browse files
authored
[cli/docs]Add GitHub Loader TypeScript type, update usage docs (#9332)
* Add GitHub Loader TypeScript type, update usage docs * Use better typing for github schema value
1 parent 071bcd3 commit f46803a

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
lines changed

.changeset/breezy-rice-retire.md

+5
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

+5
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,10 @@ export namespace Types {
187187
'apollo-engine': ApolloEngineOptions;
188188
}
189189

190+
export interface GitHubSchemaOptions {
191+
[githubProtocol: `github:${string}`]: { token: string };
192+
}
193+
190194
export type SchemaGlobPath = string;
191195
/**
192196
* @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).
@@ -195,6 +199,7 @@ export namespace Types {
195199
| string
196200
| UrlSchemaWithOptions
197201
| ApolloEngineSchemaOptions
202+
| GitHubSchemaOptions
198203
| LocalSchemaPathWithOptions
199204
| SchemaGlobPath
200205
| SchemaWithLoader

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

+32-1
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,7}
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)