# @packages/data-context

Centralized GraphQL data layer for the Cypress application. It implements a Nexus schema (code-first GraphQL) that is the single source of truth for all application state — project configuration, Cloud data, file system events, browser list, and user actions — consumed by both `app` and `launchpad` via urql.

## Key Commands

```bash
# NOTE: Full suite is slow (hundreds of tests); always target a specific file or grep pattern

# Run a specific test file
yarn workspace @packages/data-context test -- <path-to-spec>

# Run tests matching a path pattern
yarn workspace @packages/data-context test -- --testPathPattern="<pattern>"

# Build: generate GraphQL schema + Nexus types
yarn workspace @packages/data-context build

# Rebuild only the GraphQL codegen (fragment/query types)
yarn workspace @packages/data-context build:graphql

# Type-check
yarn workspace @packages/data-context check-ts
```

## Architecture

```
src/
  actions/    Mutation handlers (one file per domain: ProjectActions, AuthActions, etc.)
  codegen/    Code generation helpers for scaffolding config and test files
  data/       Data sources that wrap filesystem, Cloud API, and process state
  gen/        Auto-generated Nexus type output (nxs.gen.ts) — do not edit by hand
  polling/    Long-poll helpers for Cloud data (runs, recordings)
  sources/    GraphQL query resolvers grouped by domain
  util/       Shared utilities (error formatting, file helpers, etc.)
  DataContext.ts   Root class that wires together all actions and sources
  DataActions.ts   Aggregate of all action classes
graphql/
  graphql-codegen.yml   Codegen config (generates fragment/query types for consumers)
schemas/               JSON schema definitions
```

## Gotchas / Notes

- `src/gen/nxs.gen.ts` is auto-generated by `yarn nexus-build`. Never edit it manually; re-run `yarn workspace @packages/data-context build` to regenerate after schema changes.
- Tests run with `--experimental-vm-modules` because the test suite uses Jest with ES module support. The runner is Jest (not vitest) for this package.
- The `browser` field in `package.json` points to `src/index.ts` (source), which allows Vite-based consumers (`app`, `launchpad`, `frontend-shared`) to import TypeScript directly without a pre-build step.
- The GraphQL schema is built in two phases: (1) `build:schema` emits a JSON SDL, (2) `build:graphql` runs graphql-codegen against it for downstream consumers.

## Integration Points

- Consumed by **@packages/app**, **@packages/launchpad**, and **@packages/frontend-shared** as the GraphQL backend.
- Depends on **@packages/config** for configuration option resolution.
- Depends on **@packages/scaffold-config** for framework detection during onboarding.
- Depends on **@packages/socket** for real-time subscriptions.
- Depends on **@packages/telemetry** for OpenTelemetry spans around data operations.
