'AssertionError at /graphql/ Query fields must be a mapping (dict / OrderedDict) with field names as keys or a function which returns such a mapping

I am new to django and graphql, I am trying use graphql in django using the the instructions given in this site.

https://docs.graphene-python.org/projects/django/en/latest/installation/

I followed the instructions carefully but when I enter the url http://127.0.0.1:8000/graphql/

I am getting the error following error.

AssertionError at /graphql/
Query fields must be a mapping (dict / OrderedDict) with field names 
as keys or a function which returns such a mapping.

I just have a single app called demo. The code in the models.py of demo app is as follows...

from django.db import models

# Create your models here.
class UserProfile(models.Model):
    userId = models.IntegerField(primary_key=True)
    userName = models.CharField(max_length=15)
    password = models.CharField(max_length=15)
    address = models.CharField(max_length=30)
    phoneNumber = models.IntegerField()

    class Meta:
        db_table = 'UserProfile'

Here are the relevant parts of the settings.py file in the project folder.

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'graphene_django',
    'corsheaders',
    'demo',
]

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'corsheaders.middleware.CorsMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

CORS_ORIGIN_ALLOW_ALL = True

GRAPHENE = {
    'SCHEMA': 'abc.schema.schema'
}

abc is the name of the main project folder which contains manage.py.

Here is the urls.py file

from django.contrib import admin
from django.urls import path
from graphene_django.views import GraphQLView

urlpatterns = [
        path('admin/', admin.site.urls),
        path('graphql/', GraphQLView.as_view(graphiql=True)),
    ]

Please help,thanks in advance.



Solution 1:[1]

My problem was solved by inserting DjangoObjectType instead of ObjectType in schema.py you can import it: from graphene_django.types import DjangoObjectType

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Mohammadreza Taheri