Giter Site home page Giter Site logo

nossila / graphene-django Goto Github PK

View Code? Open in Web Editor NEW

This project forked from graphql-python/graphene-django

0.0 0.0 0.0 1.31 MB

Build powerful, efficient, and flexible GraphQL APIs with seamless Django integration.

Home Page: http://docs.graphene-python.org/projects/django/en/latest/

License: MIT License

Shell 0.09% JavaScript 0.88% Python 98.26% Makefile 0.18% HTML 0.59%

graphene-django's Introduction

Graphene Logo Graphene-Django

build pypi Anaconda-Server Badge coveralls

Graphene-Django is an open-source library that provides seamless integration between Django, a high-level Python web framework, and Graphene, a library for building GraphQL APIs. The library allows developers to create GraphQL APIs in Django quickly and efficiently while maintaining a high level of performance.

Features

  • Seamless integration with Django models
  • Automatic generation of GraphQL schema
  • Integration with Django's authentication and permission system
  • Easy querying and filtering of data
  • Support for Django's pagination system
  • Compatible with Django's form and validation system
  • Extensive documentation and community support

Installation

To install Graphene-Django, run the following command:

pip install graphene-django

Configuration

After installation, add 'graphene_django' to your Django project's INSTALLED_APPS list and define the GraphQL schema in your project's settings:

INSTALLED_APPS = [
    # ...
    'graphene_django',
]

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

Usage

To use Graphene-Django, create a schema.py file in your Django app directory and define your GraphQL types and queries:

import graphene
from graphene_django import DjangoObjectType
from .models import MyModel

class MyModelType(DjangoObjectType):
    class Meta:
        model = MyModel

class Query(graphene.ObjectType):
    mymodels = graphene.List(MyModelType)

    def resolve_mymodels(self, info, **kwargs):
        return MyModel.objects.all()

schema = graphene.Schema(query=Query)

Then, expose the GraphQL API in your Django project's urls.py file:

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

urlpatterns = [
    # ...
    path('graphql/', GraphQLView.as_view(graphiql=True)), # Given that schema path is defined in GRAPHENE['SCHEMA'] in your settings.py
]

Testing

Graphene-Django provides support for testing GraphQL APIs using Django's test client. To create tests, create a tests.py file in your Django app directory and write your test cases:

from django.test import TestCase
from graphene_django.utils.testing import GraphQLTestCase
from . import schema

class MyModelAPITestCase(GraphQLTestCase):
    GRAPHENE_SCHEMA = schema.schema

    def test_query_all_mymodels(self):
        response = self.query(
            '''
            query {
                mymodels {
                    id
                    name
                }
            }
            '''
        )

        self.assertResponseNoErrors(response)
        self.assertEqual(len(response.data['mymodels']), MyModel.objects.count())

Contributing

Contributions to Graphene-Django are always welcome! To get started, check the repository's issue tracker and contribution guidelines.

License

Graphene-Django is released under the MIT License.

Resources

Tutorials and Examples

Related Projects

  • Graphene - A library for building GraphQL APIs in Python
  • Graphene-SQLAlchemy - Integration between Graphene and SQLAlchemy, an Object Relational Mapper (ORM) for Python
  • Graphene-File-Upload - A package providing an Upload scalar for handling file uploads in Graphene
  • Graphene-Subscriptions - A package for adding real-time subscriptions to Graphene-based GraphQL APIs

Support

If you encounter any issues or have questions regarding Graphene-Django, feel free to submit an issue on the official GitHub repository. You can also ask for help and share your experiences with the Graphene-Django community on ๐Ÿ’ฌ Discord

Release Notes

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.