当前位置: 首页 > 软件库 > 大数据 > 数据查询 >

graphene-django

Integrate GraphQL into your Django project.
授权协议 MIT License
开发语言 Java
所属分类 大数据、 数据查询
软件类型 开源软件
地区 不详
投 递 者 郦良才
操作系统 跨平台
开源组织
适用人群 未知
 软件概览

Graphene Logo Graphene-Django

A Django integration for Graphene.

build

�� Join the community on Slack

Documentation

Visit the documentation to get started!

Quickstart

For installing graphene, just run this command in your shell

pip install "graphene-django>=3"

Settings

INSTALLED_APPS = (
    # ...
    'django.contrib.staticfiles', # Required for GraphiQL
    'graphene_django',
)

GRAPHENE = {
    'SCHEMA': 'app.schema.schema' # Where your Graphene schema lives
}

Urls

We need to set up a GraphQL endpoint in our Django app, so we can serve the queries.

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

urlpatterns = [
    # ...
    path('graphql', GraphQLView.as_view(graphiql=True)),
]

Examples

Here is a simple Django model:

from django.db import models

class UserModel(models.Model):
    name = models.CharField(max_length=100)
    last_name = models.CharField(max_length=100)

To create a GraphQL schema for it you simply have to write the following:

from graphene_django import DjangoObjectType
import graphene

class User(DjangoObjectType):
    class Meta:
        model = UserModel

class Query(graphene.ObjectType):
    users = graphene.List(User)

    def resolve_users(self, info):
        return UserModel.objects.all()

schema = graphene.Schema(query=Query)

Then you can query the schema:

query = '''
    query {
      users {
        name,
        lastName
      }
    }
'''
result = schema.execute(query)

To learn more check out the following examples:

GraphQL testing clients

Contributing

See CONTRIBUTING.md

Release Notes

  • Model._meta API是Django ORM的核心,它使得lookups、queries、forms、admin这些模块通过每个model类的_meta的属性可以了解每个model的情况。 1. 字段访问API,使用名字检索一个model的字段实例 Options.get_field(field_name) 根据给出的field_name返回一个字段实例。field_name可以是mode

  • 以下配置已经在ubuntu 18.04上测试通过, ubuntu16.04以为很多默认so库版本过低(比如glibc, gcc等),需求额外做一些事情, 所有非常建议使用ubuntu18.04 作为编译环境。 Graphene with out SGX Clone the Graphene Repository: git clone https://github.com/oscarlab/grap

  • Docs »  Django Highcharts  Edit on GitHub Django Highcharts Django Highchart will make it easier for you to display highcharts graphs. Quickstart Install django-highcharts using pip (we do recommend t

  • Using Django with Appengine Author: Shabda Raaj Version: 1 Copyright: This document is released under a Creative Common Attribution license. Contents * About * What will we build

  • 1. 在urls.py中给某些urlpatters命名(url_name),然后就可以通过这个装饰器直接取出这个object的地址,这样做的好处是可以只在urls.py中改链接,不用再在get_absolute_url函数中修改链接了。 @models.permalink get_absolute_url(self): return ('url_name',(),{})

  • {% extends 'base.html' %} {% block title %}环境监控{% endblock title %} {% block extracss %} {% load staticfiles %} <link rel="stylesheet" href="{% static 'app/CSS/environment.css' %}"> <scrip

  • Lists and Non-Null Object types、 scalars和 enums 是可以在Graphene中定义的唯一类型。但是,当在schema的其他部分或查询变量声明中使用类型时,可以应用其他类型修饰符来影响这些值的验证。 NonNull import graphene class Man(graphene.ObjectType): name = graphene.No

  • 枚举 枚举是一种特殊的GraphQL类型,它表示绑定到唯一常数值的一组符号名称(成员) 创建一个Enum使用类 import graphene class Episode(graphene.Enum): NEWHOPE = 4 EMPIRE = 5 JEDI = 6 也可以使用枚举实例 Episode = graphene.Enum('Episode', [('NEWH

  • Web请求中的认证 Authentication inWeb requests Django使用sessions 和 middleware来链接认证系统与请求对象(request objects)。 在每个Web请求中都提供一个 request.user 属性来表示当前用户。如果当前用户未登录,则该属性为AnonymousUser的一个实例,反之,则是一个User实例。 你可以通过is_authe

  • Abstract This research work focuses on the synthesis, characterization and processing of potassium silicate/zinc/graphene composites to improve the corrosion performance of zinc-rich coatings. A stabl

 相关资料
  • Graphene 项目的目的是使用非常性感的类型安全的 API 进行 Ajax 测试,是 Selenium 项目的扩展。

  • Please read UPGRADE-v2.0.mdto learn how to upgrade to Graphene 2.0. Graphene-SQLAlchemy A SQLAlchemy integration for Graphene. Installation For instaling graphene, just run this command in your shell

  • Graphene 是 Python 的 GraphQL 框架,用于快速轻松构建 GraphQL schemas/types 。支持多种数据源,包括 SQL(Django、SQLAlchemy)、NoSQL、自定义 Python 对象等等。 示例代码: import grapheneclass Query(graphene.ObjectType):    hello = graphene.Strin

  • Graphene-Django-Extras This package adds some extra functionalities to graphene-django to facilitate the graphql use without Relay: Allow pagination and filtering on Queries. Allow defining DjangoRest

  • 问题内容: 我在Django中有一些REST API端点,我想对Graphene使用相同的身份验证。该文档不提供任何指导。 问题答案: 例如,如果在API视图中使用,则可以将端点添加到以这种方式装饰的GraphQLView中: urls.py: 请注意,我们添加了一个新的端点,并保留了GraphiQL工具使用的原始端点。 然后,您应该在GraphQL客户端中设置标头并指向端点。 更新:请参阅此Gi

  • 我有两种型号: 模式: GraphQL的目标之一是性能。为此,GraphQL必须通过GraphQL请求(例如:GraphiQL)仅向数据库请求所请求的字段 如果我请求以下查询: 石墨烯-django库生成以下SQL: 它得到了模型的所有字段!与API Rest问题相同,不符合GraphQL指南。 如果我从模型中请求字段,我希望查询是: 外键如何解决这个问题?