Skip to content
This repository was archived by the owner on Nov 10, 2026. It is now read-only.

feat!: apply rules with mapSchema instead of graphql-middleware - #5

Closed
letterix wants to merge 1 commit into
masterfrom
feat/drop-graphql-middleware
Closed

letterix wants to merge 1 commit into
masterfrom
feat/drop-graphql-middleware

Conversation

@letterix

Copy link
Copy Markdown

graphql-middleware 6.1.35 has been unmaintained since 2023 and pins @graphql-tools/utils 8.9.0, which Dependency Track flags as High (GHSA-7mx3-vvmw-hjmv) in every sb-backend-monorepo image. This fork was the only reason it stayed in the tree.

Change

shield(rules, options) now returns (schema) => schema. It validates the rule tree against the schema (same error messages as before), then runs mapSchema from @graphql-tools/utils and wraps every object field's resolver (or defaultFieldResolver) with its rule. applyMiddleware did the same thing through addResolversToSchema, and the rule-evaluation body is unchanged.

Rule precedence is unchanged: field rule, then the type's * wildcard, then the type rule or the schema rule, then fallbackRule.

Breaking (2.0.0)

  • applyMiddleware(schema, permissions) becomes permissions(schema).
  • graphql-middleware is no longer a peer dependency. @graphql-tools/utils@^13.2.0 is now a dependency.
  • Rule fragment options and extractFragment/extractFragments are removed. Only graphql-middleware's fragment replacements used them, and sb-backend-monorepo uses none.
  • Fields with only a subscribe resolver are no longer wrapped. We have no GraphQL subscriptions.

Testing

  • The existing suite runs against permissions(schema): 58 tests, plus a new test that fields without a resolver are guarded and the input schema is left untouched. fragments.test.ts is deleted along with the feature.
  • I swapped the built dist into sb-backend-monorepo's node_modules with graphql-middleware removed. @soundboks/server passes 350 tests, including new allow and federation _entities tests, and typecheck and tests pass for all six apps.

The tests/__snapshots__ obsolete entry predates this PR (it was left over from the vitest migration).

🤖 Generated with Claude Code

graphql-middleware has been unmaintained since 2023 and pins
@graphql-tools/utils 8.9.0 (GHSA-7mx3-vvmw-hjmv). shield() now returns a
function that maps the schema and wraps each object field resolver with
its rule, which is what applyMiddleware did through addResolversToSchema.

BREAKING CHANGE: shield(rules, options) returns (schema) => schema; call it
instead of applyMiddleware(schema, permissions). graphql-middleware is no
longer a peer dependency. Rule `fragment` options and
extractFragment/extractFragments are removed, since only graphql-middleware
applied them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@letterix

Copy link
Copy Markdown
Author

Superseded by SOUNDBOKS/sb-backend-monorepo#558: graphql-shield moves into the monorepo as packages/graphql-shield. This repo will be archived once 2.0.1 is published from there.

@letterix letterix closed this Nov 10, 2026
@letterix
letterix deleted the feat/drop-graphql-middleware branch November 10, 2026 14:08
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant