graphene-django


Namegraphene-django JSON
Version 3.2.1 PyPI version JSON
download
home_pagehttps://github.com/graphql-python/graphene-django
SummaryGraphene Django integration
upload_time2024-04-09 00:41:40
maintainerNone
docs_urlNone
authorSyrus Akbary
requires_pythonNone
licenseMIT
keywords api graphql protocol rest relay graphene
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage
            # ![Graphene Logo](http://graphene-python.org/favicon.png) Graphene-Django

[![build][build-image]][build-url]
[![pypi][pypi-image]][pypi-url]
[![Anaconda-Server Badge][conda-image]][conda-url]
[![coveralls][coveralls-image]][coveralls-url]

[build-image]: https://github.com/graphql-python/graphene-django/workflows/Tests/badge.svg
[build-url]: https://github.com/graphql-python/graphene-django/actions
[pypi-image]: https://img.shields.io/pypi/v/graphene-django.svg?style=flat
[pypi-url]: https://pypi.org/project/graphene-django/
[coveralls-image]: https://coveralls.io/repos/github/graphql-python/graphene-django/badge.svg?branch=master
[coveralls-url]: https://coveralls.io/github/graphql-python/graphene-django?branch=master
[conda-image]: https://img.shields.io/conda/vn/conda-forge/graphene-django.svg
[conda-url]: https://anaconda.org/conda-forge/graphene-django

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:

```sh
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:

```python
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:

```python
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:

```python
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:

