graphql-python / graphql-python/graphene-django

assert django models in graphene.Field argument

Open
#1,085 0 comments 0 reactions 0 assignees View on GitHub
✨enhancement
Dominant language
Python
Stars
4.4k
Forks
760
PR merge metrics
No merged PRs in 30d

Description

**Is your feature request related to a problem? Please describe.**

So, typical way to use graphene-django is:
```
class ModelNameType(DjangoObjectType):
class Meta:
model = ModelName

class Querry(graphene.ObjectType):
model_name = graphene.Field(ModelNameType)
```
But, its very simple error, when you writing ModelName instead of ModelNameType in graphene.Field arguments. But its create error like this:
```
scary gigant call stack from libaries
ImportError: Could not import 'schema' for Graphene setting 'SCHEMA'. AttributeError: type object 'ModelName ' has no attribute 'name'.
```
And, after readig this error, you dont thing that it is a typo. You probably think that its problem in your model structure, bug in django filters, or something else.

**Describe the solution you'd like**
So, we can add assertions, like this
```
assert base_type(type) != models.base.ModelBase, \
f"you probably typo in {type.__name__}, try change to {type.__name__}Type"
```
and error message will be looks like
```
File "your_app\schema.py", line 100, in Querry
ModelName = graphene.Field(ModelName)
File "\venv\lib\site-packages\graphene\types\field.py", line 78, in __init__
f"you probably typo in {type.__name__}, try change to {type.__name__}Type"
AssertionError: you probably typo in ModelName, try change to ModelNameType
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.