Skip to main content

Graphene Mongoengine integration

Project description

Build Status Coverage Status Documentation Status PyPI version PyPI pyversions Downloads

Lint Test Package

Graphene-Mongo

A Mongoengine integration for Graphene.

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:

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:

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:

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:

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:

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

To learn more check out the following examples:

Contributing

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

pip install -r requirements.txt

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

make test

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

graphene_mongo-0.4.5.tar.gz (20.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

graphene_mongo-0.4.5-py3-none-any.whl (29.9 kB view details)

Uploaded Python 3

File details

Details for the file graphene_mongo-0.4.5.tar.gz.

File metadata

  • Download URL: graphene_mongo-0.4.5.tar.gz
  • Upload date:
  • Size: 20.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for graphene_mongo-0.4.5.tar.gz
Algorithm Hash digest
SHA256 aab35d29032228f2cbc22048e462ab43b356f5f1724ae17f0295be048b0bda3a
MD5 597d57ec47d6109a90ff20481c1130b6
BLAKE2b-256 b2b4b7790abd2bd5c6b4b512cec7b36814a62c93a66cda462afa2c4632ed459f

See more details on using hashes here.

Provenance

The following attestation bundles were made for graphene_mongo-0.4.5.tar.gz:

Publisher: publish.yml on graphql-python/graphene-mongo

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file graphene_mongo-0.4.5-py3-none-any.whl.

File metadata

  • Download URL: graphene_mongo-0.4.5-py3-none-any.whl
  • Upload date:
  • Size: 29.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for graphene_mongo-0.4.5-py3-none-any.whl
Algorithm Hash digest
SHA256 7c1528cea7d95a49303505f5cd4f7dc68a2d1936a1589b28d5380873afe37590
MD5 d62a176039534ea87461b1dd8078afc6
BLAKE2b-256 4f91ecc339af039c63a217de2cdb33419c6dad92668c54492dcb5e4033873408

See more details on using hashes here.

Provenance

The following attestation bundles were made for graphene_mongo-0.4.5-py3-none-any.whl:

Publisher: publish.yml on graphql-python/graphene-mongo

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page