Skip to content

Commit 6f13d28

Browse files
authored
Update README.md (#1408)
* Update README.md * Delete README.rst * Update long_description source to be from README.md
1 parent ce7492b commit 6f13d28

File tree

2 files changed

+89
-62
lines changed

2 files changed

+89
-62
lines changed

README.md

Lines changed: 88 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
# ![Graphene Logo](http://graphene-python.org/favicon.png) Graphene-Django
22

3-
4-
A [Django](https://www.djangoproject.com/) integration for [Graphene](http://graphene-python.org/).
5-
63
[![build][build-image]][build-url]
74
[![pypi][pypi-image]][pypi-url]
85
[![Anaconda-Server Badge][conda-image]][conda-url]
@@ -17,107 +14,137 @@ A [Django](https://www.djangoproject.com/) integration for [Graphene](http://gra
1714
[conda-image]: https://img.shields.io/conda/vn/conda-forge/graphene-django.svg
1815
[conda-url]: https://anaconda.org/conda-forge/graphene-django
1916

20-
[💬 Join the community on Slack](https://join.slack.com/t/graphenetools/shared_invite/enQtOTE2MDQ1NTg4MDM1LTA4Nzk0MGU0NGEwNzUxZGNjNDQ4ZjAwNDJjMjY0OGE1ZDgxZTg4YjM2ZTc4MjE2ZTAzZjE2ZThhZTQzZTkyMmM)
17+
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.
2118

22-
## Documentation
19+
## Features
2320

24-
[Visit the documentation to get started!](https://docs.graphene-python.org/projects/django/en/latest/)
21+
* Seamless integration with Django models
22+
* Automatic generation of GraphQL schema
23+
* Integration with Django's authentication and permission system
24+
* Easy querying and filtering of data
25+
* Support for Django's pagination system
26+
* Compatible with Django's form and validation system
27+
* Extensive documentation and community support
2528

26-
## Quickstart
29+
## Installation
2730

28-
For installing graphene, just run this command in your shell
31+
To install Graphene-Django, run the following command:
2932

30-
```bash
31-
pip install "graphene-django>=3"
33+
```
34+
pip install graphene-django
3235
```
3336

34-
### Settings
37+
## Configuration
38+
39+
After installation, add 'graphene_django' to your Django project's `INSTALLED_APPS` list and define the GraphQL schema in your project's settings:
3540

3641
```python
37-
INSTALLED_APPS = (
42+
INSTALLED_APPS = [
3843
# ...
39-
'django.contrib.staticfiles', # Required for GraphiQL
4044
'graphene_django',
41-
)
45+
]
4246

4347
GRAPHENE = {
44-
'SCHEMA': 'app.schema.schema' # Where your Graphene schema lives
48+
'SCHEMA': 'myapp.schema.schema'
4549
}
4650
```
4751

48-
### Urls
52+
## Usage
4953

50-
We need to set up a `GraphQL` endpoint in our Django app, so we can serve the queries.
54+
To use Graphene-Django, create a `schema.py` file in your Django app directory and define your GraphQL types and queries:
55+
56+
```python
57+
import graphene
58+
from graphene_django import DjangoObjectType
59+
from .models import MyModel
60+
61+
class MyModelType(DjangoObjectType):
62+
class Meta:
63+
model = MyModel
64+
65+
class Query(graphene.ObjectType):
66+
mymodels = graphene.List(MyModelType)
67+
68+
def resolve_mymodels(self, info, **kwargs):
69+
return MyModel.objects.all()
70+
71+
schema = graphene.Schema(query=Query)
72+
```
73+
74+
Then, expose the GraphQL API in your Django project's `urls.py` file:
5175

5276
```python
5377
from django.urls import path
5478
from graphene_django.views import GraphQLView
79+
from . import schema
5580

5681
urlpatterns = [
5782
# ...
58-
path('graphql/', GraphQLView.as_view(graphiql=True)),
83+
path('graphql/', GraphQLView.as_view(graphiql=True)), # Given that schema path is defined in GRAPHENE['SCHEMA'] in your settings.py
5984
]
6085
```
6186

62-
## Examples
87+
## Testing
6388

64-
Here is a simple Django model:
89+
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:
6590

6691
```python
67-
from django.db import models
68-
69-
class UserModel(models.Model):
70-
name = models.CharField(max_length=100)
71-
last_name = models.CharField(max_length=100)
92+
from django.test import TestCase
93+
from graphene_django.utils.testing import GraphQLTestCase
94+
from . import schema
95+
96+
class MyModelAPITestCase(GraphQLTestCase):
97+
GRAPHENE_SCHEMA = schema.schema
98+
99+
def test_query_all_mymodels(self):
100+
response = self.query(
101+
'''
102+
query {
103+
mymodels {
104+
id
105+
name
106+
}
107+
}
108+
'''
109+
)
110+
111+
self.assertResponseNoErrors(response)
112+
self.assertEqual(len(response.data['mymodels']), MyModel.objects.count())
72113
```
73114

74-
To create a GraphQL schema for it you simply have to write the following:
75-
76-
```python
77-
from graphene_django import DjangoObjectType
78-
import graphene
79-
80-
class User(DjangoObjectType):
81-
class Meta:
82-
model = UserModel
83-
84-
class Query(graphene.ObjectType):
85-
users = graphene.List(User)
115+
## Contributing
86116

87-
def resolve_users(self, info):
88-
return UserModel.objects.all()
117+
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).
89118

90-
schema = graphene.Schema(query=Query)
91-
```
119+
## License
92120

93-
Then you can query the schema:
121+
Graphene-Django is released under the [MIT License](https://github.com/graphql-python/graphene-django/blob/master/LICENSE).
94122

95-
```python
96-
query = '''
97-
query {
98-
users {
99-
name,
100-
lastName
101-
}
102-
}
103-
'''
104-
result = schema.execute(query)
105-
```
123+
## Resources
106124

107-
To learn more check out the following [examples](examples/):
125+
* [Official GitHub Repository](https://github.com/graphql-python/graphene-django)
126+
* [Graphene Documentation](http://docs.graphene-python.org/en/latest/)
127+
* [Django Documentation](https://docs.djangoproject.com/en/stable/)
128+
* [GraphQL Specification](https://spec.graphql.org/)
129+
* [GraphiQL](https://github.com/graphql/graphiql) - An in-browser IDE for exploring GraphQL APIs
130+
* [Graphene-Django Community](https://spectrum.chat/graphene) - Join the community to discuss questions and share ideas related to Graphene-Django
108131

109-
* **Schema with Filtering**: [Cookbook example](examples/cookbook)
110-
* **Relay Schema**: [Starwars Relay example](examples/starwars)
132+
## Tutorials and Examples
111133

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

113-
## GraphQL testing clients
114-
- [Firecamp](https://firecamp.io/graphql)
115-
- [GraphiQL](https://github.com/graphql/graphiql)
138+
## Related Projects
116139

140+
* [Graphene](https://github.com/graphql-python/graphene) - A library for building GraphQL APIs in Python
141+
* [Graphene-SQLAlchemy](https://github.com/graphql-python/graphene-sqlalchemy) - Integration between Graphene and SQLAlchemy, an Object Relational Mapper (ORM) for Python
142+
* [Graphene-File-Upload](https://github.com/lmcgartland/graphene-file-upload) - A package providing an Upload scalar for handling file uploads in Graphene
143+
* [Graphene-Subscriptions](https://github.com/graphql-python/graphene-subscriptions) - A package for adding real-time subscriptions to Graphene-based GraphQL APIs
117144

118-
## Contributing
145+
## Support
119146

120-
See [CONTRIBUTING.md](CONTRIBUTING.md)
147+
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)
121148

122149
## Release Notes
123150

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
name="graphene-django",
3838
version=version,
3939
description="Graphene Django integration",
40-
long_description=open("README.rst").read(),
40+
long_description=open("README.md").read(),
4141
url="https://github.com/graphql-python/graphene-django",
4242
author="Syrus Akbary",
4343
author_email="[email protected]",

0 commit comments

Comments
 (0)