Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v0.4.0 - Async BugFixes & Optimisations #225

Merged
merged 50 commits into from
Nov 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
d273922
Fix(register): updated register_enum function support custom classes
AdithyanJothir Apr 5, 2023
b9a1f24
Merge pull request #4 from AdithyanJothir/master
adarshdigievo Apr 5, 2023
ec1c7af
Merge branch 'graphql-python:master' into master
arun-sureshkumar Apr 9, 2023
81746fb
Support Async
arunsureshkumar Apr 9, 2023
e225c5c
Convert: get_node to async
arunsureshkumar Apr 11, 2023
1f0250b
Merge branch 'graphql-python:master' into master
arunsureshkumar Apr 11, 2023
adec7f5
Merge remote-tracking branch 'origin/master' into feat(async)
arunsureshkumar Apr 11, 2023
ec3e60e
Fix: Test Case
arunsureshkumar Apr 11, 2023
5ff73e6
Bug Fix on connection_resolver
arunsureshkumar Apr 11, 2023
d473b11
Support Async
arunsureshkumar Apr 11, 2023
7c99bc1
Fix: connection_resolver
arunsureshkumar Apr 11, 2023
2fe5008
Support Async, Test Case Added
arunsureshkumar Apr 11, 2023
9581ad2
Bump Version : 0.4.0
arunsureshkumar Apr 11, 2023
6eb5d23
Merge remote-tracking branch 'origin/v0.4.0' into feat(async)
arunsureshkumar Apr 11, 2023
c5b71cf
Add asgiref to dependency
arunsureshkumar Apr 11, 2023
e5bb865
Add pytest-asyncio to dependency
arunsureshkumar Apr 11, 2023
3d183f8
Fix: Test Case
arunsureshkumar Apr 11, 2023
254cb7d
Update: README.md
arunsureshkumar Apr 11, 2023
55d9eb6
Blocking Threaded to Async
arunsureshkumar Apr 12, 2023
2b2813d
Bug Fix: Argument Parser
arunsureshkumar Apr 12, 2023
f171ddd
(Deprecated) get_resolver to wrap_resolve
arunsureshkumar Apr 12, 2023
f4a2037
Fix: Count Performance
arunsureshkumar Apr 12, 2023
ec75d29
Fix: Queryset Check
arunsureshkumar Apr 24, 2023
67de479
Optimise: Lazy Reference Resolver
arunsureshkumar Apr 28, 2023
d1d60b9
Fix: DeprecationWarnings
arunsureshkumar Apr 30, 2023
60f2273
Fix: Queryset evaluation
arunsureshkumar May 6, 2023
9be137c
feat: add support for mongo date field
mak626 Aug 1, 2023
cb56602
Merge pull request #7 from mak626/date-field-support
abhinand-c Aug 1, 2023
7f1f223
refactor: change logging level
Aug 21, 2023
bbf36fe
fix(connection_field): respects non_filter_fields when argument name …
Roshan-R Nov 21, 2023
5b0f9b9
Merge pull request #9 from Roshan-R/fix_non_filter_field
abhinand-c Nov 21, 2023
4c68df5
Merge pull request #8 from edwinjosegeorge/v0.4.0
abhinand-c Nov 21, 2023
554a0f7
refact: sync to async wrapper
mak626 Nov 21, 2023
44c47aa
chore: add ruff formatting
mak626 Nov 21, 2023
a09c174
fix: inconsistent has_next_page when pk is not sorted
mak626 Nov 21, 2023
cad8b76
fix: self.get_queryset not being async
mak626 Nov 21, 2023
e5fd8df
fix[pipeline]: add ruff remove flake8
mak626 Nov 21, 2023
b35e397
Merge remote-tracking branch 'origin/v0.4.0' into pagination-fix-v2
mak626 Nov 21, 2023
b281919
refact: filter connection
mak626 Nov 21, 2023
50642e9
refact: has_next_page logic
mak626 Nov 21, 2023
ef5c9cc
Merge pull request #11 from strollby/pagination-fix-v2
abhinand-c Nov 21, 2023
997fb9b
fix: has_next_page using limit
mak626 Nov 21, 2023
efe9b4e
Merge pull request #12 from strollby/revert-count-page
mak626 Nov 21, 2023
0472de6
fix: ci change flake8 to ruff
mak626 Nov 25, 2023
080b923
fix: convert | syntax to union type for backward compatibility
mak626 Nov 25, 2023
f71981b
chore: add support for python 12
mak626 Nov 25, 2023
11d0c8b
chore: drop support for python 3.7, add support python 3.12
mak626 Nov 25, 2023
c87361c
refact: add typings
mak626 Nov 25, 2023
8facd2c
fix: ruff lint
mak626 Nov 25, 2023
a5f7afe
chore: add setup tools for python 12 to fix mongomock ImportError: No…
mak626 Nov 25, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python: ["3.7", "3.8", "3.9", "3.10", "3.11"]
python: ["3.8", "3.9", "3.10", "3.11","3.12"]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python }}
- name: Lint with flake8
- name: Lint with ruff
run: |
python -m pip install flake8
python -m pip install ruff
make lint
- name: Install dependencies
run: |
Expand Down
10 changes: 4 additions & 6 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,15 @@ jobs:
build:
strategy:
matrix:
python: ["3.11"]
python: ["3.12"]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python }}
- name: Install dependencies
- name: Lint with ruff
run: |
python -m pip install --upgrade pip
pip install flake8
- name: Lint with flake8
run: make lint
python -m pip install ruff
make lint
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ clean:
@find . -name "__pycache__" -delete

