question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:11 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
thorin072commented, May 5, 2021

@chrisberks Today I made an attempt to rewrite the filter. I found that for the request format I needed, I needed to use the interface. Following the instructions https://docs.graphene-python.org/en/latest/types/interfaces/ I implemented the following class:

class Advanced_Filter(graphene.Interface):
    doops = graphene.List(lambda: DOOPGQL)
    event = graphene.List(lambda: EventGQL)
    #project = graphene.List(lambda: ProjectGQL)
    @classmethod
    def resolve_type(cls, instance, info):
        for el in instance:
            if isinstance(el, DOOPModel):
                return DOOPGQL
            if isinstance(el, EventModel):
                return EventGQL

Right now, the resolver looks like this:

  _getAllResources = graphene.Field(lambda: graphene.List(Advanced_Filter),
        description='Implements an extended filter for DOOP, Event, Project',
        age=graphene.List(graphene.NonNull(graphene.String)),
        direction=graphene.List(graphene.NonNull(graphene.String)),
        ovz=graphene.Boolean(required=True),
        type_search=graphene.String())

    def resolve__getAllResources(self, info, age, direction, ovz):
        answer = []
        answer.append(db.query(DOOP)
            .filter_by(ovz=ovz)
            .join(Direction, Direction.id_cluster == DOOP.id_cluster)
            .filter(Direction.name.in_(direction))
            .join(Category_DOOP, Category_DOOP.id_doop == DOOP.id)
            .join(Category, Category_DOOP.id_category == Category.id)
            .filter(Category.age_max.in_(age), Category.age_min.in_(age))
            .all())
        answer.append(db.query(Event)
            .all())
        return answer

I also noticed a bug that the answer contains 2 objects at the time of the request: doop and event, but when I debug, there is only one doop object in the instance, and the event object simply disappears from the final answer selection. Unfortunately, after all my attempts, I got this answer:

query{
  Getallresources(age:["10","14"],direction:["Code"],ovz:false){
  doops{id}
  event{id}
  }
}
{
  "data": {
    "Getallresources": [
      null,
      null
    ]
  },
  "errors": [
    {
      "message": "Could not find possible implementing types for Advanced_Filter in schema. Check that schema.types is defined and is an array ofall possible types in the schema."
    },
    {
      "message": "Could not find possible implementing types for Advanced_Filter in schema. Check that schema.types is defined and is an array ofall possible types in the schema."
    }
  ]
}

I would appreciate any ideas and thoughts, maybe they will help you find the right way to solve the problem.

0reactions
chrisberkscommented, May 8, 2021

Thank you for that @thorin072, happy to help!

Read more comments on GitHub >

github_iconTop Results From Across the Web

How fix error: “Expected value of type \”*GQL\“ but got
Hello! At the data schema level in SQLAlchemy, all tables are linked through a relationship. I have the following GraphQL data schema:
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found