graphene-sqlalchemy icon indicating copy to clipboard operation
graphene-sqlalchemy copied to clipboard

Examples don't work

Open Morreski opened this issue 8 years ago • 7 comments

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 avatar Jan 11 '17 16:01 Morreski

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

kelvintaywl avatar Jan 22 '17 07:01 kelvintaywl

@syrusakbary @jhgg

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

rcatlin avatar Jan 15 '18 01:01 rcatlin

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

cmmp avatar Jan 18 '18 15:01 cmmp

Same problem

NathanBWaters avatar Apr 08 '18 23:04 NathanBWaters

Same problem. @Morreski 's tip worked.

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

alexmolodchikov avatar Apr 13 '18 03:04 alexmolodchikov

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 https://github.com/graphql-python/flask-graphql/issues/52#issuecomment-412773200

yoursdearboy avatar Nov 12 '18 12:11 yoursdearboy

@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.

valhuber avatar Dec 04 '20 01:12 valhuber