Graphene Mongoengine integration
Project description
Graphene-Mongo
A Mongoengine integration for Graphene.
Installation
For instaling 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.1.17.tar.gz
(13.9 kB
view details)
File details
Details for the file graphene-mongo-0.1.17.tar.gz
.
File metadata
- Download URL: graphene-mongo-0.1.17.tar.gz
- Upload date:
- Size: 13.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: Python-urllib/2.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d2944967fe1146257dcad292a0746e1d48e9898dc05cc702304ed61a08527565 |
|
MD5 | ce5de6f65a278c4248954db81e0f05a1 |
|
BLAKE2b-256 | 00550130796edeaa1af0e23e59f00044ec5bd7335cfb2ea14b4608c9d177beed |