Skip to content

chore: Add assert message #406

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

Closed
wants to merge 2 commits into from
Closed

Conversation

levsa
Copy link

@levsa levsa commented Apr 20, 2023

No description provided.

@codecov
Copy link

codecov bot commented Apr 21, 2023

Codecov Report

Patch coverage: 100.00% and no project coverage change.

Comparison is base (8e1c6f1) 100.00% compared to head (148329d) 100.00%.

Additional details and impacted files
@@            Coverage Diff            @@
##            master      #406   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           27        27           
  Lines         2384      2385    +1     
=========================================
+ Hits          2384      2385    +1     
Impacted Files Coverage Δ
gql/dsl.py 100.00% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@leszekhanusz
Copy link
Collaborator

Could you please give an explanation why you think that message in the assert is necessary?
In which case does the assert fails, do you have a small example?

@levsa
Copy link
Author

levsa commented Apr 25, 2023

Could you please give an explanation why you think that message in the assert is necessary? In which case does the assert fails, do you have a small example?

It helped me find which of the types I had added that caused the assertion to fail, and locate the problem. Here is a simple example:

import graphql
from gql.dsl import DSLSchema


schema_str = """
type FloatValue {
    floatValue: Float!
}

type IntValue {
    intValue: Int!
}

union Value = FloatValue | IntValue

type Entry {
    name: String!
    value: Value
}

type Query {
    values: [Entry!]!
}
"""

schema = graphql.build_ast_schema(graphql.parse(schema_str))
ds = DSLSchema(schema)
print(ds.Value)

Here, it is obvious that Value is accessed in ds, but when we have more complex code that accesses types in more automatic ways, it is hard to find the type that caused the assertion fail. Especially if I'm new to GraphQL and maybe don't know that a union is causing the failure.

@leszekhanusz
Copy link
Collaborator

Thanks for your PR.
I think that it's best to change that assert into an AttributeError.
See the PR #409

The error now should be more clear:

Traceback (most recent call last):
  File "test.py", line 28, in <module>
    print(ds.Value)
  File "/mnt/tera/git-repos/leszekhanusz/gql/gql/dsl.py", line 299, in __getattr__
    raise AttributeError(
AttributeError: Type "Value (<GraphQLUnionType 'Value'>)" is not valid as an attribute of DSLSchema. Only Object types or Interface types are accepted.

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.

2 participants