Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Examples don't work #30

Open
Morreski opened this issue Jan 11, 2017 · 7 comments
Open

Examples don't work #30

Morreski opened this issue Jan 11, 2017 · 7 comments

Comments

@Morreski
Copy link

Hi,

I followed the flask-sqlalchemy examples here (and the snippets in the project's Readme as well) but it didn't work out of the box. I had the following exception: AttributeError: 'Request' object has no attribute 'get' when trying to request from Graphiql.

After some fiddling with flask-sqlalchemy i solved the bug by passing a context argument to GraphQLView.as_view.

Here is my full url declaration:

app.add_url_rule(                                                                   
    '/graphql',                                                                     
    view_func=GraphQLView.as_view(                                                  
        'graphql',                                                                  
        schema=schema,                                                              
        graphiql=True,                                                         
        context={'session': db_session}                                             
    ),                                                                              
)

I don't know if this is the proper way to fix the problem, but thought it'll be useful to tell you about it.

@Morreski Morreski changed the title Examples doesn't work Examples don't work Jan 11, 2017
@kelvintaywl
Copy link

I faced similar issues as well and @Morreski 's example helped me fix the issue somewhat.

@rcatlin
Copy link

rcatlin commented Jan 15, 2018

@syrusakbary
@jhgg

Any plans on updating the documents or would you accept a pull request that updates the examples?

@cmmp
Copy link

cmmp commented Jan 18, 2018

Same problem for me. @Morreski solution works for me.

@NathanBWaters
Copy link

Same problem

@alexmolodchikov
Copy link

alexmolodchikov commented Apr 13, 2018

Same problem. @Morreski 's tip worked.

However this might be related as well:
http://docs.graphene-python.org/projects/sqlalchemy/en/latest/tips/

@yoursdearboy
Copy link

yoursdearboy commented Nov 12, 2018

With modern flask-graphql use get_context=lambda: {'session': db.session}:

app.add_url_rule(
  '/graphql',
  view_func=GraphQLView.as_view(
    'graphql',
    schema=schema,
    graphiql=True,
    get_context=lambda: {'session': db.session}
  )
)

See graphql-python/flask-graphql#52 (comment)

@valhuber
Copy link

valhuber commented Dec 4, 2020

@yoursdearboy Super!! Your (lambda) solution worked for me using the Dec 2020 version of graphene.

If anyone wants to explore a minimal running version, code and setup instructions are here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants