Graphene Mongoengine integration
Project description
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 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 = schema.execute(query)
To learn more check out the Flask MongoEngine example
Project details
Release history Release notifications | RSS feed
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.2.10.tar.gz
(19.2 kB
view details)
File details
Details for the file graphene-mongo-0.2.10.tar.gz
.
File metadata
- Download URL: graphene-mongo-0.2.10.tar.gz
- Upload date:
- Size: 19.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.2.0.post20200210 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.6.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6cfeb89ff6149d2c5285cdc7316dc51b923c0235bb05eb2319dbb0c03f67f066 |
|
MD5 | b53ad74f911148c9840e632bad8ee8c0 |
|
BLAKE2b-256 | 9c63a0202a3f8f814c558b2bc8106b86d4f13f13d61d3f0ce48b9b8d97865d15 |