Skip to content

How fix error: “Expected value of type \”*GQL\“ but got: *.”? #305

@thorin072

Description

@thorin072

Hello!
At the data schema level in SQLAlchemy, all tables are linked through a relationship. I have the following GraphQL data schema:

class CategoryGQL(SQLAlchemyObjectType):
    class Meta:
        proxy = True
        description = "Table of category"
        model = CategoryModel
        interfaces = [relay.Node]

class DOOPGQL(SQLAlchemyObjectType):
    class Meta:
        proxy = True
        description = "Table of DOOP"
        model = DOOPModel
        interfaces = (relay.Node,)

class DirectionGQL(SQLAlchemyObjectType):
    class Meta:
        description = "Table of direction"
        model = DirectionModel
        interfaces = [relay.Node]

class Category_DOOPGQL(SQLAlchemyObjectType):
    class Meta:
        description = "Category and Doop relationship table"
        model = Category_DOOP_Model
        interfaces = (relay.Node,)

I also implement this resolver. I got the error: Received incompatible instance, if I didn't use lambda with the first parameter graphene.List():

class AdvancedSearch(ObjectType):
    age = List(graphene.NonNull(graphene.String))  # [Array!]
    direction = List(graphene.NonNull(graphene.String))  # [Array!]
    ovz = graphene.Boolean()

    doops = graphene.List(lambda: graphene.List(DOOPGQL),ovz=ovz,age=age,direction=direction)
    
    def resolve_doops(self,info):
        query = db.query(DOOP,Direction,Category,Category_DOOP)
        query = query.filter_by(ovz=self.ovz)
        query = query.join(Direction, Direction.id_cluster == DOOP.id_cluster)
        query = query.filter(Direction.name.in_(self.direction))
        query = query.join(Category_DOOP, Category_DOOP.id_doop == DOOP.id)
        query = query.join(Category, Category_DOOP.id_category == Category.id)
        query = query.filter(Category.age_max.in_(self.age),Category.age_min.in_(self.age))
        query = query.all()
        return query

I get this answer:

"errors": [
    {
      "message": "Expected value of type \"DOOPGQL\" but got: Direction.",
      "locations": [
        {
          "line": 3,
          "column": 5
        }
      ]
    },
    {
      "message": "Expected value of type \"DOOPGQL\" but got: Category.",
      "locations": [
        {
          "line": 3,
          "column": 5
        }
      ]
    },
    {
      "message": "Expected value of type \"DOOPGQL\" but got: Category_DOOP.",
      "locations": [
        {
          "line": 3,
          "column": 5
        }
      ]
    }
  ]

I tried different ways. I changed the names of the tables in lambda: graphene. List(DOOPGQL), but I had 1\4 tables working. Maybe I'm returning a request, but not in the format that GraphQL is waiting for?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions