Skip to content

Generate the GitHub template from GitHub's GraphQL schema - #321

Merged
tnkuehne merged 6 commits into
feat/gmail-templatefrom
feat/github-template
Nov 23, 2026
Merged

tnkuehne merged 6 commits into
feat/gmail-templatefrom
feat/github-template

Conversation

@tnkuehne

@tnkuehne tnkuehne commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Why

The GitHub template offers three hand-written REST methods: list repositories, list issues, read a file. Anything else, like opening issues or pull requests, reviews, discussions or projects, needs a template change. GitHub publishes its GraphQL schema, so the template can offer the whole API as typed methods, the same way the Linear template does.

What changes

GitHub template

  • Methods: 202 typed methods, 24 queries and 178 mutations, from GitHub's public GraphQL schema. Most data is reached through repository, viewer, organization, node and search.

  • Field selections: work like in Linear, including $args and $on for interfaces and unions. Text files are read through repository.object with $on: { Blob: { text: true } }.

  • Not offered (98 operations): listed in scripts/operations.ts with a reason for each:

    • enterprise administration;
    • organization settings that need admin:org or write:org;
    • Enterprise Importer migrations;
    • GitHub Sponsors;
    • check runs and check suites, which only GitHub Apps can create;
    • package deletion.

    Deprecated operations, such as classic Projects, are left out automatically.

  • Approvals: per-user approval level, like in Linear.

    • create is used only for pure additions: issues, comments, branches, reactions.
    • addPullRequestReview is update: given an event such as APPROVE, it submits the review at once.
    • Anything that changes, merges, closes, restricts or deletes existing data asks under the default level. For example: merging, branch protection, rulesets, deployments, updateRefs.
  • Scopes: repo, workflow, project, read:org and user.

    • An account connected with fewer scopes gets permission_required from every method and from connectionStatus, with a link to reconnect.
    • The managed client requests the same scopes.
  • Errors:

    GitHub answer Result
    GraphQL errors github_error with GitHub's type, e.g. NOT_FOUND
    RATE_LIMITED errors, exhausted or secondary rate limits (403/429) rate_limited, with retryAfter from Retry-After or the limit's reset time
    401 reconnect_required
    any other 403 access_denied
  • Large responses: larger than 8 MiB give too_large, in GitHub and Linear alike, instead of being read into memory.

  • Removed: the REST methods and their helpers (listRepositories, listIssues, readFile).

    • Binary file contents and REST-only features such as releases or Actions runs aren't available yet. They need an OpenAPI generator, which a following PR adds.
  • template.md describes scopes, selections, approvals, results and how to regenerate.

Generator and the other templates

  • GraphQL request builder: moves into the shared runtime. Each template keeps its own error mapping: Linear reads extensions, GitHub reads type.
  • Fragment fields: fields inside ... on Variant are aliased and restored along the selection, because two variants may have a field of one name with different types. A field selected both for every type and in $on must pass the same $args. Selections may leave optional values undefined.
  • JSON imports: the generated file imports the JSON types that types or method signatures use.
  • Environment import: generated files import the template's Environment as TemplateEnvironment, because GitHub has a type called Environment. The generator stops when an API type would shadow another import.
  • Enums: keep deprecated values, because results can still carry them. One GitHub enum consists only of deprecated values.
  • Comments: irregular spaces in descriptions become plain spaces.
  • Failed responses without GraphQL errors: in Linear and GitHub, a 4xx/5xx response whose JSON body has no GraphQL errors no longer counts as an empty success. A 403 gives access_denied; other statuses fail.

Approval level form

A consuming app could send the approval level form through env.GITHUB.fetch() with a forged Origin. #323 fixes that in the runtime for every template.

Managed OAuth

A managed github client only grants the scopes its scopes setting allows. Installations that offer managed OAuth for GitHub must add workflow, project, read:org and user to that setting. Until they do, starting a managed connection fails with "The requested scopes are not allowed for this client". Installations with their own OAuth app (GITHUB_CLIENT_ID/GITHUB_CLIENT_SECRET) aren't affected.

Connection page

Connected state, with the same approval form as Linear and Gmail.

Before After

Not shown: the disconnected and setup-required states. They only change their description text.

Testing

  • pnpm check
  • Generator: tests for type names that shadow imports and for the TemplateEnvironment alias.
  • Request builder against GitHub's schema: variables, interfaces, unions, schema mismatches.
  • GitHub template against a mocked GitHub:
    • typed requests;
    • approvals for every level;
    • missing scopes;
    • GraphQL errors and rate limits;
    • revoked tokens;
    • expiring and non-expiring tokens;
    • callback checks.
  • Type tests: selections narrow results, $on narrows by __typename, and the README example compiles.
  • Managed OAuth tests (app runtime and control plane): now run against the GraphQL template.
  • Regenerating Linear, GitHub and Gmail from saved sources reproduces the committed files.
  • Not tested against a live GitHub account.

RetriggerView in GreptileConfidence Score: 5/5 Tier: plus

No new blocking issue was found in this PR.

Summary

