-
-
Notifications
You must be signed in to change notification settings - Fork 248
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
Nested Arguments #507
Comments
You can use arguments at any level of the schema: you just have the field return a function from the Arg case class to the result type. The same thing you did works whatever the level 😄 |
Whoo, thanks for the super fast replay! 🤔 Not sure i've understood correctly, should i change the query or the schema? final case class Queries[F[_]](
// ??? should i change the query with something like this?
user: UserArg => ForwardPaginationArg => F[Option[UserNode]] => F[RepositoryConnection]
)
// ??? or should i change the schema like this
final case class UserNode(
id: NodeId,
name: NonEmptyString,
createdAt: Instant,
updatedAt: Instant,
repositories: ForwardPaginationArg => F[RepositoryConnection]
) extends Node Could you give me a super simple example if i'm on the wrong track? Thanks 😊 This should give a full picture of what I got so far object schema extends CommonSchema with CommonArgBuilder {
@newtype case class Offset(value: NonNegLong)
@newtype case class NodeId(value: Base64String)
@newtype case class Cursor(value: Base64String)
@GQLInterface
sealed trait Node {
def id: NodeId
}
final case class UserNode(
id: NodeId,
name: NonEmptyString,
createdAt: Instant,
updatedAt: Instant,
//repository: Repository,
repositories: RepositoryConnection
) extends Node
// TODO add issue|issues
final case class RepositoryNode(
id: NodeId,
name: NonEmptyString,
url: String Refined Url,
isFork: Boolean,
createdAt: Instant,
updatedAt: Instant
) extends Node
final case class RepositoryConnection(
edges: List[RepositoryEdge],
nodes: List[RepositoryNode],
pageInfo: PageInfo,
totalCount: NonNegLong
)
final case class RepositoryEdge(
cursor: Cursor,
node: RepositoryNode
)
final case class PageInfo(
hasNextPage: Boolean,
hasPreviousPage: Boolean,
startCursor: Cursor,
endCursor: Cursor
)
} |
The second one ☝️ There is an example that shows nested effects here: https://github.com/ghostdogpr/caliban/tree/master/examples/src/main/scala/caliban/optimizations Also this article might be of interest: https://medium.com/@ghostdogpr/graphql-in-scala-with-caliban-part-2-c7762110c0f9 |
Awesome, thanks a lot for the help and for the great lib! One last question, is there any plan in future to add pagination and filter support directly in caliban, as an extra module? Or it's too specific cos might vary case by case, hence it's out of scope? |
No immediate plan because each case is specific. There was some interest from a few contributors to add some helpers for the Relay format so this might happen at some point. |
Cool, I'm working on a standalone pr in my spare time (i haven't pushed the latest changes and I'm heavily iterating over it) with the goal to abstract it to create a lib, e.g. I'm far from having anything close to be presented, but if you are interested, I could share it once it's ready and I'd be happy to contribute to this project - if it makes sense of course! |
Sure, feel free to drop by the Discord later if you want to discuss this with me and other contributors/users. |
Hi,
I'm trying to re-implement a very simplified version of the GitHub api to play with the pagination following the spec, but I'm not entirely sure how to represent the nested arguments. Could you please give me some hints?
Thanks in advance for the help!
Query example
This is a gist of my current schema
If needed, I can provide more details about the schema or the implementation, but I think they are neglectable
The text was updated successfully, but these errors were encountered: