Skip to content

fix: support custom directive definitions in schema codegen (option 1, ignoring)#4090

Draft
magicmark wants to merge 1 commit intostrawberry-graphql:mainfrom
magicmark:fix_schema_codegen_directive
Draft

fix: support custom directive definitions in schema codegen (option 1, ignoring)#4090
magicmark wants to merge 1 commit intostrawberry-graphql:mainfrom
magicmark:fix_schema_codegen_directive

Conversation

@magicmark
Copy link
Copy Markdown
Contributor

@magicmark magicmark commented Jan 7, 2026

Description

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

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

🤖 Generated with Claude Code

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

Support custom directive definitions in schema code generation and clarify errors for unsupported GraphQL definition types.

Bug Fixes:

  • Handle custom directive definitions in schema codegen without raising errors by skipping them during generation.
  • Improve the NotImplementedError message for unknown GraphQL definition types to include the actual type name.

Documentation:

  • Add release notes documenting the schema codegen fix for custom directives and the improved unknown definition error message.

Tests:

  • Extend schema codegen CLI tests to cover schemas that define and use custom directives.

Previously, schemas containing custom directive definitions would fail with
`NotImplementedError: Unknown definition None`. Now directive definitions
are gracefully skipped since they don't require code generation.

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>
@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai bot commented Jan 7, 2026

Reviewer's Guide

Updates schema code generation to ignore custom directive definitions that don’t require codegen and improves error reporting for unsupported GraphQL definition nodes, along with a focused test and release-note update.

File-Level Changes

Change Details Files
Handle custom directive definitions during schema code generation instead of crashing.
  • Extend the main codegen loop to detect DirectiveDefinitionNode instances and skip them because they don’t need generated code.
  • Preserve existing handling of federation link directives while inserting the new directive-definition branch before the generic fallback path.
strawberry/schema_codegen/__init__.py
Improve diagnostics for unsupported GraphQL definition node types.
  • Replace the NotImplementedError message to report the concrete GraphQL node class name via type(graphql_definition).name instead of printing the node object, which previously could appear as None.
strawberry/schema_codegen/__init__.py
Ensure schema codegen CLI works with schemas that declare and use custom directives.
  • Update the CLI schema fixture used in tests to declare a custom @foo directive and apply it to a field so codegen runs against a schema with directives.
tests/cli/test_schema_codegen.py
Document the bugfix and behavior change in release notes.
  • Add a patch-level RELEASE.md entry describing support for custom directive definitions in schema codegen and the improved error message for unknown definition types, including a concrete GraphQL schema example.
RELEASE.md

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
Copy Markdown

codecov bot commented Jan 7, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.23%. Comparing base (c8d6ae4) to head (10afc44).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4090   +/-   ##
=======================================
  Coverage   94.22%   94.23%           
=======================================
  Files         541      541           
  Lines       35519    35521    +2     
  Branches     1877     1878    +1     
=======================================
+ Hits        33469    33473    +4     
+ 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.

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq bot commented Jan 7, 2026

CodSpeed Performance Report

Merging this PR will not alter performance

Comparing magicmark:fix_schema_codegen_directive (10afc44) with main (c8d6ae4)

Summary

✅ 31 untouched benchmarks

@magicmark magicmark marked this pull request as ready for review January 8, 2026 16:50
@magicmark magicmark marked this pull request as draft January 8, 2026 16:51
@botberry
Copy link
Copy Markdown
Member

botberry commented Jan 8, 2026

Thanks for adding the RELEASE.md file!

Here's a preview of the changelog:


This release fixes schema codegen to support custom directive definitions. Previously, schemas containing custom directives like @authz would fail with NotImplementedError: Unknown definition None. Now directive definitions are gracefully skipped since they don't require code generation.

directive @authz(resource: String!, action: String!) on FIELD_DEFINITION

type Query {
    hello: String! @authz(resource: "greeting", action: "read")
}

This also fixes the error message for truly unknown definition types to show the actual type name instead of None.

Here's the tweet text:

🆕 Release (next) is out! Thanks to @mark_larah for the PR 👏

Get it here 👉 https://strawberry.rocks/release/(next)

Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@magicmark magicmark changed the title fix: support custom directive definitions in schema codegen fix: support custom directive definitions in schema codegen (option 1, ignoring) Jan 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants