Browse GitHub users, their repositories, organizations and followers through the GitHub GraphQL API, built on the Next.js 13 App Router.
Live demo: github-viewer-nine.vercel.app
- Home page listing GitHub users returned by a GraphQL
searchquery, each shown as an avatar card - User detail page at
/user?login=<username>that works for any valid GitHub login, not only the users on the home page - User sidebar with organizations and recent followers, linking out to their GitHub profiles
- List of the user's repositories, newest first
- Responsive Tailwind layout: the user card grid moves from one to two to three columns as the viewport grows
- Server and client data fetching with one Apollo setup. The home page is an async React Server Component that queries GitHub via
registerApolloClientfrom@apollo/experimental-nextjs-app-support/rsc(src/lib/getClient.ts). The user page is a Client Component usinguseSuspenseQuery, wrapped in anApolloNextAppProvider(src/lib/apolloProvider.tsx). - SSR-aware caching. Both clients use
NextSSRInMemoryCache; on the server the client link chain is prefixed withSSRMultipartLink({ stripDefer: true })so data fetched during server rendering is handed to the browser cache. - Auth via an Apollo link. A
setContextlink adds theAuthorization: Bearerheader and is concatenated with theHttpLinkthat points athttps://api.github.com/graphql. - Typed, parameterised queries.
GetUserByLogin($login: String!)(src/query/index.ts) fetches a user, 5 followers, 10 organizations and up to 100 repositories ordered byCREATED_AT DESCin a single request. - Next.js platform features.
next/font/google(Figtree and Cabin) exposed as CSS variables for Tailwind,next/imagewith GitHub avatar domains allow-listed innext.config.js, and theMetadataAPI for the page title.
- Next.js 13.4 (App Router), React 18, TypeScript
- Apollo Client 3.8 with
@apollo/experimental-nextjs-app-support, GraphQL - Tailwind CSS 3 (with
prettier-plugin-tailwindcss) - Jest 29 and React Testing Library (smoke tests for the header and footer in
tests/)
Requirements: Node.js 18+ and Yarn, plus a GitHub personal access token with read access to public data.
git clone https://github.com/AaronMullan/github-viewer.git
cd github-viewer
yarn installCreate .env.local with these variables:
GITHUB_ACCESS_TOKEN= # used by the server-side client (home page)
NEXT_PUBLIC_GITHUB_ACCESS_TOKEN= # used by the client-side Apollo provider (user page)Then:
yarn dev # http://localhost:3000
yarn test # Jest, run once
yarn test:watch # Jest in watch mode
yarn build && yarn start