Replaces GitHub’s three REST methods with 202 generated, typed GraphQL methods.

  • GitHub calls now use a generated, typed GraphQL API.
  • GraphQL selections now handle arguments and type-specific fields.
  • GitHub mutation calls now follow each user's approval setting.
  • GitHub calls now check required scopes and return clear GraphQL results.
  • Generated templates now keep their API types separate from imported types.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Typed method and field selection] --> B[Build GraphQL request]
  B --> C{Mutation needs approval?}
  C -->|Yes| D[Ask the current user]
  D -->|Accepted| E[Check connection and scopes]
  C -->|No| E
  E --> F[Call GitHub]
  F --> G[Limit response size and read errors]
  G --> H[Restore selected field names]
  H --> I[Return typed result]
Loading

Reviews (10) · Last reviewed commit: "Compare fragment arguments regardless of..." · Reviewed by Greptile

@tnkuehne
tnkuehne added this pull request to stack #320 November 22, 2026 23:52
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Nov 22, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
widefleet-docs 55f76aa Nov 23 2026, 10:17 AM

@tnkuehne
tnkuehne force-pushed the feat/github-template branch from 2f615f4 to 44d4514 Compare November 22, 2026 23:55
Comment thread templates/github/scripts/operations.ts Resolved
@tnkuehne
tnkuehne force-pushed the feat/github-template branch from 44d4514 to a242796 Compare November 23, 2026 00:16
Comment thread templates/github/src/graphql.ts Resolved
Comment thread templates/linear/src/graphql.ts Resolved
"approval-methods.ts",
"input.ts",
...(rules.kind === "discovery" ? ["google.ts"] : []),
rules.kind === "discovery" ? "google.ts" : "graphql.ts",

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Updating Linear breaks builds

Regenerating an existing Linear app now replaces src/graphql.ts with a file that no longer exports linearApi or linearErrors. The app's existing src/connection.ts imports both, but this command does not update that file. The documented update command therefore leaves the app unable to build.

Keep the old exports compatible, or migrate the app's callers when replacing the shared builder. Its existing src/run.ts also needs the new result-name restoration when fragment fields become aliased.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Intended: an app copied from the earlier Linear template, before the shared runtime existed, takes src/connection.ts and src/run.ts from the template once when it first regenerates. The generator owns only the files it writes and copies. Keeping linearApi/linearErrors exports in the shared builder would put Linear-specific code into every GraphQL template.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it — that makes sense. The generator's responsibility is scoped to the files it generates, and apps migrating from the old Linear template should pick up the updated connection.ts and run.ts from the template itself during regeneration.

Is there documentation or a migration note that tells users to copy those files when regenerating, or is that expected to be obvious from the template structure? If users might miss it and end up with the broken imports, a note in the template README or regeneration docs could help.

Shall I remember this as a rule: "Template regeneration only updates generated files; apps migrating from earlier templates must manually copy connection.ts and run.ts from the template to avoid import breakage"?

Comment thread templates/github/src/graphql.ts Resolved
@tnkuehne
tnkuehne force-pushed the feat/github-template branch from 11e4400 to 17cb5d5 Compare November 23, 2026 10:05
The GitHub template wrapped three hand-written REST methods. It now offers
GitHub's GraphQL API as typed methods with field selections, generated like
the Linear template: pnpm --filter @platform/template-generator generate github.

Mutations ask for approval by each user's level. Enterprise and organization
administration, migrations, GitHub Sponsors and the mutations only GitHub
Apps can call are not offered. The connector requests the scopes the offered
methods need, and accounts connected with fewer scopes are asked to
reconnect.

The GraphQL request builder moves into the generator's shared runtime. The
generator imports the template's environment type under its own name,
since GitHub has a type called Environment, and stops when an API type would
shadow another import.
GitHub's and Linear's responses larger than 8 MiB return too_large instead of
being read into memory. addPullRequestReview asks first, since an event
submits the review at once. The generator imports the JSON types that only
method signatures use, and the catalog search test looks for a phrase of
GitHub's new description.
Two variants of a union or interface may have a field of one name with
different types, such as Issue.state and PullRequest.state. GraphQL rejects
both in one selection under the same name. Fields inside ... on Variant now
take the alias field__on__Variant, and results get their selected names
back.
Restoring renamed every key ending in __on__Variant, including keys inside
JSON values such as Linear's attachment metadata, and a field selected both
for every type and in a fragment kept only one of its objects. The result is
now read along the selection and the schema: only aliases the request wrote
are renamed, both objects of one field are merged, and JSON values stay as
the provider returned them.
A field selected for every type and in $on lands in one object of the
result, so both selections must pass the same $args; requests that differ
now fail before anything is sent. Selections may leave optional values
undefined, as arguments already could.
Arguments of a field selected for every type and in $on are equal when they
hold the same values, whatever order their keys have.
@tnkuehne
tnkuehne force-pushed the feat/github-template branch from 17cb5d5 to 55f76aa Compare November 23, 2026 10:16
@tnkuehne

Copy link
Copy Markdown
Contributor Author

@greptileai review

@tnkuehne
tnkuehne merged commit 4028981 into main Nov 23, 2026
15 of 16 checks passed
@tnkuehne
tnkuehne deleted the feat/github-template branch November 23, 2026 10:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant