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

How can params be used in sub trees of a query? #71

Open
victorbadila opened this issue Jul 15, 2019 · 2 comments
Open

How can params be used in sub trees of a query? #71

victorbadila opened this issue Jul 15, 2019 · 2 comments

Comments

@victorbadila
Copy link

Suppose I have a gql query that looks like this:

"query category($id: Int!, $pageSize: Int!, $currentPage: Int!) {
  category(id: $id) {
    id
    description
    name
  }
  products(pageSize: $pageSize, currentPage: $currentPage) {
    items {
      id
      name
    }
  }
}
"

Is there any way I could write it using this library? I am able to do so for the individual category and product queries, but I wasn't able to do this for the full example, where params int he query are passed down in different trees.

@victorbadila
Copy link
Author

I just realised that the gql can be written as a function:

const composedQuery = (id: number, pageSize: number, currentPage: number) => ({
  category: params({ id }, { id: types.number, description: types: string... }),
  products: params({ pageSize, currentPage }, {
    items: {
      id: types.number, // etc.
    }
  })
});

Would this be the preferred way of doing it?

@acro5piano
Copy link
Owner

acro5piano commented Jul 16, 2019

Hi @victorbadila , thank you for your interest in this library!

I just realised that the gql can be written as a function:

I never tried that way, but it looks working well and seems the only solution if the following code does not work:

const categoryQuery = params({ $id: 'Int!', $pageSize: 'Int!', $currentPage: 'Int!' }, {
  category: params({ id: '$id' }, { 
    id: types.number,
    description: types.string,
    // ...
  }),
  products: params({ pageSize: '$currentPage' }, {
    items: {
      id: types.number,
       // etc.
    },
  }),
});

Have you tried that? I believe it works.

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