Skip to content
This repository was archived by the owner on Feb 6, 2025. It is now read-only.

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

@sanchit-gupta-cn

Description

@sanchit-gupta-cn

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions