Summary
When extracting shared GQL schemas into standalone packages (e.g. @saga-ed/coach-gql-schema in Coach PR #34), consumers currently reference .gql files via filesystem glob patterns into node_modules:
GQL_SERVER_SCHEMAPATTERNS=node_modules/@saga-ed/coach-gql-schema/schemas/**/*.gql
This works but couples consumers to the internal directory structure of the schema package and to node_modules layout. Two changes in the SOA infrastructure would allow a cleaner contract.
Proposed Changes
1. Subpath exports for schema files
Schema packages should expose .gql files via the exports map using a subpath pattern:
This formalizes the contract — consumers reference @saga-ed/coach-gql-schema/schemas/cns.gql rather than reaching into node_modules internals.
2. GQLServer accepts typeDefs string/DocumentNode directly
Schema packages already produce a merged schema.graphql via codegen. If the package exports this as a typeDefs string:
// in the schema package's src/index.ts
import { readFileSync } from 'node:fs';
export const typeDefs = readFileSync(
new URL('../generated/schema.graphql', import.meta.url),
'utf-8'
);
Then consumers can do:
import { typeDefs } from '@saga-ed/coach-gql-schema';
// pass typeDefs directly to GQLServer — no glob needed
This eliminates GQL_SERVER_SCHEMAPATTERNS entirely for that consumer. GQLServer would need to accept a schema string (or DocumentNode) in addition to its current glob-based input.
Prototype Plan
Prototype both changes in the SOA gql-api example app before applying to Coach:
- Add
"./schemas/*" to the example schema package's exports map
- Export the merged schema as a
typeDefs string from the package entry point
- Update
GQLServer to accept typeDefs as an alternative to glob patterns
- Validate the example app works with both approaches
Context
- Coach PR: saga-ed/coach#34 (shared GQL schema extraction)
- Review notes:
claude/projects/gql-schema-refactor/research/pr-34-review.md
🤖 Generated with Claude Code
Summary
When extracting shared GQL schemas into standalone packages (e.g.
@saga-ed/coach-gql-schemain Coach PR #34), consumers currently reference.gqlfiles via filesystem glob patterns intonode_modules:This works but couples consumers to the internal directory structure of the schema package and to
node_moduleslayout. Two changes in the SOA infrastructure would allow a cleaner contract.Proposed Changes
1. Subpath exports for schema files
Schema packages should expose
.gqlfiles via theexportsmap using a subpath pattern:This formalizes the contract — consumers reference
@saga-ed/coach-gql-schema/schemas/cns.gqlrather than reaching intonode_modulesinternals.2. GQLServer accepts typeDefs string/DocumentNode directly
Schema packages already produce a merged
schema.graphqlvia codegen. If the package exports this as atypeDefsstring:Then consumers can do:
This eliminates
GQL_SERVER_SCHEMAPATTERNSentirely for that consumer.GQLServerwould need to accept a schema string (orDocumentNode) in addition to its current glob-based input.Prototype Plan
Prototype both changes in the SOA
gql-apiexample app before applying to Coach:"./schemas/*"to the example schema package's exports maptypeDefsstring from the package entry pointGQLServerto accepttypeDefsas an alternative to glob patternsContext
claude/projects/gql-schema-refactor/research/pr-34-review.md🤖 Generated with Claude Code