You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: .github/ISSUE_TEMPLATE/bug_report.md
+3-3
Original file line number
Diff line number
Diff line change
@@ -27,8 +27,8 @@ a github repo, https://repl.it or similar (you can use this template as a starti
27
27
28
28
29
29
***Please tell us about your environment:**
30
-
31
-
- Version:
32
-
- Platform:
30
+
31
+
- Version:
32
+
- Platform:
33
33
34
34
***Other information** (e.g. detailed explanation, stacktraces, related issues, suggestions how to fix, links for us to have context, eg. stackoverflow)
[💬 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.
21
18
22
-
## Documentation
19
+
## Features
23
20
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
25
28
26
-
## Quickstart
29
+
## Installation
27
30
28
-
For installing graphene, just run this command in your shell
31
+
To install Graphene-Django, run the following command:
29
32
30
-
```bash
31
-
pip install "graphene-django>=3"
33
+
```
34
+
pip install graphene-django
32
35
```
33
36
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:
35
40
36
41
```python
37
-
INSTALLED_APPS=(
42
+
INSTALLED_APPS=[
38
43
# ...
39
-
'django.contrib.staticfiles', # Required for GraphiQL
40
44
'graphene_django',
41
-
)
45
+
]
42
46
43
47
GRAPHENE= {
44
-
'SCHEMA': 'app.schema.schema'# Where your Graphene schema lives
48
+
'SCHEMA': 'myapp.schema.schema'
45
49
}
46
50
```
47
51
48
-
### Urls
52
+
##Usage
49
53
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
+
classMyModelType(DjangoObjectType):
62
+
classMeta:
63
+
model = MyModel
64
+
65
+
classQuery(graphene.ObjectType):
66
+
mymodels = graphene.List(MyModelType)
67
+
68
+
defresolve_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:
path('graphql/', GraphQLView.as_view(graphiql=True)),# Given that schema path is defined in GRAPHENE['SCHEMA'] in your settings.py
59
84
]
60
85
```
61
86
62
-
## Examples
87
+
## Testing
63
88
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:
65
90
66
91
```python
67
-
from django.db import models
68
-
69
-
classUserModel(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
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
-
classUser(DjangoObjectType):
81
-
classMeta:
82
-
model = UserModel
83
-
84
-
classQuery(graphene.ObjectType):
85
-
users = graphene.List(User)
115
+
## Contributing
86
116
87
-
defresolve_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).
89
118
90
-
schema = graphene.Schema(query=Query)
91
-
```
119
+
## License
92
120
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).
94
122
95
-
```python
96
-
query ='''
97
-
query {
98
-
users {
99
-
name,
100
-
lastName
101
-
}
102
-
}
103
-
'''
104
-
result = schema.execute(query)
105
-
```
123
+
## Resources
106
124
107
-
To learn more check out the following [examples](examples/):
*[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)
112
137
113
-
## GraphQL testing clients
114
-
-[Firecamp](https://firecamp.io/graphql)
115
-
-[GraphiQL](https://github.com/graphql/graphiql)
138
+
## Related Projects
116
139
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
117
144
118
-
## Contributing
145
+
## Support
119
146
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)
0 commit comments