mirror of
https://github.com/graphql-python/graphene-django.git
synced 2024-11-25 11:04:11 +03:00
Fresh start
parent
e884da1ac1
commit
75009de111
141
Graphene-Django-Repository.md
Normal file
141
Graphene-Django-Repository.md
Normal file
|
@ -0,0 +1,141 @@
|
|||
## Overview
|
||||
|
||||
Graphene-Django is an open-source repository hosted on GitHub that provides a seamless integration between Django, a high-level Python web framework, and Graphene, a library for building GraphQL APIs. The repository allows developers to create GraphQL APIs in Django quickly and efficiently while maintaining a high level of performance.
|
||||
|
||||
Graphene-Django is maintained by a community based team of developers and contributors from around the world. Its aim is to simplify the process of building GraphQL APIs in Django and improve overall developer experience.
|
||||
|
||||
## Contents
|
||||
|
||||
1. [Features](#Features)
|
||||
2. [Installation](#Installation)
|
||||
3. [Configuration](#Configuration)
|
||||
4. [Usage](#Usage)
|
||||
5. [Testing](#Testing)
|
||||
6. [Contributing](#Contributing)
|
||||
7. [License](#License)
|
||||
8. [Resources](#Resources)
|
||||
|
||||
## 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:
|
||||
|
||||
```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, schema=schema.schema)),
|
||||
]
|
||||
```
|
||||
|
||||
## 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/master/CONTRIBUTING.md).
|
||||
|
||||
## License
|
||||
|
||||
Graphene-Django is released under the [MIT License](https://github.com/graphql-python/graphene-django/blob/master/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
|
8
Home.md
8
Home.md
|
@ -1,8 +0,0 @@
|
|||
Welcome to the graphene-django wiki!
|
||||
|
||||
We are using the wiki to consolidate tips and tricks when working with Graphene-Django. This is intended to hold working examples of code for specific requirements and is distinct from the documentation, which demonstrates the basic usage of Graphene Django.
|
||||
|
||||
The wiki is open to any contributor so please add your tips and tricks!
|
||||
|
||||
# Table of Contents
|
||||
- [FAQ](FAQ)
|
Loading…
Reference in New Issue
Block a user