--- title: "ADR 0016: GraphQL batch file fetch endpoint and batch size" --- * Status: accepted * Code: [`pkg/provider/github/graphql.go`](https://github.com/tektoncd/pipelines-as-code/blob/main/pkg/provider/github/graphql.go) ## Context File contents are fetched with GraphQL, one aliased `object(expression: "<ref>:<path>")` field per file, instead of one REST call per file. The GraphQL URL is not configured: it is derived from the REST client's base URL. ## Decision * `buildGraphQLEndpoint` maps `https://api.github.com` to `https://api.github.com/graphql`. For anything else it replaces a trailing `/api/v3` of the base URL path with `/api/graphql` (GitHub Enterprise: `https://ghe.example.com/api/v3/` becomes `https://ghe.example.com/api/graphql`; the unit test servers on `http://127.0.0.1:PORT` follow the same rule). A path without that suffix falls back to `/api/graphql` on the same host. The base URL has its trailing slash trimmed first, so the comparison is against the slash-less form. * `ref` and every path are escaped for backslash and double quote before being placed in the query string. * `fetchFiles` sends at most 50 paths per query (`maxBatchSize`); the cap is there to avoid query complexity problems. * The request is marked with `retryhttp.WithReadOnlyPostRetry`, since the POST is a read-only query and may be retried by the retrying transport. ## Consequences * A base URL that does not end in `/api/v3` is assumed to serve GraphQL at `/api/graphql`, whatever its path was. * Fetching more than 50 files costs more than one request.