Skip to content

Migrate newsfeed example to TypeScript with Grats and Vite - #345

Closed
captbaritone wants to merge 4 commits into
relayjs:mainfrom
captbaritone:todo-upgrade
Closed

Migrate newsfeed example to TypeScript with Grats and Vite#345
captbaritone wants to merge 4 commits into
relayjs:mainfrom
captbaritone:todo-upgrade

Conversation

@captbaritone

Copy link
Copy Markdown
Contributor

Summary

  • Webpack + Babel → Vite: Modern dev server with HMR, faster builds
  • Raw http + hand-written graphql-js → GraphQL Yoga + Grats: Code-first GraphQL using @gqlType, @gqlField annotations — TypeScript types are the source of truth for the schema
  • graphql v17-alpha → v16 stable: Stable GraphQL dependency
  • React 18 → React 19: Updated to latest React
  • TypeScript 4.9 → 5.7: Modern TypeScript with strict mode
  • ESLint flat config (v9): Modern linting with typescript-eslint
  • Removed DefinitelyTyped Relay shims: Relay v21 canary ships its own TypeScript types
  • Removed custom GraphiQL playground: GraphQL Yoga includes a built-in GraphiQL at /graphql
  • Removed future/ directory: Broken tutorial stubs with unresolvable imports
  • Added CI steps: yarn ci runs grats, relay, tsc, lint, and vite build

The server-side code is restructured into data/models/ (Grats-annotated types) and data/graphql/ (node/actor interfaces and connection helpers). The schema is generated from TypeScript annotations via yarn grats, and schema.graphql is checked into the repo as a generated artifact.

Test plan

  • cd newsfeed && yarn to install dependencies
  • yarn grats generates schema.graphql + schema.ts without errors
  • yarn relay generates Relay artifacts without errors
  • yarn tsc passes TypeScript type checking
  • yarn lint passes ESLint
  • yarn dev starts the dev server and the app works at http://localhost:5173
  • yarn ci passes the full CI pipeline
  • Stories display with titles, summaries, images, and poster bylines
  • Like button and comments section render correctly

Modernize the newsfeed example app:
- Webpack + Babel → Vite
- Raw http server + hand-written graphql-js → GraphQL Yoga + Grats
- graphql v17-alpha → v16 stable
- React 18 → React 19
- TypeScript 4.9 → 5.7
- ESLint legacy config → flat config (v9)
- Remove DefinitelyTyped Relay shims (v21 ships its own types)
- Remove GraphiQL custom playground (Yoga has built-in)
- Remove future/ directory (broken tutorial stubs)
- Remove committed dist/ artifacts
- Add CI steps for newsfeed
@meta-cla meta-cla Bot added the CLA Signed label May 22, 2026
Without a lockfile, yarn resolves ^0.0.0-main-4dcb3ffa to the stable
v21 release which doesn't ship TypeScript types. Pin the exact version.
Replace @killsParentOnException with @semanticNonNull for non-spec
fields by enabling Grats' strictSemanticNullability. Spec-required
non-null fields (Node.id, PageInfo.hasNextPage/hasPreviousPage,
Edge.cursor, Connection.pageInfo) keep @killsParentOnException.

On the client side, add @throwOnFieldError to all queries and fragments
so Relay generates non-null types for @semanticNonNull fields, and
@catch on mutations since @throwOnFieldError doesn't support mutation
definitions.

Add per-todo ErrorBoundary so field errors only take down the affected
todo item rather than the entire app.
The class itself is the model — the private property holds the raw
database row. Also removes redundant explicit type parameter on
useFragment in StoryLikeButton.
@captbaritone

Copy link
Copy Markdown
Contributor Author

Closing — the newsfeed example is part of a step-by-step tutorial guide, so migrating it would break the tutorial flow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant