|
| 1 | +--- |
| 2 | +name: Graphene Django CRUDDALS |
| 3 | +description: Turn your Django-models into a complete GraphQL API with all CRUD operations |
| 4 | +url: https://graphene-django-cruddals.readthedocs.io/en/latest/ |
| 5 | +github: juanjcardona13/graphene_django_cruddals |
| 6 | +--- |
| 7 | + |
| 8 | +You can install the package with pip |
| 9 | + |
| 10 | +```bash |
| 11 | +pip install graphene-django-cruddals |
| 12 | +``` |
| 13 | + |
| 14 | +To use it, simply create a new class that inherits "`DjangoModelCruddals`" |
| 15 | +Suppose we have the following models. |
| 16 | + |
| 17 | +```python |
| 18 | +from django.db import models |
| 19 | + |
| 20 | + |
| 21 | +class Question(models.Model): |
| 22 | + question_text = models.CharField(max_length=200) |
| 23 | + pub_date = models.DateTimeField('date published') |
| 24 | + is_active = models.BooleanField(default=True) |
| 25 | +``` |
| 26 | + |
| 27 | +Then we can create a complete CRUD+DALS for the models `Question` with the following code |
| 28 | + |
| 29 | +```python |
| 30 | +from graphene_django_cruddals import DjangoModelCruddals |
| 31 | + |
| 32 | +class CruddalsQuestion(DjangoModelCruddals): |
| 33 | + class Meta: |
| 34 | + model = Question |
| 35 | +``` |
| 36 | + |
| 37 | +Now you can use the `schema` that was generated for you, |
| 38 | + |
| 39 | +```python |
| 40 | +schema = CruddalsQuestion.Schema |
| 41 | +``` |
| 42 | + |
| 43 | +or use in your existing schema root `Query` and `Mutation` |
| 44 | + |
| 45 | +```python |
| 46 | +class Query( |
| 47 | + # ... your others queries |
| 48 | + CruddalsQuestion.Query, |
| 49 | + graphene.ObjectType, |
| 50 | +): |
| 51 | + pass |
| 52 | + |
| 53 | + |
| 54 | +class Mutation( |
| 55 | + # ... your others mutations |
| 56 | + CruddalsQuestion.Mutation, |
| 57 | + graphene.ObjectType, |
| 58 | +): |
| 59 | + pass |
| 60 | + |
| 61 | + |
| 62 | +schema = graphene.Schema( query=Query, mutation=Mutation, ) |
| 63 | +``` |
| 64 | + |
| 65 | +That's it! You can test in graphiql or any other client that you use to test your GraphQL APIs.. |
| 66 | + |
| 67 | +Find more information in the [official documentation](https://graphene-django-cruddals.readthedocs.io/en/latest/). |
0 commit comments