```python
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](https://github.com/graphql-python/graphene-django/issues) and [contribution guidelines](https://github.com/graphql-python/graphene-django/blob/main/CONTRIBUTING.md).

## License

Graphene-Django is released under the [MIT License](https://github.com/graphql-python/graphene-django/blob/main/LICENSE).

## Resources

* [Official GitHub Repository](https://github.com/graphql-python/graphene-django)
* [Graphene Documentation](http://docs.graphene-python.org/en/latest/)
* [Django Documentation](https://docs.djangoproject.com/en/stable/)
* [GraphQL Specification](https://spec.graphql.org/)
* [GraphiQL](https://github.com/graphql/graphiql) - An in-browser IDE for exploring GraphQL APIs
* [Graphene-Django Community](https://spectrum.chat/graphene) - Join the community to discuss questions and share ideas related to Graphene-Django

## Tutorials and Examples

* [Official Graphene-Django Tutorial](https://docs.graphene-python.org/projects/django/en/latest/tutorial-plain/)
* [Building a GraphQL API with Django and Graphene-Django](https://www.howtographql.com/graphql-python/0-introduction/)
* [Real-world example: Django, Graphene, and Relay](https://github.com/graphql-python/swapi-graphene)

## Related Projects

* [Graphene](https://github.com/graphql-python/graphene) - A library for building GraphQL APIs in Python
* [Graphene-SQLAlchemy](https://github.com/graphql-python/graphene-sqlalchemy) - Integration between Graphene and SQLAlchemy, an Object Relational Mapper (ORM) for Python
* [Graphene-File-Upload](https://github.com/lmcgartland/graphene-file-upload) - A package providing an Upload scalar for handling file uploads in Graphene
* [Graphene-Subscriptions](https://github.com/graphql-python/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](https://github.com/graphql-python/graphene-django/issues/new) on the official GitHub repository. You can also ask for help and share your experiences with the Graphene-Django community on [💬 Discord](https://discord.gg/Fftt273T79)

## Release Notes

* See [Releases page on github](https://github.com/graphql-python/graphene-django/releases)

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/graphql-python/graphene-django",
    "name": "graphene-django",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": "api graphql protocol rest relay graphene",
    "author": "Syrus Akbary",
    "author_email": "me@syrusakbary.com",
    "download_url": "https://files.pythonhosted.org/packages/ca/f4/8e6a9221ed92cfd68ac51b495da0aaaa76ddfc527983990c9d1c7e5e5a93/graphene-django-3.2.1.tar.gz",
    "platform": "any",
    "description": "# ![Graphene Logo](http://graphene-python.org/favicon.png) Graphene-Django\n\n[![build][build-image]][build-url]\n[![pypi][pypi-image]][pypi-url]\n[![Anaconda-Server Badge][conda-image]][conda-url]\n[![coveralls][coveralls-image]][coveralls-url]\n\n[build-image]: https://github.com/graphql-python/graphene-django/workflows/Tests/badge.svg\n[build-url]: https://github.com/graphql-python/graphene-django/actions\n[pypi-image]: https://img.shields.io/pypi/v/graphene-django.svg?style=flat\n[pypi-url]: https://pypi.org/project/graphene-django/\n[coveralls-image]: https://coveralls.io/repos/github/graphql-python/graphene-django/badge.svg?branch=master\n[coveralls-url]: https://coveralls.io/github/graphql-python/graphene-django?branch=master\n[conda-image]: https://img.shields.io/conda/vn/conda-forge/graphene-django.svg\n[conda-url]: https://anaconda.org/conda-forge/graphene-django\n\nGraphene-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.\n\n## Features\n\n* Seamless integration with Django models\n* Automatic generation of GraphQL schema\n* Integration with Django's authentication and permission system\n* Easy querying and filtering of data\n* Support for Django's pagination system\n* Compatible with Django's form and validation system\n* Extensive documentation and community support\n\n## Installation\n\nTo install Graphene-Django, run the following command:\n\n```sh\npip install graphene-django\n```\n\n## Configuration\n\nAfter installation, add 'graphene_django' to your Django project's `INSTALLED_APPS` list and define the GraphQL schema in your project's settings:\n\n```python\nINSTALLED_APPS = [\n    # ...\n    'graphene_django',\n]\n\nGRAPHENE = {\n    'SCHEMA': 'myapp.schema.schema'\n}\n```\n\n## Usage\n\nTo use Graphene-Django, create a `schema.py` file in your Django app directory and define your GraphQL types and queries:\n\n```python\nimport graphene\nfrom graphene_django import DjangoObjectType\nfrom .models import MyModel\n\nclass MyModelType(DjangoObjectType):\n    class Meta:\n        model = MyModel\n\nclass Query(graphene.ObjectType):\n    mymodels = graphene.List(MyModelType)\n\n    def resolve_mymodels(self, info, **kwargs):\n        return MyModel.objects.all()\n\nschema = graphene.Schema(query=Query)\n```\n\nThen, expose the GraphQL API in your Django project's `urls.py` file:\n\n```python\nfrom django.urls import path\nfrom graphene_django.views import GraphQLView\nfrom . import schema\n\nurlpatterns = [\n    # ...\n    path('graphql/', GraphQLView.as_view(graphiql=True)), # Given that schema path is defined in GRAPHENE['SCHEMA'] in your settings.py\n]\n```\n\n## Testing\n\nGraphene-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:\n\n```python\nfrom django.test import TestCase\nfrom graphene_django.utils.testing import GraphQLTestCase\nfrom . import schema\n\nclass MyModelAPITestCase(GraphQLTestCase):\n    GRAPHENE_SCHEMA = schema.schema\n\n    def test_query_all_mymodels(self):\n        response = self.query(\n            '''\n            query {\n                mymodels {\n                    id\n                    name\n                }\n            }\n            '''\n        )\n\n        self.assertResponseNoErrors(response)\n        self.assertEqual(len(response.data['mymodels']), MyModel.objects.count())\n```\n\n## Contributing\n\nContributions to Graphene-Django are always welcome! To get started, check the repository's [issue tracker](https://github.com/graphql-python/graphene-django/issues) and [contribution guidelines](https://github.com/graphql-python/graphene-django/blob/main/CONTRIBUTING.md).\n\n## License\n\nGraphene-Django is released under the [MIT License](https://github.com/graphql-python/graphene-django/blob/main/LICENSE).\n\n## Resources\n\n* [Official GitHub Repository](https://github.com/graphql-python/graphene-django)\n* [Graphene Documentation](http://docs.graphene-python.org/en/latest/)\n* [Django Documentation](https://docs.djangoproject.com/en/stable/)\n* [GraphQL Specification](https://spec.graphql.org/)\n* [GraphiQL](https://github.com/graphql/graphiql) - An in-browser IDE for exploring GraphQL APIs\n* [Graphene-Django Community](https://spectrum.chat/graphene) - Join the community to discuss questions and share ideas related to Graphene-Django\n\n## Tutorials and Examples\n\n* [Official Graphene-Django Tutorial](https://docs.graphene-python.org/projects/django/en/latest/tutorial-plain/)\n* [Building a GraphQL API with Django and Graphene-Django](https://www.howtographql.com/graphql-python/0-introduction/)\n* [Real-world example: Django, Graphene, and Relay](https://github.com/graphql-python/swapi-graphene)\n\n## Related Projects\n\n* [Graphene](https://github.com/graphql-python/graphene) - A library for building GraphQL APIs in Python\n* [Graphene-SQLAlchemy](https://github.com/graphql-python/graphene-sqlalchemy) - Integration between Graphene and SQLAlchemy, an Object Relational Mapper (ORM) for Python\n* [Graphene-File-Upload](https://github.com/lmcgartland/graphene-file-upload) - A package providing an Upload scalar for handling file uploads in Graphene\n* [Graphene-Subscriptions](https://github.com/graphql-python/graphene-subscriptions) - A package for adding real-time subscriptions to Graphene-based GraphQL APIs\n\n## Support\n\nIf you encounter any issues or have questions regarding Graphene-Django, feel free to [submit an issue](https://github.com/graphql-python/graphene-django/issues/new) on the official GitHub repository. You can also ask for help and share your experiences with the Graphene-Django community on [\ud83d\udcac Discord](https://discord.gg/Fftt273T79)\n\n## Release Notes\n\n* See [Releases page on github](https://github.com/graphql-python/graphene-django/releases)\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Graphene Django integration",
    "version": "3.2.1",
    "project_urls": {
        "Homepage": "https://github.com/graphql-python/graphene-django"
    },
    "split_keywords": [
        "api",
        "graphql",
        "protocol",
        "rest",
        "relay",
        "graphene"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "1be8cc2caedbc0e65f2bd5c5a9efa06f4c11506b027006120385f71b956bf1f7",
                "md5": "7f85a26d129812b10c3a0d54e9e1514f",
                "sha256": "3fbdd8d4990ecec326c59d68edfcaf9a7bc9c4dbdcbf88b11ac46dfc10240e49"
            },
            "downloads": -1,
            "filename": "graphene_django-3.2.1-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "7f85a26d129812b10c3a0d54e9e1514f",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": null,
            "size": 114542,
            "upload_time": "2024-04-09T00:41:38",
            "upload_time_iso_8601": "2024-04-09T00:41:38.686881Z",
            "url": "https://files.pythonhosted.org/packages/1b/e8/cc2caedbc0e65f2bd5c5a9efa06f4c11506b027006120385f71b956bf1f7/graphene_django-3.2.1-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "caf48e6a9221ed92cfd68ac51b495da0aaaa76ddfc527983990c9d1c7e5e5a93",
                "md5": "4a7736ccdfe48bd44acf1c086a349973",
                "sha256": "52145037872d2575974c4bb2be224756ffeafe5a4e20f9c4367519622965812b"
            },
            "downloads": -1,
            "filename": "graphene-django-3.2.1.tar.gz",
            "has_sig": false,
            "md5_digest": "4a7736ccdfe48bd44acf1c086a349973",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 87830,
            "upload_time": "2024-04-09T00:41:40",
            "upload_time_iso_8601": "2024-04-09T00:41:40.755474Z",
            "url": "https://files.pythonhosted.org/packages/ca/f4/8e6a9221ed92cfd68ac51b495da0aaaa76ddfc527983990c9d1c7e5e5a93/graphene-django-3.2.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-04-09 00:41:40",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "graphql-python",
    "github_project": "graphene-django",
    "travis_ci": false,
    "coveralls": true,
    "github_actions": true,
    "tox": true,
    "lcname": "graphene-django"
}
        
Elapsed time: 0.24004s