Kashuab / mobx-depot

Scaffold MobX-powered models, queries and mutations with your GraphQL schema.
https://mobx-depot.dev
MIT License
8 stars 0 forks source link

Implement support for nested query arguments #34

Closed Kashuab closed 1 year ago

Kashuab commented 1 year ago

We need to implement the ability to, within a selection builder, provide arguments for nested queries:

{
  user(id: 1234) {
    email
    name  
    posts(first: 10, sort: "ascending") {
      title
      content
    }
  }
}

I'm not sure what the most intuitive approach would be. Here's the first thought that comes to mind:

const userQuery = new UserQuery(
  { id: 1234 },
  user => user
    .email
    .name
    .posts.first(10).sort("ascending")(
      post => post.title.content
    )
);
Kashuab commented 1 year ago

Implemented, published version 0.0.42

Kashuab commented 1 year ago

Actually, changed my mind. Instead of chaining functions, you can now pass an args argument to the query. This allows for support of required args:

const userQuery = new UserQuery(
  { id: 1234 },
  user => user
    .email
    .name
    .posts(
      { first: 10, sort: "ascending" },
      post => post.title.content
    )
);