graphql-python / graphql-server

This is the core package for using GraphQL in a custom server easily
MIT License
120 stars 72 forks source link

Graphql-Server + Graphene + Flask issues #79

Closed jrast closed 3 years ago

jrast commented 3 years ago

I'm trying to setup flask with graphene and graphql-server. As this is just a test which I am running, I'm using the latest beta releases:

Note: I had to use the beta versions of both packages, otherwise I run into dependency issues with graphql-core

Now I found some example which use graphql_server.flask.GraphQLView for the flask views. However, I couldnt use the graphene schema directly, I had to use schema.graphql_schema instead.

The following code is a minimal working example:

from flask import Flask
from graphene import ObjectType, String, Schema
from graphql_server.flask import GraphQLView

class Query(ObjectType):
    hello = String(name=String(default_value='stranger'))
    goodbye = String()

    def resolve_hello(root, info, name):
        return 'Hello {}'.format(name)

    def resolve_goodbye(root, info):
        return 'See ya!'

schema = Schema(query=Query)
app = Flask(__name__)

app.add_url_rule('/graphql', view_func=GraphQLView.as_view(
    'graphql',
    schema=schema.graphql_schema,  # TODO: Check what the consequences are of using the graphql_schema
    graphiql=True,
    graphiql_version='1.3.2'
))

app.add_url_rule('/graphql/batch', view_func=GraphQLView.as_view(
    'graphql_batch',
    schema=schema.graphql_schema,  # TODO: Check what the consequences are of using the graphql_schema
    batch=True
))

if __name__ == '__main__':
    app.run(host='0.0.0.0')
jrast commented 3 years ago

Nevermind: Just found a note in the docs which exactly mentiones this...

JonathanBecks commented 2 years ago

Hi @jrast ich steh auf dem Schlauch! I have the same issue but can't work it out how the docs can help me. Can you show me what you did to solve this issue?