From f46803a8c70840280529a52acbb111c865712af2 Mon Sep 17 00:00:00 2001 From: Eddy Nguyen Date: Mon, 15 May 2023 23:08:25 +1000 Subject: [PATCH] [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 --- .changeset/breezy-rice-retire.md | 5 +++ packages/utils/plugins-helpers/src/types.ts | 5 +++ .../docs/config-reference/schema-field.mdx | 33 ++++++++++++++++++- 3 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 .changeset/breezy-rice-retire.md diff --git a/.changeset/breezy-rice-retire.md b/.changeset/breezy-rice-retire.md new file mode 100644 index 00000000000..dbad5d9dd85 --- /dev/null +++ b/.changeset/breezy-rice-retire.md @@ -0,0 +1,5 @@ +--- +'@graphql-codegen/plugin-helpers': patch +--- + +Update GitHub loader TypeScript type and usage docs diff --git a/packages/utils/plugins-helpers/src/types.ts b/packages/utils/plugins-helpers/src/types.ts index 0f8ad29de51..d81f5948669 100644 --- a/packages/utils/plugins-helpers/src/types.ts +++ b/packages/utils/plugins-helpers/src/types.ts @@ -187,6 +187,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). @@ -195,6 +199,7 @@ export namespace Types { | string | UrlSchemaWithOptions | ApolloEngineSchemaOptions + | GitHubSchemaOptions | LocalSchemaPathWithOptions | SchemaGlobPath | SchemaWithLoader diff --git a/website/src/pages/docs/config-reference/schema-field.mdx b/website/src/pages/docs/config-reference/schema-field.mdx index a707d79ca70..67a918cf509 100644 --- a/website/src/pages/docs/config-reference/schema-field.mdx +++ b/website/src/pages/docs/config-reference/schema-field.mdx @@ -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: "" } + } +}; +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'; @@ -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= yarn graphql-codegen +``` You can load from a JSON file, `.graphql` file, or from a code file containing `gql` tag syntax.