Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[cli/docs]Add GitHub Loader TypeScript type, update usage docs #9332

Merged
merged 2 commits into from
May 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/breezy-rice-retire.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@graphql-codegen/plugin-helpers': patch
---

Update GitHub loader TypeScript type and usage docs
5 changes: 5 additions & 0 deletions packages/utils/plugins-helpers/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,10 @@ export namespace Types {
'apollo-engine': ApolloEngineOptions;
}

export interface GitHubSchemaOptions {
[githubProtocol: `github:${string}`]: { token: string };
}

export type SchemaGlobPath = string;
/**
* @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).
Expand All @@ -191,6 +195,7 @@ export namespace Types {
| string
| UrlSchemaWithOptions
| ApolloEngineSchemaOptions
| GitHubSchemaOptions
| LocalSchemaPathWithOptions
| SchemaGlobPath
| SchemaWithLoader
Expand Down
33 changes: 32 additions & 1 deletion website/src/pages/docs/config-reference/schema-field.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,33 @@ export default config;

### GitHub

You can load your schema file from a remote GitHub file, using the following syntax:
You can load your schema file from a remote GitHub file using one of the following approaches:

#### Provide GitHub token in Codegen Config

Provide the GitHub path to your schema and token using the following syntax:

```ts {4,5,6,7}
import { CodegenConfig } from '@graphql-codegen/cli';

const config: CodegenConfig = {
schema: {
'github:user/repo#branchName:path/to/file.graphql':
{ token: "<YOUR GITHUB TOKEN>" }
}
};
export default config;
```

Then, run codegen:

```bash
yarn graphql-codegen
```

#### Provide GitHub token via Codegen CLI

Alternatively, you can provide just the GitHub path to your schema:

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

Then, provide your GitHub token using the `GITHU_TOKEN` environment variable when running codegen:

```bash
GITHUB_TOKEN=<YOUR GITHUB TOKEN> yarn graphql-codegen
```

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

Expand Down