sangria-relay icon indicating copy to clipboard operation
sangria-relay copied to clipboard

Using DeferredResolver (Fetchers) to resolve relay connections

Open Aqueelmiq opened this issue 5 years ago • 1 comments

Let's say I have users and posts graphql types. I can define a connection representing (User creating post edge) as:

  implicit val UserDataType: ObjectType[QueryCtx, User] =
    deriveObjectType[QueryCtx, User](
      Interfaces(nodeInterface),
      AddFields(
        idField[User],
        Field(
          "posts",
          OptionType(postsConnection),
          arguments = Connection.Args.All,
          resolve = state ⇒
            Connection.connectionFromFutureSeq(
              state.ctx.getPostsByUser(ids),
              ConnectionArgs(state)
          )
        )
      )
    )

Now, I am trying to do the same except this time resolve the connections using a deferred resolver implemented using Fetcher.rel. The Connection class doesn't have any helper methods for a deferred resolver (only for furture and seqs). Is there any example on how to do this?

Aqueelmiq avatar Jan 01 '19 02:01 Aqueelmiq

I also stumbled upon this. I don't think this is currently supported. Did you have any luck?

@OlegIlyenko Any ideas? I tried digging into this but I'm not sure how a Fetcher is materialized to a list.

Edit: Well, it should be easier than I thought: https://sangria-graphql.org/learn/#transforming-the-deferred-value

giannoug avatar Aug 17 '19 20:08 giannoug