Giter Site home page Giter Site logo

graphql-python / graphene-gae Goto Github PK

View Code? Open in Web Editor NEW
117.0 14.0 14.0 183 KB

GraphQL Support for Google AppEngine [DEPRECATED - Looking for maintainers]

Home Page: http://docs.graphene-python.org/projects/gae/en/latest/

License: BSD 3-Clause "New" or "Revised" License

Makefile 3.63% Python 96.37%
graphql graphene google-appengine python

graphene-gae's Introduction

Graphene GAE (deprecated!)

โš ๏ธ This repository is deprecated due to lack of maintainers. If you're interested in taking over let us know via the Graphene Slack

A Google AppEngine integration library for Graphene

Upgrade Notes

If you're upgrading from an older version (pre 2.0 version) please check out the Graphene Upgrade Guide.

Installation

To install Graphene-GAE on your AppEngine project, go to your project folder and runthis command in your shell:

pip install graphene-gae -t ./libs

This will install the library and its dependencies to the libs folder under your projects root - so the dependencies get uploaded withyour GAE project when you publish your app.

Make sure the libs folder is in your python path by adding the following to your `appengine_config.py`:

import sys

for path in ['libs']:
    if path not in sys.path:
        sys.path[0:0] = [path]

Examples

Here's a simple GAE model:

class Article(ndb.Model):
    headline = ndb.StringProperty()
    summary = ndb.TextProperty()
    text = ndb.TextProperty()

    author_key = ndb.KeyProperty(kind='Author')

    created_at = ndb.DateTimeProperty(auto_now_add=True)
    updated_at = ndb.DateTimeProperty(auto_now=True)

To create a GraphQL schema for it you simply have to write the following:

import graphene
from graphene_gae import NdbObjectType

class ArticleType(NdbObjectType):
    class Meta:
        model = Article

class QueryRoot(graphene.ObjectType):
    articles = graphene.List(ArticleType)

    @graphene.resolve_only_args
    def resolve_articles(self):
        return Article.query()

schema = graphene.Schema(query=QueryRoot)

Then you can simply query the schema:

query = '''
    query GetArticles {
      articles {
        headline,
        summary,
        created_at
      }
    }
'''
result = schema.execute(query)

To learn more check out the following examples:

Contributing

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

make deps
make install

Make sure tests and lint are running:

make test
make lint

graphene-gae's People

Contributors

diegodf avatar ekampf avatar emsu avatar erikwrede avatar jkimbo avatar mdornseif avatar nolanw avatar sheenarbw avatar syrusakbary avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

graphene-gae's Issues

How do you filter?

I know that with graphene Django you can use filter fields but, what about if were using NDBObjectType
is there a way to still use filters??

class SearchPropertyType(NdbObjectType):
class Meta:
model = SearchPropertyModel
fields = ["points"]
interfaces = (relay.Node,)

app.yaml handlers?

I'm pretty new to Google App Engine.

What do I need to add to the handlers section of app.yaml to make it work?

NDBConnectionField

Curious, is it possible to return a list in the resolver of a ndbConnectionField?
It only lets me return a ndb.Query, I think this has to do with it needing ndb_iter()?
Any clairification on this would be great!

class Query(graphene.ObjectType):
    properties = NdbConnectionField(SearchPropertyType, filter=graphene.Argument(Filters, required=False, default_value=None))

    def resolve_properties(self, info, **kwargs):
       list = ndb.get_mult(list_of_keys)
       return list

KeyProperty not showing up in schema

Hi all, this library has a lot of promise nice work so far!

I've noticed that my KeyProperties aren't showing up when I inspect the resulting schema. Maybe there's something that I'm missing that to-be-completed docs would reveal?

the code I'm testing the library with:

Model Definition:

class AuthorizeNetConnection(ndb.Model):
    usr = ndb.KeyProperty(kind='CEUser')
    account_nickname = ndb.StringProperty(indexed=False)
    api_login_id = ndb.StringProperty(indexed=False)
    api_transaction_key = ndb.StringProperty(indexed=False)
    active = ndb.BooleanProperty(default=True)

Type Definition:

class ConnectionType(NdbObjectType):

    class Meta:
        model = datamodel.AuthorizeNetConnection

