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

@defer fields not working as expected when backed by DataSources #1980

Closed
kyri-petrou opened this issue Nov 4, 2023 · 0 comments · Fixed by #1981
Closed

@defer fields not working as expected when backed by DataSources #1980

kyri-petrou opened this issue Nov 4, 2023 · 0 comments · Fixed by #1981

Comments

@kyri-petrou
Copy link
Collaborator

As the title says, there seems to be an issue affecting @deferfields under some specific conditions. Let's say we have the following schema:

  case class Bar(
    value: UQuery[String] // Backed by a datasource
  )
  case class Foo(bar: UIO[List[Bar]])
  case class Query(foo: UIO[Foo])

And I want to execute the following query:

foo {
  bar { ... @defer { value } }
}

This works fine as long as no item in the list makes a request to the datasource that requires deduplication. e.g.,

  case class Req(i: Int) extends Request[Nothing, String]
  val ds = DataSource.fromFunctionZIO("ValuesDS") { (_: Req) =>
    ZIO.succeed("value").delay(50.millis)
  }

  def makeBar(i: Int): Bar = Bar(ZQuery.fromRequest(Req(i))(ds))

  val works = Query(ZIO.succeed {
    Foo(bar = ZIO.succeed(List(makeBar(1), makeBar(2), makeBar(3))))
  })

  val broken = Query(ZIO.succeed {
    Foo(bar = ZIO.succeed(List(makeBar(1), makeBar(3), makeBar(3))))
  })

What happens in the "broken" case is that the streamed messages look like this:

{"incremental":[{"data":null,"errors":[{"message":"Effect failure","locations":[{"line":6,"column":36}],"path":["foo","bar",0,"value"]}],"path":["foo","bar",0]}],"hasNext":true}

I managed to trace down the issue to the datasource not completing the requests, dying with the following message:

Data source ValuesDS did not complete request Req(3) ....

Note that if I change my query to this, then it works as expected again:

foo {
  ... @defer { bar { value } }
}
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

Successfully merging a pull request may close this issue.

1 participant