graphql-faker icon indicating copy to clipboard operation
graphql-faker copied to clipboard

Specify number of items in array

Open chookie opened this issue 7 years ago • 14 comments

Would it be possible to add the ability to specify the number of items in a list? I would imagine being able to enter a min number and max number then it returns a random number of items within that range. If the numbers are the same then obviously it just returns that number. An example of syntax is below but you might have a better idea.

image

chookie avatar May 24 '17 07:05 chookie

@chookie Thank you for the idea it's definitely something we need to add to Faker. It partly overlaps with validation tool we plan to work on so you could specify @list(minItems: 5, maxIterms: 10) for input value and we want to reuse the same directives inside Faker.

We still didn't finish with the design of these directives so it will take some time before we can add this feature to Faker.

IvanGoncharov avatar May 25 '17 13:05 IvanGoncharov

Hello, @IvanGoncharov This list length will be very useful for us ;) When we can have this feature?

zachcr avatar Jan 11 '18 04:01 zachcr

@zachzhi I plan to spend some time on Faker in the second half of this month and this issue is on my checklist. Hower before implementing it I want to switch to official graphql-js instead of the custom fork and write some basic tests.

I will ping you when I will have some prototype to test.

IvanGoncharov avatar Jan 11 '18 12:01 IvanGoncharov

Any update on this? Thank you for the tool, looks very promising 👍

o-alexandrov avatar Feb 27 '18 05:02 o-alexandrov

@OlzhasAlexandrov I'm still working on pushing necessary functionality in the graphql-js. It's extremely slow and time-consuming 😞 but I managed to push like 80% required for APIs-guru/graphql-* projects. For this particular project, I still need to push one PR that will allow switching away from the custom fork of express-graphql.

TL;DR; I'm working on my checklist but its very very slow progress.

IvanGoncharov avatar Feb 27 '18 09:02 IvanGoncharov

@OlzhasAlexandrov happy to help. I might learn something. Need/want help?

idkjs avatar Feb 27 '18 17:02 idkjs

I would be glad to help also, there is any todo list/PR/branch/fork that I can look into?

lucasfeliciano avatar Jun 29 '18 12:06 lucasfeliciano

Constantly just being given 3-4 elements in array, I have a use case here that required like 1000-10000 items on UI. Is there anyway to achieve that so far?

p.s @IvanGoncharov May be you can pint out to the related line of code where I just can hard-code the number of items so I can build custom version of faker just to be able to play with long lists.

kuncevic avatar Oct 17 '18 02:10 kuncevic

@kuncevic Still planning to implement this, it's in my queue.

May be you can pint out to the related line of code where I just can hard-code the number of items so I can build custom version of faker just to be able to play with long lists.

https://github.com/APIs-guru/graphql-faker/blob/2f58a7f4fc230609756b97f16bd3615df1c162d4/src/fake_schema.ts#L182

IvanGoncharov avatar Oct 17 '18 02:10 IvanGoncharov

Just modified node_modules\graphql-faker\dist\fake_schema.js at var length = fake_1.getRandomInt(500, 1000); for now which is a bit dirty but works for my use case.

kuncevic avatar Oct 17 '18 22:10 kuncevic

Hello everyone, I just created #61 as I desperately need this feature and hardcoding is no-go in my case. Check it out :)

My proposal is following

employees: [Employee] @sample(min: 10, max: 20)

/cc: @IvanGoncharov

MilosMosovsky avatar Oct 18 '18 03:10 MilosMosovsky

Why call it @sample? why not sth like @itemCount or @items? Otherwise looks neat :)

kristianmandrup avatar Nov 14 '18 18:11 kristianmandrup

Why call it @sample? why not sth like @itemCount or @items? Otherwise looks neat :)

I had same thought, but I would stick to @fakeArray in such case this way it is really self explained, e.g: employees: [Employee] @fakeArray(min: 10, max: 20)

kuncevic avatar Nov 24 '18 17:11 kuncevic

It's been a while since last posts 😄 ... but wondering if you are aware of something that fills the need?

Thank you,

EDIT: oh sorry, it seems it has been solved 1 year later by https://github.com/APIs-guru/graphql-faker/commit/5db15f66f13c0c69f7d69b3be004ffd0ba455f05 (maybe close this issue?)

sneko avatar Nov 16 '21 08:11 sneko