当前位置: 首页 > 知识库问答 >
问题:

需要向图形QL视图提供一个架构

凤棋
2023-03-14

我正在按照本教程将 Graphql 与 Django 集成,当我在本地机器上点击 graphql URL 时,我根据该教程执行了所有操作

http://localhost:8000/graphql

我得到以下错误

断言错误在 /graphql

需要向GraphQLView提供架构。

请求方法:GET请求URL:http://localhost:8000/graphqlDjango版本:1.11.1异常类型:断言错误异常值:
需要向GraphQLView提供架构。异常位置:/home/psingh/Projects/django_graphql/env/local/lib/python2.7/site-packages/graphene_django/views。初始化中的py,第84行Python可执行文件:/home/psingh/Projects/django_graphql/env/bin/Python-Python版本:2.7.6 Python-Pathon路径:
['/home/psingh/Projects/django_graphql/Projects','/home/psingh/Products/djang o_graph ql/env/lib/python2.7','-home/psingh/Projects/djang o_ graph ql/env/lib/python2.7/plat-x86_64-linux-gnu','/home/psingh/Projects/djiang o_graphql/env/lib/python2.7/lib-tk','/home/psingh/Projects/psingh/Projects/djang o graph ql/env/lib/python2.7/lib old','/home/psingh/Projects/django_graphql/env/lib/python2.7/lib-dynload','/usr/lib/python2.7','/usr/lib/python2.7/plat-x86_64-linux-gnu','-usr/lib/python2.7/lib-tk','/home/psingh/Projects/django_graphql/env/local/lib/python27/site packages','-home/psingh/Projects/django.graphql/env/lib/ppython2.7/site packes']服务器时间:2017年5月12日星期五12:18:31 0000

在settings.py中

GRAPHENE = {
'SCHEMA': 'project.schema.schema'

}

项目

import graphene
import mainapp.schema 
class Query(mainapp.schema.Query, graphene.ObjectType):
  # This class will inherit from multiple Queries
  # as we begin to add more apps to our project
  pass

schema = graphene.Schema(query=Query)

应用程序

import graphene
from graphene_django.types import DjangoObjectType
from cookbook.ingredients.models import Category, Ingredient

class CategoryType(DjangoObjectType):
  class Meta:
     model = Category


 class IngredientType(DjangoObjectType):
   class Meta:
      model = Ingredient


 class Query(graphene.AbstractType):
   all_categories = graphene.List(CategoryType)
   all_ingredients = graphene.List(IngredientType)

   def resolve_all_categories(self, args, context, info):
     return Category.objects.all()

  def resolve_all_ingredients(self, args, context, info):
     # We can easily optimize query count in the resolve method
     return Ingredient.objects.select_related('category').all()

project_urls.py

from django.conf.urls import include, url
from django.contrib import admin

from graphene_django.views import GraphQLView
import schema

urlpatterns = [
   url(r'^admin/', admin.site.urls),
   url(r'^graphql', GraphQLView.as_view(graphiql=True)),
   url(r'^', include('mainapp.urls')),    

]

任何帮助都会很好。我不熟悉编码。提前谢谢。

共有3个答案

东门佐
2023-03-14

settings.py文件下的INSTALLED_APPS中是否添加了“graphene_django”?查看这里-https://docs . graphene-python . org/projects/django/en/latest/tutorial-plain/# update-settings

酆君墨
2023-03-14

如果你不想在settings.py中添加GRAPHENE变量,那么你可以在中传递方案参数GraphQLView.as_view()方法调用

   from onlineshop_project.scheme import schema
   urlpatterns = [
       url(r'^admin/', admin.site.urls),
       url(r'^graphql', GraphQLView.as_view(graphiql=True, schema=schema)),
   ]

您可以查看文档。

黄宏大
2023-03-14

您必须将模式添加到< code>settings.py中,如下所示:

GRAPHENE={'Schema':'cookbook.schema.schema'}

您需要2个schema.py文件,一个在项目的根级别,一个在应用程序文件夹中。

 类似资料:
  • 尝试实现reactive graph ql并遇到一些问题。 pom相关性, 架构:- 分解器:- 这里,如果我返回Flux或Mono,得到以下错误。 所以,尝试作为列表返回。 但是使用阻塞调用将Flux转换为List也会抛出错误, 这里,得到下面的错误。 使用graphiql进行测试。 http://localhost:8089/graphiql

  • 我目前正在学习GraphQL教程,并在“添加数据库”部分解释如何使用GraphQL设置Prisma。 我在prisma中添加完信息。yml文件,已安装prisma,运行prisma deploy并遵循以下步骤,但每次我再次运行prisma info、prisma token或prisma deploy时,都会收到相同的错误: 我一直在努力寻找解决这个错误的方法。我尝试更新节点和npm,下载dock

  • 我需要使用javaFX2执行以下操作: 1-)加载图像并使用imageView显示。[好的] 2-)右键单击并选择“添加节点”选项,屏幕上将出现一个黑色圆圈,您可以将圆圈拖动到图像的任何位置。[好的] 3-)使用鼠标的滚轮放大或缩小图像视图,在图像上提供“缩放感觉”。[确定] 3.1-)但是,每次缩放图像时,我都希望我的圆圈遵循缩放比例,这意味着它们不能保持在屏幕的相同位置。[不知道] 我的问题是

  • 我正在研究在两个数据集上跨边缘在TitanGraph DB上执行图形聚合(groupBy,groupCount)查询: > 大约200,000个节点和大约10亿边 有人知道我需要在什么时候安装Faunus才能在1分钟内完成这种小精灵查询吗?

  • 问题内容: 我有以下控制器… 我的servlet上下文使用以下值设置… 现在,如果我转到那,我得到的视图就是userManagement.jsp,这正是我想要的… 但是,如果我转到404错误。 我看不到的是为什么会发生这种情况,因为我将requestMapping设置为与上面完全相同,并且在/ WEB-INF / views中我有一个createUser.jsp和userManagement.js

  • 导语 环境:Windows Xp + Qt 4.8.4+QtCreator 2.6.2 目录 三、场景(QGraphicsScene) (一)场景层 (二)索引算法 (三)边界矩形 (四)图形项查找 (五)事件处理和传播 (六)打印 四、视图(QGraphicsView) (一)缩放与旋转 (二)场景边框与场景对齐方式 (三)拖动模式 (四)事件传递 (五)背景缓存 (六)OpenGL渲染 (七)