lint:
@flake8 graphene_mongo --count --show-source --statistics
@ruff check graphene_mongo
@ruff format . --check

test: clean
pytest graphene_mongo/tests --cov=graphene_mongo --cov-report=html --cov-report=term
Expand Down
54 changes: 49 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

A [Mongoengine](https://mongoengine-odm.readthedocs.io/) integration for [Graphene](http://graphene-python.org/).


## Installation

For installing graphene-mongo, just run this command in your shell
Expand All @@ -23,13 +22,14 @@ Here is a simple Mongoengine model as `models.py`:
from mongoengine import Document
from mongoengine.fields import StringField


class User(Document):
meta = {'collection': 'user'}
first_name = StringField(required=True)
last_name = StringField(required=True)
```

To create a GraphQL schema for it you simply have to write the following:
To create a GraphQL schema and sync executor; for it you simply have to write the following:

```python
import graphene
Expand All @@ -38,15 +38,60 @@ from graphene_mongo import MongoengineObjectType

from .models import User as UserModel


class User(MongoengineObjectType):
class Meta:
model = UserModel


class Query(graphene.ObjectType):
users = graphene.List(User)

def resolve_users(self, info):
return list(UserModel.objects.all())
return list(UserModel.objects.all())


schema = graphene.Schema(query=Query)
```

Then you can simply query the schema:

```python
query = '''
query {
users {
firstName,
lastName
}
}
'''
result = await schema.execute(query)
```

To create a GraphQL schema and async executor; for it you simply have to write the following:

```python
import graphene

from graphene_mongo import AsyncMongoengineObjectType
from asgiref.sync import sync_to_async
from concurrent.futures import ThreadPoolExecutor

from .models import User as UserModel


class User(AsyncMongoengineObjectType):
class Meta:
model = UserModel


class Query(graphene.ObjectType):
users = graphene.List(User)

async def resolve_users(self, info):
return await sync_to_async(list, thread_sensitive=False,
executor=ThreadPoolExecutor())(UserModel.objects.all())


schema = graphene.Schema(query=Query)
```
Expand All @@ -71,7 +116,6 @@ To learn more check out the following [examples](examples/):
* [Django MongoEngine example](examples/django_mongoengine)
* [Falcon MongoEngine example](examples/falcon_mongoengine)


## Contributing

After cloning this repo, ensure dependencies are installed by running:
Expand Down
20 changes: 8 additions & 12 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,18 @@
master_doc = "index"

# General information about the project.
project = u"Graphene Mongo"
copyright = u"Graphene 2018"
author = u"Abaw Chen"
project = "Graphene Mongo"
copyright = "Graphene 2018"
author = "Abaw Chen"

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
#
# The short X.Y version.
version = u"0.1"
version = "0.1"
# The full version, including alpha/beta/rc tags.
release = u"0.1.2"
release = "0.1.2"

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down Expand Up @@ -275,9 +275,7 @@
# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title,
# author, documentclass [howto, manual, or own class]).
latex_documents = [
(master_doc, "Graphene.tex", u"Graphene Documentation", u"Syrus Akbary", "manual")
]
latex_documents = [(master_doc, "Graphene.tex", "Graphene Documentation", "Syrus Akbary", "manual")]

# The name of an image file (relative to this directory) to place at the top of
# the title page.
Expand Down Expand Up @@ -316,9 +314,7 @@

# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
(master_doc, "graphene_django", u"Graphene Django Documentation", [author], 1)
]
man_pages = [(master_doc, "graphene_django", "Graphene Django Documentation", [author], 1)]

# If true, show URL addresses after external links.
#
Expand All @@ -334,7 +330,7 @@
(
master_doc,
"Graphene-Django",
u"Graphene Django Documentation",
"Graphene Django Documentation",
author,
"Graphene Django",
"One line description of project.",
Expand Down
4 changes: 1 addition & 3 deletions examples/django_mongoengine/bike/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,5 @@
from graphene_django.views import GraphQLView

urlpatterns = [
path(
"graphql", csrf_exempt(GraphQLView.as_view(graphiql=True)), name="graphql-query"
)
path("graphql", csrf_exempt(GraphQLView.as_view(graphiql=True)), name="graphql-query")
]
4 changes: 1 addition & 3 deletions examples/django_mongoengine/bike_catalog/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,7 @@
# https://docs.djangoproject.com/en/2.2/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
{
"NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator"
},
{"NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator"},
{"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator"},
{"NAME": "django.contrib.auth.password_validation.CommonPasswordValidator"},
{"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator"},
Expand Down
4 changes: 1 addition & 3 deletions examples/django_mongoengine/bike_catalog/settings_test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from .settings import * # flake8: noqa

mongoengine.connect(
"graphene-mongo-test", host="mongomock://localhost", alias="default"
)
mongoengine.connect("graphene-mongo-test", host="mongomock://localhost", alias="default")
4 changes: 1 addition & 3 deletions examples/falcon_mongoengine/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
from .schema import schema


def set_graphql_allow_header(
req: falcon.Request, resp: falcon.Response, resource: object
):
def set_graphql_allow_header(req: falcon.Request, resp: falcon.Response, resource: object):
resp.set_header("Allow", "GET, POST, OPTIONS")


Expand Down
22 changes: 13 additions & 9 deletions examples/falcon_mongoengine/tests/tests.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import mongoengine
from graphene.test import Client

from examples.falcon_mongoengine.schema import schema
from .fixtures import fixtures_data

mongoengine.connect(
"graphene-mongo-test", host="mongomock://localhost", alias="default"
)
mongoengine.connect("graphene-mongo-test", host="mongomock://localhost", alias="default")


def test_category_last_1_item_query(fixtures_data):
Expand All @@ -23,7 +22,16 @@ def test_category_last_1_item_query(fixtures_data):

expected = {
"data": {
"categories": {"edges": [{"node": {"name": "Work", "color": "#1769ff"}}]}
"categories": {
"edges": [
{
"node": {
"name": "Work",
"color": "#1769ff",
}
}
]
}
}
}

Expand All @@ -45,11 +53,7 @@ def test_category_filter_item_query(fixtures_data):
}
}"""

expected = {
"data": {
"categories": {"edges": [{"node": {"name": "Work", "color": "#1769ff"}}]}
}
}
expected = {"data": {"categories": {"edges": [{"node": {"name": "Work", "color": "#1769ff"}}]}}}

client = Client(schema)
result = client.execute(query)
Expand Down
5 changes: 2 additions & 3 deletions examples/falcon_mongoengine/types.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import graphene
from graphene import relay
from graphene_mongo import MongoengineObjectType

from .models import Category, Bookmark
from graphene_mongo import MongoengineObjectType
from .models import Bookmark, Category


class CategoryType(MongoengineObjectType):
Expand Down
4 changes: 1 addition & 3 deletions examples/flask_mongoengine/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@
}
}""".strip()

app.add_url_rule(
"/graphql", view_func=GraphQLView.as_view("graphql", schema=schema, graphiql=True)
)
app.add_url_rule("/graphql", view_func=GraphQLView.as_view("graphql", schema=schema, graphiql=True))

if __name__ == "__main__":
init_db()
Expand Down
4 changes: 0 additions & 4 deletions examples/flask_mongoengine/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,21 @@


class Department(Document):

meta = {"collection": "department"}
name = StringField()


class Role(Document):

meta = {"collection": "role"}
name = StringField()


class Task(EmbeddedDocument):

name = StringField()
deadline = DateTimeField(default=datetime.now)


class Employee(Document):

meta = {"collection": "employee"}
name = StringField()
hired_on = DateTimeField(default=datetime.now)
Expand Down
13 changes: 10 additions & 3 deletions examples/flask_mongoengine/schema.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import graphene
from graphene.relay import Node
from graphene_mongo.tests.nodes import PlayerNode, ReporterNode

from graphene_mongo import MongoengineConnectionField, MongoengineObjectType
from .models import Department as DepartmentModel
Expand All @@ -20,7 +19,11 @@ class Meta:
model = RoleModel
interfaces = (Node,)
filter_fields = {
'name': ['exact', 'icontains', 'istartswith']
"name": [
"exact",
"icontains",
"istartswith",
]
}


Expand All @@ -35,7 +38,11 @@ class Meta:
model = EmployeeModel
interfaces = (Node,)
filter_fields = {
'name': ['exact', 'icontains', 'istartswith']
"name": [
"exact",
"icontains",
"istartswith",
]
}


Expand Down
8 changes: 6 additions & 2 deletions graphene_mongo/__init__.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
from .fields import MongoengineConnectionField
from .fields_async import AsyncMongoengineConnectionField

from .types import MongoengineObjectType, MongoengineInputType, MongoengineInterfaceType
from .types_async import AsyncMongoengineObjectType

__version__ = "0.1.1"

__all__ = [
"__version__",
"MongoengineObjectType",
"AsyncMongoengineObjectType",
"MongoengineInputType",
"MongoengineInterfaceType",
"MongoengineConnectionField"
]
"MongoengineConnectionField",
"AsyncMongoengineConnectionField",
]
Loading