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

TypeError: __init__() got an unexpected keyword argument 'type' #987

Open
sanchit-gupta-cn opened this issue Jan 6, 2021 · 6 comments
Open
Milestone

Comments

@sanchit-gupta-cn
Copy link

sanchit-gupta-cn commented Jan 6, 2021

Hi,
I am getting a TypeError on importing graphql_compiler.compile_graphql_to_cypher.

Stacktrace

Traceback (most recent call last):
  File "graphql_compiler_redis_test.py", line 6, in <module>
    from graphql_compiler import compile_graphql_to_cypher
  File "/env/lib/python3.6/site-packages/graphql_compiler/__init__.py", line 3, in <module>
    from .compiler import (  # noqa
  File "/env/lib/python3.6/site-packages/graphql_compiler/compiler/__init__.py", line 2, in <module>
    from .common import (  # noqa
  File "/env/lib/python3.6/site-packages/graphql_compiler/compiler/common.py", line 4, in <module>
    from . import (
  File "/env/lib/python3.6/site-packages/graphql_compiler/compiler/emit_cypher.py", line 3, in <module>
    from .blocks import Fold, QueryRoot, Recurse, Traverse
  File "/env/lib/python3.6/site-packages/graphql_compiler/compiler/blocks.py", line 7, in <module>
    from .helpers import (
  File "/env/lib/python3.6/site-packages/graphql_compiler/compiler/helpers.py", line 14, in <module>
    from ..schema import INBOUND_EDGE_FIELD_PREFIX, OUTBOUND_EDGE_FIELD_PREFIX, is_vertex_field_name
  File "/env/lib/python3.6/site-packages/graphql_compiler/schema.py", line 26, in <module>
    description='Name of the filter operation to perform.',
TypeError: __init__() got an unexpected keyword argument 'type'

Steps to Reproduce

from graphql_compiler import compile_graphql_to_cypher

System details

Linux: Ubuntu 20.04.1 LTS
Python version: 3.6.12
The output of pip list:

Package          Version
---------------- -------
arrow            0.17.0
funcy            1.15
graphql-compiler 1.11.0
graphql-core     2.3.2
pip              20.3.3
promise          2.3
python-dateutil  2.8.1
pytz             2020.5
Rx               1.6.1
setuptools       51.0.0
six              1.15.0
SQLAlchemy       1.3.22
wheel            0.35.1

PS: The python virtual environment had just graphql-compiler installed.

Things I already tried

I tried with python v3.8.5. Got the same error.

I went through this issue #861 and made sure that the package versions are correct, especially graphql-core as mentioned in setup.py

Digging a little more,
I found that error points to L26 of graphql_compiler/schema.py. Snippet of code around there is:

FilterDirective = GraphQLDirective(
    name='filter',
    args=OrderedDict([(
        'op_name', GraphQLArgument(
            type=GraphQLNonNull(GraphQLString),
            description='Name of the filter operation to perform.',
        )),
        ('value', GraphQLArgument(
            type=GraphQLNonNull(GraphQLList(GraphQLNonNull(GraphQLString))),
            description='List of string operands for the operator.',
        ))]
    ),

here you are attempting to create a GraphQLArgument with type=GraphQLNonNull(GraphQLString),
but going through the codebase of graphql-core v2.3.2, class GraphQLArgument constructor is this:

class GraphQLArgument(object):
    __slots__ = "type", "default_value", "description", "out_name"

    def __init__(
        self,
        type_,  # type: Union[GraphQLInputObjectType, GraphQLNonNull, GraphQLList, GraphQLScalarType]
        default_value=None,  # type: Optional[Any]
        description=None,  # type: Optional[Any]
        out_name=None,  # type: Optional[str]
    ):
        # type: (...) -> None
        self.type = type_
        self.default_value = default_value
        self.description = description
        self.out_name = out_name

the constructor seems to accept the keyword argument type_ instead of type.
So I went through your repo to find over here that this change from type to type_ has already been done.

pip install graphql-compiler installs v1.11.0. Should I explicitly use one of v2.0.0dev versions?

Sorry if this was a lot of info but I hope that it helps in resolving this issue.
Looking forward to your reply.

@sanchit-gupta-cn
Copy link
Author

I solved the issue using v2.0.0.dev29

pip install graphql-compiler==2.0.0.dev29

But still wondering when will v2.0.0 be released because we intend to use graphql-compiler in production.

@obi1kenobi
Copy link
Contributor

Hi, thanks for checking out this project and for tracking down the issue. For now, yes, I'd advise using one of the v2.0.0.dev releases — some of the API-breaking changes we need to do to release v2.0 (e.g. deprecate Gremlin and explicitly define the package's public API) have had to be pushed back. I unfortunately don't have a timeline I can share at the moment.

I also see that you are using the Cypher backend, potentially with Redis Graph? The Cypher backend is still in an alpha stage and not currently actively developed — last time we worked on it, we found that the then-most-recent Neo4j and Redis Graph versions didn't yet support all aspects of the latest published version of the Cypher language spec, so we paused development to allow them to catch up to the spec.

We are unfortunately a very small team and we don't have the bandwidth to pick Cypher development back up at this time. Our efforts have been focused largely on improving the SQL side of the compiler since that's a very common and large use case, so I'd encourage you to try the compiler's support for PostgreSQL. If instead you are set on using the Cypher backend, we'd be happy to take pull requests :)

Sorry I don't have a better reply!

@obi1kenobi
Copy link
Contributor

Also, if you don't mind me asking out of curiosity, how did you hear about GraphQL compiler? Hoping to figure out the popular ways through which people discover our project.

@sanchit-gupta-cn
Copy link
Author

Hi,
Thank you for the detailed reply. Will be looking forward to v2 being released.

And yes, your guess was correct. I was trying to use graphql-compiler along with RedisGraph. The main motivation was to avoid writing boilerplate code converting GraphQL to Cypher, something like this library, but for RedisGraph. I came across graphql-compiler when going through this issue.

Btw, redisgraph-py now supports query parameters (Ref), so maybe this doc can be updated. But yeah, RedisGraph still doesn't have complete Cypher coverage.

Also, we really appreciate the kensho guys contributing to this project and keeping it open source (and for also writing awesome blogs!). I'll make sure to raise PRs if I find myself modifying the code for our use-case, or if I find any bugs :).

@obi1kenobi
Copy link
Contributor

Thank you for the kind words, they made our day!

Please feel free to open PRs for anything that needs updating, and we'd be happy to review and accept them. The Cypher backend actually started off as @LWprogramming's intern project, and while we haven't worked on it in a while, we'd love to have it properly updated and as fully-functional as possible.

The doc you mentioned needs updating lives in this repo here and it'd be a great place to start contributing.

@obi1kenobi obi1kenobi added this to the v2.0 milestone Jan 7, 2021
@obi1kenobi
Copy link
Contributor

Also, if I understood correctly, you mentioned that this issue is resolved in the v2.0 prereleases? If so, I'd like to mark it as closed since fixing the reported problem doesn't require any further code changes, and simply requires v2.0 to be released.

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

2 participants