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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

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

Merging #1254 (1c74740) into main (a97c96f) will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##             main    #1254   +/-   ##
=======================================
  Coverage   97.69%   97.70%           
=======================================
  Files          88       88           
  Lines        3388     3396    +8     
  Branches      498      500    +2     
=======================================
+ Hits         3310     3318    +8     
  Misses         43       43           
  Partials       35       35           

@botberry
Copy link
Member

botberry commented Sep 15, 2021

Hi, thanks for contributing to Strawberry 🍓!

We noticed that this PR is missing a RELEASE.md file. We use that to automatically do releases here on GitHub and, most importantly, to PyPI!

So as soon as this PR is merged, a release will be made 🚀.

Here's an example of RELEASE.md:

Release type: patch

Description of the changes, ideally with some examples, if adding a new feature.

Release type can be one of patch, minor or major. We use semver, so make sure to pick the appropriate type. If in doubt feel free to ask :)

Here's the tweet text:

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

Get it here 👉 https://github.com/strawberry-graphql/strawberry/releases/tag/(next)

@@ -161,3 +162,27 @@ def anime(self) -> Anime:

assert not result.errors
assert result.data == {"anime": {"name": "One Piece"}}


def test_input_cannot_inherit_from_interface():
Copy link
Member

Choose a reason for hiding this comment

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

Can these tests cover the actual messages of the errors as well?

Copy link
Member Author

Choose a reason for hiding this comment

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

Do yo know how to catch the exception message with pytest? Or I need to try, catch, save, raise, assert?

Copy link
Member

Choose a reason for hiding this comment

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

You can use

with pytest.raises(ExceptionType) as exc:
    ...
assert exc.value == "something"

Copy link
Member

Choose a reason for hiding this comment

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

Also, note that pytest.raises takes a match argument that may be enough here

Copy link
Member Author

Choose a reason for hiding this comment

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

Let me have a look, thanks



class InvalidSuperclassInterface(Exception):
def __init__(self, input_name: str, interface_names=List[str]):
Copy link
Member

@BryceBeagle BryceBeagle Sep 17, 2021

Choose a reason for hiding this comment

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

Actually, now that I think about it, wouldn't it be better to take a type and List[type] instead? Let the Exception handle everything related to output?

Copy link
Member Author

Choose a reason for hiding this comment

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

You are right

@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 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: In progress
Development

Successfully merging this pull request may close these issues.

Interfaces should not work with input types
4 participants