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

Upgrade to graphql-core v3 #42

Open
fhennig opened this issue Sep 29, 2020 · 2 comments · May be fixed by #61
Open

Upgrade to graphql-core v3 #42

fhennig opened this issue Sep 29, 2020 · 2 comments · May be fixed by #61

Comments

@fhennig
Copy link
Contributor

fhennig commented Sep 29, 2020

Graphene's update to v3 is stabilizing. For flask, it is already possible to operate with pre-release packages (graphene v.3.0b5, graphql-server[flask] v3.0.0b1), for graphql-django the upgrade to v3 is in progress: graphql-python/graphene-django#705.

@leahein
Copy link

leahein commented May 25, 2021

Is there an update on this? I've submitted PR #61 that should resolve this.

@Kulv3r
Copy link

Kulv3r commented Aug 27, 2024

Hacky workaround for anyone searching for it:

make an extra file called graphene_file_upload_fix.py, paste this into it:

import sys
from importlib.abc import MetaPathFinder, Loader
from importlib.machinery import ModuleSpec

import graphql_server.flask


class GrapheneFileUploadImportHook(MetaPathFinder, Loader):
    """
    Since we can't modify `graphene_file_upload` lib directly and
    it's still trying to import from `flask_graphql` (since not maintained),
    we can achieve this by manipulating Python's module import system
    to intercept and redirect imports from `flask_graphql` to `graphql_server.flask`.
    This method is a bit hacky but works well for this issue.

    Import this module before importing `graphene_file_upload`.
    """
    def find_spec(self, fullname, path, target=None):
        if fullname == 'flask_graphql':
            return ModuleSpec(fullname, self, is_package=False)

    def create_module(self, spec):
        # Since flask_graphql doesn't exist, we're going to redirect it to graphql_server.flask
        return sys.modules.setdefault(spec.name, sys.modules['graphql_server.flask'])

    def exec_module(self, module):
        # No module execution needed as we're aliasing to an existing module
        pass


# Add the custom import hook to the beginning of the meta path finder list
sys.meta_path.insert(0, GrapheneFileUploadImportHook())

it's for Flask, but you can easily adjust it for Django or whatnot

then import it BEFORE you 1st time import graphene-file-upload
in my case i import it in app.py, as a 1st line.

that's it.

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

Successfully merging a pull request may close this issue.

3 participants