Coder Social home page Coder Social logo

Comments (10)

cockscomb avatar cockscomb commented on July 29, 2024 27

I found a test case of passing context.

@pytest.mark.parametrize('app', [create_app(get_context=lambda:"CUSTOM CONTEXT")])

I succeeded passing custom context in the following way.

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

from flask-graphql.

dbasden avatar dbasden commented on July 29, 2024 4

There seem to be changes in graphql-server-core and flask-graphql to change unit tests :
"Improved query execution using pluggable backend" in graphql-server-core e.g.:
graphql-python/graphql-server@d60b180

There is an underlying change in graphql-python/graphql-core@f6d79ab
in the commit "Modernize execute function" around graphql-core v2.1.0

This is where "context_value" is deprecated for "context"

graphql-python/graphql-core@f6d79ab

It looks like "context" is now not what is being passed by the user of flask-graphql, but a Request object instead. Maybe there is a name collision in flask-graphql?

from flask-graphql.

dbasden avatar dbasden commented on July 29, 2024 2

It looks like the breaking change was actually a long time ago, but was only put out in a full release recently:

d728f80

I don't know if the behaviour of "context_value" was meant to go away and the documentation was left unchanged?

Edit: This also seems to be referenced in the last comment (made after merge) of #19

from flask-graphql.

jjwtay avatar jjwtay commented on July 29, 2024 2

Cannot speak to why they would have possibly removed it but I can say for now I just am using this to work around.

class MyGraphQLView(GraphQLView):
   def get_context(self):
       context = super().get_context()
       context.session = db.session

       return context

from flask-graphql.

Tryph avatar Tryph commented on July 29, 2024 1

@cockscomb It works perfectly thanks for sharing this

from flask-graphql.

vlad-bezden avatar vlad-bezden commented on July 29, 2024

I'm having the same problem. I tried to use context and context_value and neither of them works.

from flask-graphql.

jjwtay avatar jjwtay commented on July 29, 2024

same

from flask-graphql.

rscarrera27 avatar rscarrera27 commented on July 29, 2024

same

from flask-graphql.

jw3126 avatar jw3126 commented on July 29, 2024

Is there a recommended way to do the things that were done by using context in older versions? I have seen the suggestion to restore the old context behaviour by inheritence. But I guess context was removed for a reason (btw what reason?), so there may be a better way?

from flask-graphql.

jw3126 avatar jw3126 commented on July 29, 2024

Ah thanks! This was what I meant by "restore the old context behavior by inheritance".

from flask-graphql.

Related Issues (20)

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.