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

keyArgs: array of objects support #11198

Closed
younes0 opened this issue Sep 7, 2023 · 7 comments
Closed

keyArgs: array of objects support #11198

younes0 opened this issue Sep 7, 2023 · 7 comments

Comments

@younes0
Copy link

younes0 commented Sep 7, 2023

There is not support array of objects as keyArgs.

With variables

variables: {
  limit: 12,
  offset: 0
  myArray: [
     { myFirst: false, mySecond: true },
     { myFirst: true, mySecond: false },
  ]
}

The following field policies do not work

myThings: offsetLimitPagination(["myArray", ["myFirst", "mySecond"]]),
// or
myThings: offsetLimitPagination(["myArray", [["myFirst", "mySecond"]]]),

This question/feature was already asked but didn't get any answer: #7314 (comment)

@phryneas
Copy link
Member

phryneas commented Sep 7, 2023

In such a complex case, you can use a keyArgs function.

We aim to provide functionality for all the common use cases, but once it gets complex like this, it's impossible for us to find a notation that fits everyone - and if we could find one, it would add significant bundle size as a burden to everyone, including those who would not be needing it.

In that case, it's better (and probably much simpler to use for you) to implement this in userland.


PS It seems that we do have that functionality in fact, I just had never encountered it. I'm investigating.


PS2: Please excuse the back-and-forth - I stand with my initial answer. We do have a feature like that, but only for objects, not arrays. In the array case, please provide your own function.

@younes0
Copy link
Author

younes0 commented Sep 7, 2023

@phryneas thanks for your feedback. I will provide then a working example here so it can be used as reference for people having the same usecase.

PS: I noticed that the offsetLimitPagination function doesn't accept keyArgs function.

@phryneas
Copy link
Member

phryneas commented Sep 7, 2023

@younes0 The KeyArgs type there includes KeyArgsFunction. What exactly are you seeing?

image

@younes0
Copy link
Author

younes0 commented Sep 7, 2023

@phryneas my bad, i was wrong.

@younes0
Copy link
Author

younes0 commented Sep 7, 2023

specifying keyArgs function doesn't help: changing helpers that extract the key/value would do the work but I'm struggling very much to understand how the parsing code works.

I will change my GraphQL schema in the end to avoid nested object in arrays.

@younes0 younes0 closed this as completed Sep 7, 2023
@younes0
Copy link
Author

younes0 commented Sep 18, 2023

I changed my GraphQL schema to accept a (JSON) string value.
The JSON is then parsed on the server side.
Not ideal but works flawlessly: in my case i had an array of objects contains dates.

@github-actions
Copy link
Contributor

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
For general questions, we recommend using StackOverflow or our discord server.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 19, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants