1import { gql } from "@apollo/client";
2import { createFileRoute } from "@tanstack/react-router";
3
4import type { GitRef } from "@/__generated__/graphql";
5
6export const REFS_QUERY = gql`
7 query CodePageRefs($repo: String) {
8 repository(ref: $repo) {
9 name
10 refs {
11 nodes {
12 name
13 shortName
14 type
15 hash
16 isDefault
17 }
18 }
19 }
20 }
21`;
22
23export interface RefsQueryData {
24 repository: {
25 name: string;
26 refs: { nodes: GitRef[] } | null;
27 } | null;
28}
29
30export const Route = createFileRoute("/$repo")({
31 beforeLoad: ({ params: { repo }, context: { preloadQuery } }) => {
32 // Normalize the repo slug: "_" means the default (null) repo
33 const ref = repo === "_" ? null : repo;
34
35 // Preload refs once for the entire repo — shared by code browser,
36 // and used for the /$repo → tree redirect.
37 const refsRef = preloadQuery<RefsQueryData>(REFS_QUERY, {
38 variables: { repo: ref },
39 });
40
41 return { ref, refsRef };
42 },
43});