Skip to content

feat(interface): input type cannot inherit an interface type #1254

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Jun 10, 2025

Conversation

scratchmex
Copy link
Member

@scratchmex scratchmex commented Sep 15, 2021

Description

@strawberry.interface
    class SomeInterface:
        some_arg: str

@strawberry.input
class SomeInput(SomeInterface):  # this should throw an error
    another_arg: str

raises the exception InvalidSuperclassInterface:

InvalidSuperclassInterface("An Input class 'SomeInput' cannot inherit from an Interface(s) 'SomeInterface'")

also works when inheriting from multiple interfaces:

InvalidSuperclassInterface("An Input class 'SomeInput' cannot inherit from an Interface(s) 'SomeInterface, SomeOtherInterface'")

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).

@codecov
Copy link

codecov bot commented Sep 15, 2021

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 95.06%. Comparing base (279a31d) to head (b76a380).
Report is 4 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1254      +/-   ##
==========================================
+ Coverage   95.04%   95.06%   +0.01%     
==========================================
  Files         514      515       +1     
  Lines       33539    33583      +44     
  Branches     1735     1736       +1     
==========================================
+ Hits        31878    31924      +46     
+ Misses       1379     1377       -2     
  Partials      282      282              
🚀 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.

@botberry
Copy link
Member

botberry commented Sep 15, 2021

Thanks for adding the RELEASE.md file!

Here's a preview of the changelog:


Starting with this release, Strawberry will throw an error if one of your input
types tries to inherit from one or more interfaces. This new error enforces the
GraphQL specification that input types cannot implement interfaces.

The following code, for example, will now throw an error:

import strawberry


@strawberry.interface
class SomeInterface:
    some_field: str


@strawberry.input
class SomeInput(SomeInterface):
    another_field: int

Here's the tweet text:

🆕 Release (next) is out! Thanks to Ivan Gonzalez for the PR 👏

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

@patrick91
Copy link
Member

Hi @scratchmex would you be able to rebase this PR and address the comments made by Bryce? 😊 no worries if not I can't take a look at some point in future :)

@DoctorJohn DoctorJohn force-pushed the iss/1236 branch 2 times, most recently from 52822f6 to f566442 Compare June 10, 2025 13:16
Copy link

codspeed-hq bot commented Jun 10, 2025

CodSpeed Performance Report

Merging #1254 will not alter performance

Comparing scratchmex:iss/1236 (b76a380) with main (d999936)

Summary

✅ 21 untouched benchmarks

@DoctorJohn
Copy link
Member

@patrick91 I rebased this PR, addressed all feedback, and turned the exception into a StrawberryException.

@DoctorJohn DoctorJohn requested a review from patrick91 June 10, 2025 14:15
Copy link
Member

@patrick91 patrick91 left a comment

Choose a reason for hiding this comment

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

Awesome! Thank you @DoctorJohn! <3

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

Added validation to prevent GraphQL input types from inheriting interface types, aligning with GraphQL specification constraints.

  • Added new InvalidSuperclassInterfaceError in strawberry/exceptions/invalid_superclass_interface.py for proper error handling
  • Implemented validation in strawberry/types/object_type.py to catch interface inheritance attempts by input types
  • Added comprehensive error documentation in docs/errors/invalid-superclass-interface.md with clear examples
  • Added test cases in tests/schema/test_input.py to verify error handling for both single and multiple interface inheritance

6 files reviewed, 2 comments
Edit PR Review Bot Settings | Greptile

Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
@patrick91 patrick91 merged commit fae9c2d into strawberry-graphql:main Jun 10, 2025
102 of 103 checks passed
@github-project-automation github-project-automation bot moved this from In progress to Done in Strawberry Monthly Work Jun 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

Successfully merging this pull request may close these issues.

Interfaces should not work with input types
5 participants