graphene-mongo


Namegraphene-mongo JSON
Version 0.4.3 PyPI version JSON
download
home_pagehttps://github.com/graphql-python/graphene-mongo
SummaryGraphene Mongoengine integration
upload_time2024-03-20 12:20:24
maintainerNone
docs_urlNone
authorAbaw Chen
requires_python<4,>=3.8
licenseMIT
keywords graphene-mongo graphql api graphql protocol relay graphene mongo mongoengine
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            [![Build Status](https://travis-ci.org/graphql-python/graphene-mongo.svg?branch=master)](https://travis-ci.org/graphql-python/graphene-mongo) [![Coverage Status](https://coveralls.io/repos/github/graphql-python/graphene-mongo/badge.svg?branch=master)](https://coveralls.io/github/graphql-python/graphene-mongo?branch=master) [![Documentation Status](https://readthedocs.org/projects/graphene-mongo/badge/?version=latest)](http://graphene-mongo.readthedocs.io/en/latest/?badge=latest) [![PyPI version](https://badge.fury.io/py/graphene-mongo.svg)](https://badge.fury.io/py/graphene-mongo) [![PyPI pyversions](https://img.shields.io/pypi/pyversions/graphene-mongo.svg)](https://pypi.python.org/pypi/graphene-mongo/) [![Downloads](https://pepy.tech/badge/graphene-mongo)](https://pepy.tech/project/graphene-mongo)

[![Lint](https://github.com/graphql-python/graphene-mongo/actions/workflows/lint.yml/badge.svg?branch=master)](https://github.com/graphql-python/graphene-mongo/actions/workflows/lint.yml) [![Test Package](https://github.com/graphql-python/graphene-mongo/actions/workflows/ci.yml/badge.svg)](https://github.com/graphql-python/graphene-mongo/actions/workflows/ci.yml)

# Graphene-Mongo

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

```
pip install graphene-mongo
```

## Examples

Here is a simple Mongoengine model as `models.py`:

```python
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 and sync executor; for it you simply have to write the following:

```python
import graphene

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())


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 graphene_mongo.utils 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)
```

Then you can simply query the schema:

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

To learn more check out the following [examples](examples/):

* [Flask MongoEngine example](examples/flask_mongoengine)
* [Django MongoEngine example](examples/django_mongoengine)
* [Falcon MongoEngine example](examples/falcon_mongoengine)

## Contributing

After cloning this repo, ensure dependencies are installed by running:

```sh
pip install -r requirements.txt
```

After developing, the full test suite can be evaluated by running:

```sh
make test
```


            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/graphql-python/graphene-mongo",
    "name": "graphene-mongo",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4,>=3.8",
    "maintainer_email": null,
    "keywords": "graphene-mongo, graphql, api, graphql, protocol, relay, graphene, mongo, mongoengine",
    "author": "Abaw Chen",
    "author_email": "abaw.chen@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/30/ab/078b9c36b5518f185e3d1bbf01ac360ee154a1dc876489a2c0f1a791b479/graphene_mongo-0.4.3.tar.gz",
    "platform": null,
    "description": "[![Build Status](https://travis-ci.org/graphql-python/graphene-mongo.svg?branch=master)](https://travis-ci.org/graphql-python/graphene-mongo) [![Coverage Status](https://coveralls.io/repos/github/graphql-python/graphene-mongo/badge.svg?branch=master)](https://coveralls.io/github/graphql-python/graphene-mongo?branch=master) [![Documentation Status](https://readthedocs.org/projects/graphene-mongo/badge/?version=latest)](http://graphene-mongo.readthedocs.io/en/latest/?badge=latest) [![PyPI version](https://badge.fury.io/py/graphene-mongo.svg)](https://badge.fury.io/py/graphene-mongo) [![PyPI pyversions](https://img.shields.io/pypi/pyversions/graphene-mongo.svg)](https://pypi.python.org/pypi/graphene-mongo/) [![Downloads](https://pepy.tech/badge/graphene-mongo)](https://pepy.tech/project/graphene-mongo)\n\n[![Lint](https://github.com/graphql-python/graphene-mongo/actions/workflows/lint.yml/badge.svg?branch=master)](https://github.com/graphql-python/graphene-mongo/actions/workflows/lint.yml) [![Test Package](https://github.com/graphql-python/graphene-mongo/actions/workflows/ci.yml/badge.svg)](https://github.com/graphql-python/graphene-mongo/actions/workflows/ci.yml)\n\n# Graphene-Mongo\n\nA [Mongoengine](https://mongoengine-odm.readthedocs.io/) integration for [Graphene](http://graphene-python.org/).\n\n## Installation\n\nFor installing graphene-mongo, just run this command in your shell\n\n```\npip install graphene-mongo\n```\n\n## Examples\n\nHere is a simple Mongoengine model as `models.py`:\n\n```python\nfrom mongoengine import Document\nfrom mongoengine.fields import StringField\n\n\nclass User(Document):\n    meta = {'collection': 'user'}\n    first_name = StringField(required=True)\n    last_name = StringField(required=True)\n```\n\nTo create a GraphQL schema and sync executor; for it you simply have to write the following:\n\n```python\nimport graphene\n\nfrom graphene_mongo import MongoengineObjectType\n\nfrom .models import User as UserModel\n\n\nclass User(MongoengineObjectType):\n    class Meta:\n        model = UserModel\n\n\nclass Query(graphene.ObjectType):\n    users = graphene.List(User)\n\n    def resolve_users(self, info):\n        return list(UserModel.objects.all())\n\n\nschema = graphene.Schema(query=Query)\n```\n\nThen you can simply query the schema:\n\n```python\nquery = '''\n    query {\n        users {\n            firstName,\n            lastName\n        }\n    }\n'''\nresult = await schema.execute(query)\n```\n\nTo create a GraphQL schema and async executor; for it you simply have to write the following:\n\n```python\nimport graphene\n\nfrom graphene_mongo import AsyncMongoengineObjectType\nfrom graphene_mongo.utils import sync_to_async\nfrom concurrent.futures import ThreadPoolExecutor\n\nfrom .models import User as UserModel\n\n\nclass User(AsyncMongoengineObjectType):\n    class Meta:\n        model = UserModel\n\n\nclass Query(graphene.ObjectType):\n    users = graphene.List(User)\n\n    async def resolve_users(self, info):\n        return await sync_to_async(list, thread_sensitive=False,\n                             executor=ThreadPoolExecutor())(UserModel.objects.all())\n\n\nschema = graphene.Schema(query=Query)\n```\n\nThen you can simply query the schema:\n\n```python\nquery = '''\n    query {\n        users {\n            firstName,\n            lastName\n        }\n    }\n'''\nresult = await schema.execute_async(query)\n```\n\nTo learn more check out the following [examples](examples/):\n\n* [Flask MongoEngine example](examples/flask_mongoengine)\n* [Django MongoEngine example](examples/django_mongoengine)\n* [Falcon MongoEngine example](examples/falcon_mongoengine)\n\n## Contributing\n\nAfter cloning this repo, ensure dependencies are installed by running:\n\n```sh\npip install -r requirements.txt\n```\n\nAfter developing, the full test suite can be evaluated by running:\n\n```sh\nmake test\n```\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Graphene Mongoengine integration",
    "version": "0.4.3",
    "project_urls": {
        "Homepage": "https://github.com/graphql-python/graphene-mongo",
        "Repository": "https://github.com/graphql-python/graphene-mongo"
    },
    "split_keywords": [
        "graphene-mongo",
        " graphql",
        " api",
        " graphql",
        " protocol",
        " relay",
        " graphene",
        " mongo",
        " mongoengine"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "bfbd45d36bc18c5f57a791029302d624841d843b681730781be3e925d345f3ef",
                "md5": "09e283c383845a96038159e4eee934e0",
                "sha256": "61439a496682e4f257594096739907172327b36f1626da77e9e8e40cc9545ba6"
            },
            "downloads": -1,
            "filename": "graphene_mongo-0.4.3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "09e283c383845a96038159e4eee934e0",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4,>=3.8",
            "size": 89749,
            "upload_time": "2024-03-20T12:20:22",
            "upload_time_iso_8601": "2024-03-20T12:20:22.131273Z",
            "url": "https://files.pythonhosted.org/packages/bf/bd/45d36bc18c5f57a791029302d624841d843b681730781be3e925d345f3ef/graphene_mongo-0.4.3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "30ab078b9c36b5518f185e3d1bbf01ac360ee154a1dc876489a2c0f1a791b479",
                "md5": "123f1b30f4a3b3681c7e0fa1732a1bc4",
                "sha256": "80897cfb596b82d3b2f19543335b53269709ac0d26684d63e652c367b7c52170"
            },
            "downloads": -1,
            "filename": "graphene_mongo-0.4.3.tar.gz",
            "has_sig": false,
            "md5_digest": "123f1b30f4a3b3681c7e0fa1732a1bc4",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4,>=3.8",
            "size": 78113,
            "upload_time": "2024-03-20T12:20:24",
            "upload_time_iso_8601": "2024-03-20T12:20:24.815873Z",
            "url": "https://files.pythonhosted.org/packages/30/ab/078b9c36b5518f185e3d1bbf01ac360ee154a1dc876489a2c0f1a791b479/graphene_mongo-0.4.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-03-20 12:20:24",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "graphql-python",
    "github_project": "graphene-mongo",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "graphene-mongo"
}
        
Elapsed time: 0.36870s