Skip to content

Commit

Permalink
Merge pull request #132 from tOgg1/develop
Browse files Browse the repository at this point in the history
Prepare release v0.12.0
  • Loading branch information
tOgg1 authored Jul 3, 2024
2 parents 5a8b359 + 683a97c commit fc45ccd
Show file tree
Hide file tree
Showing 22 changed files with 571 additions and 273 deletions.
16 changes: 0 additions & 16 deletions .github/workflows/pre-commit.yml

This file was deleted.

31 changes: 14 additions & 17 deletions .github/workflows/primary.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,18 @@ on:
jobs:
test:

runs-on: ubuntu-20.04
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.7", "3.8", "3.9", "3.10"]
poetry-version: ["1.3.1"]
python-version: [ "3.9", "3.10", "3.11", "3.12" ]
poetry-version: [ "1.8.3" ]

steps:
- uses: actions/checkout@v2
- name: Run image
uses: abatilo/[email protected]
with:
poetry-version: ${{ matrix.poetry-version }}

- uses: actions/checkout@v4
- name: Install Poetry
uses: snok/install-poetry@v1
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: 'poetry'
Expand All @@ -36,23 +33,23 @@ jobs:
release:
needs: test
if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags')
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: 3.9
python-version: 3.12
- name: Install Poetry
uses: snok/install-poetry@v1
- name: Install dependencies
run: |
pip install twine
pip install poetry==1.1.4
pip install wheel
poetry config virtualenvs.create false
poetry install --no-interaction
poetry install
- name: Build package
run: make build
- name: Publish package
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ repos:
exclude: (migrations/|locale/|docs/)
args:
- --line-length=120
- repo: https://gitlab.com/pycqa/flake8
- repo: https://github.com/pycqa/flake8
rev: 3.9.2
hooks:
- id: flake8
Expand Down
56 changes: 56 additions & 0 deletions docs/guide/nested-fields.rst
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,62 @@ populator of the relationship.
If you don't have an existing type for creating a user, e.g. the "CreateCatInput" we used above,
you can set the type to "auto", which will create a new type.

Many to many with `through` models
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The way Django handles a `through` model internally is functionally similar to using many to one relationships. This
implies that the more convienient option is to use `many_to_one_extras` instead of `many_to_many_extras` when dealing
with `through` models.

If you have a many to many relationship with a `through` model, you can use
a `many_to_one_extras` field to specify how to handle the `through` model.
Due to how the m2m fields are automatically generated using the input schema, it is recommended to use the
`many_to_one_extras` field instead of the `many_to_many_extras` field.

Suppose we have a `Dog` model with a many to many relationship
with a `Cat` model, but we want to keep track of the number of times a dog
has fought a cat. We can do this with a `through` model:

.. code:: python
class Dog(models.Model):
owner = models.ForeignKey(User, null=True, on_delete=models.SET_NULL)
name = models.TextField()
fights = models.ManyToManyField(Cat, through='Fight')
class Fight(models.Model):
dog = models.ForeignKey(Dog, on_delete=models.CASCADE, related_name='fights')
cat = models.ForeignKey(Cat, on_delete=models.CASCADE, related_name='fights')
times = models.IntegerField(default=0)
We can then create a mutation to create a dog, and add a fight to it:

.. code:: python
class CreateDogMutation(DjangoCreateMutation):
class Meta:
model = Dog
many_to_one_extras = {
'fights': {
'exact': {"type": "auto"}
}
}
This will infer the dog's ID, and allows us to create a fight in the same
mutation:

.. code::
mutation {
createDog(input: {
name: "Buster",
fights: [{cat: "Q2F0Tm9kZTox", times: 1}]
}}){
dog{
...DogInfo
}
}
}
One to one extras
~~~~~~~~~~~~~~~~~

Expand Down
Loading

0 comments on commit fc45ccd

Please sign in to comment.