Skip to content

refactor(graphql): Generate initial app types from schema#3911

Draft
effigies wants to merge 17 commits intoOpenNeuroOrg:masterfrom
effigies:build/graphql-codegen
Draft

refactor(graphql): Generate initial app types from schema#3911
effigies wants to merge 17 commits intoOpenNeuroOrg:masterfrom
effigies:build/graphql-codegen

Conversation

@effigies
Copy link
Copy Markdown
Contributor

This PR establishes a process for converting openneuro-app types from hand-written to generated. It:

  1. Creates a code generation script. I had wanted to do this as a single script that imports from the server and outputs to the types, but pnp errors made me compromise by using the existing script and just gitignore-ing the intermediate file.
  2. Replaces user-types.ts in 3626bd8. This seemed the simplest and was a decent proof of concept.
  3. Replaces dataset-events.ts in d58bcd3. This is a slightly more complex set of types.

If we're happy with this, I would suggest making further changes in a separate PR to keep the infrastructure changes separated from the majority of the mostly-mechanical type changes.

I will not have time to work on this further until after this coming week. Feel free to examine or ignore.

Builds on #3910, so those changes are duplicated here.

effigies added 15 commits April 24, 2026 13:42
Add a minimal `dump-schema` yarn script to the monorepo.
Two-step pipeline: dump-schema writes SDL, then graphql-codegen
generates TypedDocumentNode types for openneuro-app.

- codegen.ts at repo root with client-preset, fragment masking off
- codegen and codegen:check scripts in root package.json
- @graphql-typed-document-node/core added to openneuro-app deps
- Several document sources excluded due to duplicate operation names
  and type mismatches (to be resolved in subsequent tasks)
Replace gql tagged templates with graphql() from the generated helper.
Fix $links type mismatch ([String] -> [String!]) to match schema.
Rename advancedSearchDatasets to UserAdvancedSearchDatasets to resolve
duplicate operation name with use-search-results.tsx.
Re-include user.ts in codegen document scanning.

Downstream consumer type errors (user-datasets-view.tsx, user-query.tsx,
etc.) are expected and will be resolved in subsequent tasks.
Replace hand-written User and Dataset types from user-types.ts with
generated types from graphql-codegen in all consumer files.

- User type derived as NonNullable<UserQuery["user"]>
- Dataset type derived from UserAdvancedSearchDatasetsQuery edge nodes
- Component prop interfaces (UserRoutesProps, UserCardProps, etc.)
  relocated to their consuming component files
- OutletContextType moved to user-routes.tsx
- SearchInput replaced with DatasetSearchInput, string sort values
  replaced with SearchSortOption enum
- Admin pages extend User type with `modified` field (not in GET_USER
  query, pending GET_USERS migration to codegen)
- SearchResultsCitation uses minimal CitationDataset interface to
  accept datasets from multiple query sources
- NotificationHeader uses minimal User interface compatible with both
  generated and hand-written User types (event-types.ts bridge)
- user-notifications-context.tsx casts generated notifications to
  Event type for mapRawEventToMappedNotification (Task 6 bridge)
- Test fixtures updated with required `created` field and enum values
- GitHubAuthButton.sync prop widened to accept string | Date | null

No file except event-types.ts now imports from user-types.ts.
All GraphQL-derived types now come from codegen output.
Component prop interfaces relocated to their consuming components.
event-types.ts updated to import User from generated types.
Replace gql tagged templates with graphql() from generated helper.
Fix duplicate operation name: rename second SaveAdminNote to
UpdateAdminNote. Re-include datasetEvents.ts in codegen document
scanning and regenerate types.
Replace all imports from types/event-types.ts with generated types from
graphql-codegen. Non-GraphQL exports (MappedNotification, formatStatusForDisplay,
mapRawEventToMappedNotification) are relocated to a new notification-mapper.ts
module in the notifications directory.

- Use ResponseStatusType enum instead of string literal unions for
  mutation variables (processContributorRequest, processContributorCitation)
- Use NotificationStatusType for updateEventStatus/updateNotificationStatus
- Derive DatasetEvent and Notification types from generated query results
- Remove invalid 'reason' param from processContributorCitation call
  (the mutation schema does not accept it)
- Zero files now import from event-types.ts
All GraphQL-derived types now come from codegen output.
UI mapping functions relocated to notifications/notification-mapper.ts.
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 25, 2026

Codecov Report

❌ Patch coverage is 54.67033% with 165 lines in your changes missing coverage. Please review.
✅ Project coverage is 53.61%. Comparing base (9a03fe8) to head (464c6ce).

Files with missing lines Patch % Lines
codegen.ts 2.85% 34 Missing ⚠️
...scripts/users/notifications/notification-mapper.ts 0.00% 24 Missing ⚠️
packages/openneuro-server/src/datalad/snapshots.ts 23.52% 13 Missing ⚠️
...openneuro-server/src/libs/authentication/crypto.ts 7.69% 12 Missing ⚠️
...sers/notifications/user-notification-accordion.tsx 0.00% 10 Missing ⚠️
packages/openneuro-server/src/datalad/files.ts 37.50% 10 Missing ⚠️
...enneuro-server/src/elasticsearch/elastic-client.ts 27.27% 8 Missing ⚠️
.../scripts/dataset/components/dataset-event-item.tsx 12.50% 7 Missing ⚠️
packages/openneuro-server/src/datalad/draft.ts 14.28% 6 Missing ⚠️
...nneuro-server/src/elasticsearch/reindex-dataset.ts 25.00% 6 Missing ⚠️
... and 14 more
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3911      +/-   ##
==========================================
+ Coverage   48.87%   53.61%   +4.74%     
==========================================
  Files         680      685       +5     
  Lines       37665    41737    +4072     
  Branches     1867     1881      +14     
==========================================
+ Hits        18408    22378    +3970     
- Misses      19098    19200     +102     
  Partials      159      159              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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