Skip to content

Repository files navigation

Read Me

CInpm version

This project is meant to extract all the GraphQL operations from a relay project and clean them so that a client can be generated

CLI Usage

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 \
extract \
--src ./src \
--out ./out \
--schema ./schema.graphql \
--exclude-subscriptions
  • --exclude-subscriptions: When set, subscription operations are skipped and not written to the output.

Annotate your schema SDL to mark unused fields (based on operations found in source files).

npx @stackworx/relay-extractor \
annotate-unused \
--src ./src \
--schema ./schema.graphql

By default this overwrites the file passed to --schema. To write somewhere else (or to stdout):

# Write to a different file
npx @stackworx/relay-extractor annotate-unused --src ./src --schema ./schema.graphql --out ./schema.annotated.graphql
# Print to stdout
npx @stackworx/relay-extractor annotate-unused --src ./src --schema ./schema.graphql --out -
  • Default annotation mode is @deprecated(reason: "relay-extractor: unused").
  • Use --mode directive --directive-name unused to apply a custom directive instead.

Issues

  • Remove Relay Compiler Directives
  • Remove Relay Interla fields (__id)
  • Handle missing arguments that relay handles with argumentDefinitions

Testing: Vitest + GraphQL fix

  • 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 graphql subpath imports.

  • Fix: Add aliases so Vitest resolves the ESM entry points consistently. This is configured in vitest.config.ts:

    import{defineConfig}from'vitest/config'exportdefaultdefineConfig({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

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages