This project is meant to extract all the GraphQL operations from a relay project and clean them so that a client can be generated
Extract operations from a source folder to an output directory. Optionally provide a schema (SDL or introspection JSON) and exclude subscriptions.
npx @stackworx/relay-extractor \
--src ./src \
--out ./out \
--schema ./schema.graphql \
--exclude-subscriptions--exclude-subscriptions: When set, subscription operations are skipped and not written to the output.
- Remove Relay Compiler Directives
- Remove Relay Interla fields (
__id) - Handle missing arguments that relay handles with
argumentDefinitions
-
Background: When running Vitest with GraphQL-related tooling, you may see errors like: "Cannot use GraphQLSchema ... from another module or realm" due to how module resolution handles
graphqlsubpath imports. -
Fix: Add aliases so Vitest resolves the ESM entry points consistently. This is configured in
vitest.config.ts:import { defineConfig } from 'vitest/config' export default defineConfig({ resolve: { alias: { 'graphql/language/printer': 'graphql/language/printer.js', 'graphql/language': 'graphql/language/index.js', graphql: 'graphql/index.js', }, }, })
-
Reference: vitest-dev/vitest#4605 (comment)
-
Run tests:
npm run test -- --run