Skip to content

Conversation

@magicmark
Copy link
Contributor

@magicmark magicmark commented Jan 9, 2026

Previously, schemas containing custom directive definitions would fail with NotImplementedError: Unknown definition None. Now directive definitions are generated.

Also fixes the error message for unknown definitions to show the actual type name instead of None.

Description

Types of Changes

  • Core
  • Bugfix
  • New feature
  • Enhancement/optimization
  • Documentation

Issues Fixed or Closed by This PR

Checklist

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • I have tested the changes and verified that they work and don't break anything (as well as I can manage).

Summary by Sourcery

Generate schema code for custom directive definitions and improve error reporting for unsupported GraphQL definition types.

New Features:

  • Support code generation of Strawberry schema directive stub classes from custom directive definitions in GraphQL schemas.

Bug Fixes:

  • Prevent schema codegen from failing with NotImplementedError when encountering directive definitions by handling DirectiveDefinitionNode explicitly.
  • Improve the NotImplementedError message for unknown schema definition types to show the actual GraphQL node type name.

Documentation:

  • Add release notes describing custom directive schema codegen support and the improved error message behavior.

Tests:

  • Extend schema codegen CLI tests to cover generation of directive stubs with arguments and locations.

@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Jan 9, 2026

Reviewer's Guide

Adds support for generating Python stub classes for custom GraphQL directive definitions in schema codegen, updates tests and release notes, and improves the error message when encountering unknown definition types during code generation.

File-Level Changes

Change Details Files
Generate stub Strawberry schema directive classes for GraphQL directive definitions during schema codegen.
  • Introduce _get_directive_definition to map DirectiveDefinitionNode into a Definition containing a decorated ClassDef for the directive
  • Build @strawberry.schema_directive decorator with locations and description arguments derived from the directive definition
  • Generate class fields from directive arguments, including type annotations, or a pass statement when there are no arguments
  • Automatically import Location from strawberry.schema_directive when directives are present
strawberry/schema_codegen/__init__.py
Wire directive definition handling into the main codegen dispatch and improve the unknown-definition error message.
  • Extend codegen to recognize DirectiveDefinitionNode and delegate to _get_directive_definition
  • Change NotImplementedError message to use the actual GraphQL definition type name via type(graphql_definition).__name__
strawberry/schema_codegen/__init__.py
Add regression test and release notes for directive schema codegen support.
  • Extend CLI schema codegen test schema to include a custom @authz directive and adjust the expected generated output to include the directive stub class and import
  • Document the new behavior and example generated code, plus the improved error message, in RELEASE.md
tests/cli/test_schema_codegen.py
RELEASE.md

Possibly linked issues

  • #: PR implements the issue’s “Add support for custom schema directives” task in schema codegen, partially fulfilling the issue.

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@codecov
Copy link

codecov bot commented Jan 9, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.24%. Comparing base (c8d6ae4) to head (13c94f4).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4093      +/-   ##
==========================================
+ Coverage   94.22%   94.24%   +0.01%     
==========================================
  Files         541      542       +1     
  Lines       35519    35563      +44     
  Branches     1877     1882       +5     
==========================================
+ Hits        33469    33515      +46     
+ Misses       1739     1737       -2     
  Partials      311      311              
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@magicmark magicmark force-pushed the generate_directives branch from f58816e to b7024c9 Compare January 9, 2026 20:29
@codspeed-hq
Copy link

codspeed-hq bot commented Jan 9, 2026

Merging this PR will not alter performance

✅ 31 untouched benchmarks


Comparing magicmark:generate_directives (13c94f4) with main (c8d6ae4)

Open in CodSpeed

@magicmark magicmark force-pushed the generate_directives branch from b7024c9 to b31db07 Compare January 9, 2026 21:54
Previously, schemas containing custom directive definitions would fail with
`NotImplementedError: Unknown definition None`. Now directive definitions
are generated with stub implementations.

Also fixes the error message for unknown definitions to show the actual
type name instead of `None`.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@magicmark magicmark force-pushed the generate_directives branch from b31db07 to 13c94f4 Compare January 9, 2026 22:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant