mirror of
https://github.com/graphql-python/graphene-django.git
synced 2025-07-13 17:52:19 +03:00
updated documentation
This commit is contained in:
parent
76fbcefbc7
commit
9e667e00e5
73
README.md
73
README.md
|
@ -12,11 +12,13 @@ A [Django](https://www.djangoproject.com/) integration for [Graphene](http://gra
|
||||||
For installing graphene, just run this command in your shell
|
For installing graphene, just run this command in your shell
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
pip install "graphene-django>=2.0"
|
pip install "graphene-neo4j>=2.0"
|
||||||
```
|
```
|
||||||
|
|
||||||
### Settings
|
### Settings
|
||||||
|
|
||||||
|
Use basic graphene_django package in INSTALLED_APPS
|
||||||
|
|
||||||
```python
|
```python
|
||||||
INSTALLED_APPS = (
|
INSTALLED_APPS = (
|
||||||
# ...
|
# ...
|
||||||
|
@ -44,14 +46,14 @@ urlpatterns = [
|
||||||
|
|
||||||
## Examples
|
## Examples
|
||||||
|
|
||||||
Here is a simple Django model:
|
Here is a simple neomodel model:
|
||||||
|
|
||||||
```python
|
```python
|
||||||
from django.db import models
|
from neomodel import *
|
||||||
|
|
||||||
class UserModel(models.Model):
|
class UserModel(StructuredNode):
|
||||||
name = models.CharField(max_length=100)
|
name = StringProperty(required=True)
|
||||||
last_name = models.CharField(max_length=100)
|
age = IntegerProperty()
|
||||||
```
|
```
|
||||||
|
|
||||||
To create a GraphQL schema for it you simply have to write the following:
|
To create a GraphQL schema for it you simply have to write the following:
|
||||||
|
@ -62,25 +64,62 @@ import graphene
|
||||||
|
|
||||||
class User(DjangoObjectType):
|
class User(DjangoObjectType):
|
||||||
class Meta:
|
class Meta:
|
||||||
|
# pass yours model here, the fields are define automatically
|
||||||
model = UserModel
|
model = UserModel
|
||||||
|
|
||||||
class Query(graphene.ObjectType):
|
class Query(graphene.ObjectType):
|
||||||
users = graphene.List(User)
|
users = graphene.List(User)
|
||||||
|
|
||||||
def resolve_users(self, info):
|
def resolve_users(self, info):
|
||||||
return UserModel.objects.all()
|
return UserModel.nodes.all()
|
||||||
|
|
||||||
schema = graphene.Schema(query=Query)
|
schema = graphene.Schema(query=Query)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
### Relay schema
|
||||||
|
|
||||||
|
```python
|
||||||
|
import graphene
|
||||||
|
from graphene_django import DjangoObjectType
|
||||||
|
from graphene_django.filter.fields import DjangoFilterConnectionField
|
||||||
|
|
||||||
|
class UserType(DjangoObjectType):
|
||||||
|
class Meta:
|
||||||
|
# pass yours model here, the fields are define automatically
|
||||||
|
model = UserModel
|
||||||
|
|
||||||
|
# definition of filter settings
|
||||||
|
# key - the <field_name>
|
||||||
|
# value - the list of search instructions
|
||||||
|
neomodel_filter_fields = {
|
||||||
|
'name': ['icontains', 'contains', 'exact'],
|
||||||
|
'age': ['lte', 'gte', 'gt'],
|
||||||
|
}
|
||||||
|
|
||||||
|
interfaces = (
|
||||||
|
graphene.relay.Node,
|
||||||
|
)
|
||||||
|
|
||||||
|
class Query(graphene.ObjectType):
|
||||||
|
""" The types resolves automatically
|
||||||
|
"""
|
||||||
|
user = graphene.relay.Node.Field(UserType)
|
||||||
|
users = DjangoFilterConnectionField(UserType)
|
||||||
|
|
||||||
|
|
||||||
|
schema = graphene.Schema(query=Query)
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
Then you can simply query the schema:
|
Then you can simply query the schema:
|
||||||
|
|
||||||
```python
|
```python
|
||||||
query = '''
|
query = '''
|
||||||
query {
|
query {
|
||||||
users {
|
users {
|
||||||
name,
|
name
|
||||||
lastName
|
age
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
'''
|
'''
|
||||||
|
@ -92,22 +131,6 @@ To learn more check out the following [examples](examples/):
|
||||||
* **Schema with Filtering**: [Cookbook example](examples/cookbook)
|
* **Schema with Filtering**: [Cookbook example](examples/cookbook)
|
||||||
* **Relay Schema**: [Starwars Relay example](examples/starwars)
|
* **Relay Schema**: [Starwars Relay example](examples/starwars)
|
||||||
|
|
||||||
|
|
||||||
## Contributing
|
|
||||||
|
|
||||||
After cloning this repo, ensure dependencies are installed by running:
|
|
||||||
|
|
||||||
```sh
|
|
||||||
pip install -e ".[test]"
|
|
||||||
```
|
|
||||||
|
|
||||||
After developing, the full test suite can be evaluated by running:
|
|
||||||
|
|
||||||
```sh
|
|
||||||
py.test graphene_django --cov=graphene_django # Use -v -s for verbose mode
|
|
||||||
```
|
|
||||||
|
|
||||||
|
|
||||||
### Documentation
|
### Documentation
|
||||||
|
|
||||||
The [documentation](http://docs.graphene-python.org/projects/django/en/latest/) is generated using the excellent [Sphinx](http://www.sphinx-doc.org/) and a custom theme.
|
The [documentation](http://docs.graphene-python.org/projects/django/en/latest/) is generated using the excellent [Sphinx](http://www.sphinx-doc.org/) and a custom theme.
|
||||||
|
|
Loading…
Reference in New Issue
Block a user