Skip to main content

Graphene Mongoengine integration

Project description

https://travis-ci.org/graphql-python/graphene-mongo.svg?branch=master https://coveralls.io/repos/github/graphql-python/graphene-mongo/badge.svg?branch=master https://badge.fury.io/py/graphene-mongo.svg https://img.shields.io/pypi/pyversions/graphene-mongo.svg

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


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.11.tar.gz (19.3 kB view details)

Uploaded Source

File details

Details for the file graphene-mongo-0.2.11.tar.gz.

File metadata

  • Download URL: graphene-mongo-0.2.11.tar.gz
  • Upload date:
  • Size: 19.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: Python-urllib/2.7

File hashes

Hashes for graphene-mongo-0.2.11.tar.gz
Algorithm Hash digest
SHA256 2e5974f5f9a4228764e1f5a3f78c411fc97f7f76cee74bb144f6e93308fc212d
MD5 f0fe2603c1759a91b0a27d8d902569be
BLAKE2b-256 62f073c56be16d07934394c02aafa8676f3b5105db5d7352621417c8847f1a8e

See more details on using hashes here.

Provenance

Supported by

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