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

ORMField batching results in null result #401

Open
odfalik opened this issue Jan 26, 2024 · 1 comment
Open

ORMField batching results in null result #401

odfalik opened this issue Jan 26, 2024 · 1 comment

Comments

@odfalik
Copy link

odfalik commented Jan 26, 2024

I'm trying to get batching set up on a 1:N relationship. Suppose a Foo has many Bars

class FooObject(SQLAlchemyObjectType):
    class Meta:
        model = Foo
        interfaces = (graphene.relay.Node,)

    bars = ORMField(batching=True)

(I've also tried doing batching=True in the Meta)

class Query(graphene.ObjectType):
    test_query_batching = graphene.Field(
        lambda: graphene.List(FooObject),
    )

    def resolve_test_foo_query_batching(self, info):
        return Foo.query.limit(5).all()

Querying this resolver as such

query TestQueryBatching {
  testQueryBatching {
    id
    bars {
      edges {
        node {
          id
        }
      }
    }
  }
}

results in Cannot return null for non-nullable field BarObjectConnection.edges. This query succeeds if batching is disabled. I'm unsure as to why we'd be getting null for BarObjectConnection.edges, though. Any ideas as to what might be leading to this?

Versions:

  • SQLAlchemy==1.4.51
  • Flask-SQLAlchemy==2.5.1
  • graphene-sqlalchemy==3.0.0rc1
@odfalik odfalik changed the title Enabling field batching results in SQAOT ORMField batching results in null result Jan 26, 2024
@odfalik odfalik changed the title SQAOT ORMField batching results in null result ORMField batching results in null result Jan 26, 2024
@davidmcnamee
Copy link

davidmcnamee commented Mar 2, 2024

Not sure what the bug is here, but this temporary workaround seemed to do the trick for me:

def execute(schema, query: str):
    """
    Temporary workaround for https://github.com/graphql-python/graphene-sqlalchemy/issues/401
    Use `execute(schema, query)` instead of `schema.execute(query)`
    """
    return asyncio.run(
        graphql(
            schema.graphql_schema,
            source=query,
            context_value={},
        )
    )

based on this code

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