question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Examples don't work

See original GitHub issue

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.

Issue Analytics

  • State:open
  • Created 7 years ago
  • Reactions:16
  • Comments:7

github_iconTop GitHub Comments

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

1reaction
valhubercommented, 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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

examples don't work - Help
Hi, I just clone the Timeline JS project through the github. I find there is an example folder in the project and it...
Read more >
examples don't work at all.
examples don't work at all. In the exercise Manipulating HTML the four boxes do not do anything when i hover over or click...
Read more >
Why examples don't work? (a struggle with imports)
At first two problems appeared easy to fix: SyntaxError: import declarations may only appear at top level of a module; The character encoding...
Read more >
`with-react-native-web` example doesn't work · Issue #1919
The example should work in order for developers to learn and explore how things are wired up. Furthermore, the example is using the...
Read more >
What are some examples of C code that doesn't work when ...
What are some examples of C code that doesn't work when compiled in a C++ compiler?
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found