Introspection result:

{
  "invalid": false,
  "data": {
    "__type": {
      "name": "ConnectionType",
      "kind": "OBJECT",
      "fields": [
        {
          "name": "account_nickname"
        },
        {
          "name": "active"
        },
        {
          "name": "api_login_id"
        },
        {
          "name": "api_transaction_key"
        },
        {
          "name": "ndb_id"
        }
      ]
    }
  },
  "errors": []
}

PolyModel

PolyModels current don't work because the type check in complete_object_value in the graphql library.

I know your busy @ekampf but if you could give me some hints to where I would fix the type checking error that currently occurs that would be great.

Currently, I can hack it by making the graphql package ndb aware. My current lead is that somewhere I need to edit how the is_type_of function is passed to graphql so that it recognizes that child classes are the same as parent classes or at least that child classes are valid instances of the parent class.

Expected value of type "UserType" but got: User

Hi,

I try to develop simple GraphQL with graphene-gae using flask framework. But I'm getting error when I try to execute the query. The query is:

query {
    allUsers {
        username,
        email
    }
}

and the error message is Expected value of type \"UserType\" but got: User

Here is my snippet of code

user.py

from google.appengine.ext import ndb


class User(ndb.Model):
    username = ndb.StringProperty()
    email = ndb.StringProperty()
    password = ndb.StringProperty()
    created_at = ndb.DateTimeProperty(auto_now_add=True)
    updated_at = ndb.DateTimeProperty(auto_now=True)

schema.py

import graphene

from graphene_gae import NdbObjectType
from user import User


class UserType(NdbObjectType):
    class Meta:
        model = User


class Query(graphene.ObjectType):
    all_users = graphene.List(UserType)

    def resolve_all_users(self, info):
        return User.query()


schema = graphene.Schema(query=Query)

I'm using graphene-gae 2.0.dev2017073101

TimeProperty

NDB has support for TimeProperty but it seems to be missing.

In https://github.com/graphql-python/graphene-gae/blob/master/graphene_gae/ndb/converter.py#L129 I see:

converters = {
    ndb.StringProperty: convert_ndb_string_property,
    ndb.TextProperty: convert_ndb_string_property,
    ndb.BooleanProperty: convert_ndb_boolean_property,
    ndb.IntegerProperty: convert_ndb_int_property,
    ndb.FloatProperty: convert_ndb_float_property,
    ndb.JsonProperty: convert_ndb_json_property,
    ndb.DateProperty: convert_ndb_datetime_property,
    ndb.DateTimeProperty: convert_ndb_datetime_property,
    ndb.KeyProperty: convert_ndb_key_propety,
    ndb.StructuredProperty: convert_local_structured_property,
    ndb.LocalStructuredProperty: convert_local_structured_property,
    ndb.ComputedProperty: convert_computed_property
}

Is it as simple as just adding ndb.TimeProperty: convert_ndb_datetime_property?

Version bump?

The last release version is over a year old and of the 192 commits, there are around 76 that have happened since then.

Could we find a place to cut a newer release?

Is it possible to use google-cloud-ndb with this package?

I know this package supports ndb w/ AppEngine. However, wondering if we could use graphene to support ndb from google-cloud-ndb?

The difference i've seen so far between the two is google-cloud-ndb requries a client.context() for each query and mutation

Passing query as JSON (for variables, etc.) seems broken

I'm very new to this GraphQL world but my understanding of GraphQL is that, in order to pass variables or operation_name in addition to query, the body of POST has to be encoded in JSON. A GraphQL query HTML body, with a pair of query and variables, would look like:

{ "query": "...", "variables": "..." }

This does not seem to work with graphene-gae. I put many logging.warn()'s in _get_grapl_params() but could not understand the intent. If the said assumption that GraphQL query body is either raw GraphQL or JSON, this _get_grapl_params() would look like:

    def _get_grapl_params(self):
        try:
            (read body as JSON)
        except:
            (read body as raw GraphQL)

(I even have no idea why this handler has to be implemented in graphene-gae, not graphene.)

I'm trying to fix this myself, but I'm slow; new to Python, new to GraphQL, new to Web world. Feel free to beat me. ;)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.