strawberry-graphql-django


Namestrawberry-graphql-django JSON
Version 0.39.2 PyPI version JSON
download
home_pagehttps://github.com/strawberry-graphql/strawberry-django
SummaryStrawberry GraphQL Django extension
upload_time2024-04-25 22:35:54
maintainerThiago Bellini Ribeiro
docs_urlNone
authorLauri Hintsala
requires_python<4.0,>=3.8
licenseMIT
keywords graphql api django strawberry-graphql
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage
            # Strawberry GraphQL Django integration

[![CI](https://github.com/strawberry-graphql/strawberry-django/actions/workflows/tests.yml/badge.svg)](https://github.com/strawberry-graphql/strawberry-django/actions/workflows/tests.yml)
[![Coverage](https://codecov.io/gh/strawberry-graphql/strawberry-django/branch/main/graph/badge.svg?token=JNH6PUYh3e)](https://codecov.io/gh/strawberry-graphql/strawberry-django)
[![PyPI](https://img.shields.io/pypi/v/strawberry-graphql-django)](https://pypi.org/project/strawberry-graphql-django/)
[![Downloads](https://pepy.tech/badge/strawberry-graphql-django)](https://pepy.tech/project/strawberry-graphql-django)
![PyPI - Python Version](https://img.shields.io/pypi/pyversions/strawberry-graphql-django)

[**Docs**](https://strawberry-graphql.github.io/strawberry-django/) | [**Discord**](https://strawberry.rocks/discord)

This package provides powerful tools to generate GraphQL types, queries,
mutations and resolvers from Django models.

Installing `strawberry-graphql-django` package from the python package repository.

```shell
pip install strawberry-graphql-django
```

## Supported Features

- [x] GraphQL type generation from models
- [x] Filtering, pagination and ordering
- [x] Basic create, retrieve, update and delete (CRUD) types and mutations
- [x] Basic Django auth support, current user query, login and logout mutations
- [x] Django sync and async views
- [x] Permission extension using django's permissioning system
- [x] Relay support with automatic resolvers generation
- [x] Query optimization to improve performance and avoid common pitfalls (e.g n+1)
- [x] Debug Toolbar integration with graphiql to display metrics like SQL queries
- [x] Unit test integration

## Basic Usage

```python
# models.py

from django.db import models

class Fruit(models.Model):
    """A tasty treat"""
    name = models.CharField(
        max_length=20,
    )
    color = models.ForeignKey(
        "Color",
        on_delete=models.CASCADE,
        related_name="fruits",
        blank=True,
        null=True,
    )

class Color(models.Model):
    name = models.CharField(
        max_length=20,
        help_text="field description",
    )
```

```python
# types.py

import strawberry_django
from strawberry import auto

from . import models

@strawberry_django.type(models.Fruit)
class Fruit:
    id: auto
    name: auto
    color: 'Color'

@strawberry_django.type(models.Color)
class Color:
    id: auto
    name: auto
    fruits: list[Fruit]
```

```python
# schema.py

import strawberry
import strawberry_django
from strawberry_django.optimizer import DjangoOptimizerExtension

from .types import Fruit

@strawberry.type
class Query:
    fruits: list[Fruit] = strawberry_django.field()

schema = strawberry.Schema(
    query=Query,
    extensions=[
        DjangoOptimizerExtension,  # not required, but highly recommended
    ],
)
```

```python
# urls.py

from django.urls import include, path
from strawberry.django.views import AsyncGraphQLView

from .schema import schema

urlpatterns = [
    path('graphql', AsyncGraphQLView.as_view(schema=schema)),
]
```

Code above generates following schema.

```graphql
"""
A tasty treat
"""
type Fruit {
  id: ID!
  name: String!
  color: Color
}

type Color {
  id: ID!
  """
  field description
  """
  name: String!
  fruits: [Fruit!]
}

type Query {
  fruits: [Fruit!]!
}
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/strawberry-graphql/strawberry-django",
    "name": "strawberry-graphql-django",
    "maintainer": "Thiago Bellini Ribeiro",
    "docs_url": null,
    "requires_python": "<4.0,>=3.8",
    "maintainer_email": "thiago@bellini.dev",
    "keywords": "graphql, api, django, strawberry-graphql",
    "author": "Lauri Hintsala",
    "author_email": "lauri.hintsala@verkkopaja.fi",
    "download_url": "https://files.pythonhosted.org/packages/45/36/1da92a2565877baca6bc81671967fecc55b8d8be6062dd41a4b6f9b12598/strawberry_graphql_django-0.39.2.tar.gz",
    "platform": null,
    "description": "# Strawberry GraphQL Django integration\n\n[![CI](https://github.com/strawberry-graphql/strawberry-django/actions/workflows/tests.yml/badge.svg)](https://github.com/strawberry-graphql/strawberry-django/actions/workflows/tests.yml)\n[![Coverage](https://codecov.io/gh/strawberry-graphql/strawberry-django/branch/main/graph/badge.svg?token=JNH6PUYh3e)](https://codecov.io/gh/strawberry-graphql/strawberry-django)\n[![PyPI](https://img.shields.io/pypi/v/strawberry-graphql-django)](https://pypi.org/project/strawberry-graphql-django/)\n[![Downloads](https://pepy.tech/badge/strawberry-graphql-django)](https://pepy.tech/project/strawberry-graphql-django)\n![PyPI - Python Version](https://img.shields.io/pypi/pyversions/strawberry-graphql-django)\n\n[**Docs**](https://strawberry-graphql.github.io/strawberry-django/) | [**Discord**](https://strawberry.rocks/discord)\n\nThis package provides powerful tools to generate GraphQL types, queries,\nmutations and resolvers from Django models.\n\nInstalling `strawberry-graphql-django` package from the python package repository.\n\n```shell\npip install strawberry-graphql-django\n```\n\n## Supported Features\n\n- [x] GraphQL type generation from models\n- [x] Filtering, pagination and ordering\n- [x] Basic create, retrieve, update and delete (CRUD) types and mutations\n- [x] Basic Django auth support, current user query, login and logout mutations\n- [x] Django sync and async views\n- [x] Permission extension using django's permissioning system\n- [x] Relay support with automatic resolvers generation\n- [x] Query optimization to improve performance and avoid common pitfalls (e.g n+1)\n- [x] Debug Toolbar integration with graphiql to display metrics like SQL queries\n- [x] Unit test integration\n\n## Basic Usage\n\n```python\n# models.py\n\nfrom django.db import models\n\nclass Fruit(models.Model):\n    \"\"\"A tasty treat\"\"\"\n    name = models.CharField(\n        max_length=20,\n    )\n    color = models.ForeignKey(\n        \"Color\",\n        on_delete=models.CASCADE,\n        related_name=\"fruits\",\n        blank=True,\n        null=True,\n    )\n\nclass Color(models.Model):\n    name = models.CharField(\n        max_length=20,\n        help_text=\"field description\",\n    )\n```\n\n```python\n# types.py\n\nimport strawberry_django\nfrom strawberry import auto\n\nfrom . import models\n\n@strawberry_django.type(models.Fruit)\nclass Fruit:\n    id: auto\n    name: auto\n    color: 'Color'\n\n@strawberry_django.type(models.Color)\nclass Color:\n    id: auto\n    name: auto\n    fruits: list[Fruit]\n```\n\n```python\n# schema.py\n\nimport strawberry\nimport strawberry_django\nfrom strawberry_django.optimizer import DjangoOptimizerExtension\n\nfrom .types import Fruit\n\n@strawberry.type\nclass Query:\n    fruits: list[Fruit] = strawberry_django.field()\n\nschema = strawberry.Schema(\n    query=Query,\n    extensions=[\n        DjangoOptimizerExtension,  # not required, but highly recommended\n    ],\n)\n```\n\n```python\n# urls.py\n\nfrom django.urls import include, path\nfrom strawberry.django.views import AsyncGraphQLView\n\nfrom .schema import schema\n\nurlpatterns = [\n    path('graphql', AsyncGraphQLView.as_view(schema=schema)),\n]\n```\n\nCode above generates following schema.\n\n```graphql\n\"\"\"\nA tasty treat\n\"\"\"\ntype Fruit {\n  id: ID!\n  name: String!\n  color: Color\n}\n\ntype Color {\n  id: ID!\n  \"\"\"\n  field description\n  \"\"\"\n  name: String!\n  fruits: [Fruit!]\n}\n\ntype Query {\n  fruits: [Fruit!]!\n}\n```\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Strawberry GraphQL Django extension",
    "version": "0.39.2",
    "project_urls": {
        "Documentation": "https://strawberry-graphql.github.io/strawberry-django",
        "Homepage": "https://github.com/strawberry-graphql/strawberry-django",
        "Repository": "https://github.com/strawberry-graphql/strawberry-django"
    },
    "split_keywords": [
        "graphql",
        " api",
        " django",
        " strawberry-graphql"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "1e1e5bad4092c8c56521d7f433ca2764c37333996ebca6d4844086f35cc4f08b",
                "md5": "cd2c6b17fa92ff8f9734646021203742",
                "sha256": "29c4294391b16f5733afbf05da0c5d20b62ca68a195219a07d6e1ea3a4219f6b"
            },
            "downloads": -1,
            "filename": "strawberry_graphql_django-0.39.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "cd2c6b17fa92ff8f9734646021203742",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.8",
            "size": 84457,
            "upload_time": "2024-04-25T22:35:52",
            "upload_time_iso_8601": "2024-04-25T22:35:52.117270Z",
            "url": "https://files.pythonhosted.org/packages/1e/1e/5bad4092c8c56521d7f433ca2764c37333996ebca6d4844086f35cc4f08b/strawberry_graphql_django-0.39.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "45361da92a2565877baca6bc81671967fecc55b8d8be6062dd41a4b6f9b12598",
                "md5": "62919eda5ae0c3f40993c602b0edb30b",
                "sha256": "673025c261e547787b2e452e757867df81a8ac163ed82160c5e4b7e79e1b6435"
            },
            "downloads": -1,
            "filename": "strawberry_graphql_django-0.39.2.tar.gz",
            "has_sig": false,
            "md5_digest": "62919eda5ae0c3f40993c602b0edb30b",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.8",
            "size": 68979,
            "upload_time": "2024-04-25T22:35:54",
            "upload_time_iso_8601": "2024-04-25T22:35:54.374205Z",
            "url": "https://files.pythonhosted.org/packages/45/36/1da92a2565877baca6bc81671967fecc55b8d8be6062dd41a4b6f9b12598/strawberry_graphql_django-0.39.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-04-25 22:35:54",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "strawberry-graphql",
    "github_project": "strawberry-django",
    "travis_ci": false,
    "coveralls": true,
    "github_actions": true,
    "lcname": "strawberry-graphql-django"
}
        
Elapsed time: 0.23722s