• Stars
    star
    285
  • Rank 140,225 (Top 3 %)
  • Language
    Python
  • License
    MIT License
  • Created over 6 years ago
  • Updated about 1 month ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Graphene MongoEngine integration

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 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_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

More Repositories

1

graphene

GraphQL framework for Python
Python
7,978
star
2

graphene-django

Build powerful, efficient, and flexible GraphQL APIs with seamless Django integration.
Python
4,235
star
3

gql

A GraphQL client in Python
Python
1,474
star
4

flask-graphql

Adds GraphQL support to your Flask application.
Python
1,316
star
5

graphene-sqlalchemy

Graphene SQLAlchemy integration
Python
971
star
6

graphql-core

A Python 3.6+ port of the GraphQL.js reference implementation of GraphQL.
Python
498
star
7

graphql-core-legacy

GraphQL base implementation for Python (legacy version – see graphql-core for the current one)
Python
375
star
8

graphql-ws

GraphQL websockets
Python
271
star
9

graphene-pydantic

Integrate GraphQL with your Pydantic models
Python
220
star
10

swapi-graphene

GraphQL Starwars API using Graphene and Django
Python
172
star
11

sanic-graphql

Adds GraphQL support to your Sanic app.
Python
149
star
12

graphql-relay-py

A library to help construct a graphql-py server supporting react-relay
Python
145
star
13

aiohttp-graphql

Adds GraphQL support to your aiohttp app.
Python
118
star
14

graphene-gae

GraphQL Support for Google AppEngine [DEPRECATED - Looking for maintainers]
Python
117
star
15

graphql-server

This is the core package for using GraphQL in a custom server easily
Python
114
star
16

gql-next

A Python GraphQL Client library providing ability to validate and make type-safe GraphQL calls
Python
76
star
17

graphene-tornado

Python
52
star
18

graphene-federation

Federation implementation for Graphene.
Python
40
star
19

webob-graphql

GraphQL integration for WebOb based frameworks: Pyramid, Pylons...
Python
28
star
20

GraphQL-SublimeText

GraphQL language syntax for SublimeText
17
star
21

graphene-python.org

Graphene-Python.org official website
JavaScript
6
star