Closed MH4GF closed 2 years ago
@types/faker
was already in. (Perhaps someone forgot to turn it off?)Almost completed migrating to TypeScript so that DefinitelyTyped no longer needs to maintain its external [@types/faker](https://www.npmjs.com/package/@types/faker) package.
ref: https://fakerjs.dev/about/announcements/2022-01-14.html@types/faker
packageUsing the browser is great for experimenting 👍. However, due to all of the strings Faker uses to generate fake data, Faker is a large package.
ref: https://fakerjs.dev/guide/#browsercasual | casual result | faker | faker result |
---|---|---|---|
casual.seed(0) | N/A | faker.seed(0) | N/A |
Math.round(casual.double(0, 10) * 100) / 100 | 3.8 |
faker.datatype.float({ min: 0, max: 10, precision: 0.1 }) | 6.4 |
casual.integer(0, 9999) | 6130 |
faker.datatype.number({ min: 0, max: 9999 }) | 9962 |
casual.uuid | '99bd9d8d-79a6-474e-8f46-6cc8796ed151' |
faker.datatype.uuid() | '89bd9d8d-69a6-474e-8f46-7cc8796ed151' |
casual.boolean | true |
faker.datatype.boolean() | true |
new Date(casual.unix_time) | 1970-01-08T09:31:42.245Z |
faker.date.past() | 2022-02-14T08:58:38.892Z |
casual.word | 'laborum' |
faker.lorem.word() | 'harum' |
@ardeois Thank you for your thoughtful comments!
As @JimmyPaolini points out here https://github.com/ardeois/graphql-codegen-typescript-mock-data/issues/90#issuecomment-1258031326 , the current implementation has a problem that is no different from a destructive change because the output results are different.
As a solution to this, I think that your suggested option 3 is a better choice. It makes sense that most users would be satisfied with casual and only those who want to use faker can choose it of their own volition.
I'll try to add the generatorLibrary option after work! Also the ValueGenerator class you suggested looks good. Since the purpose of this PR will be different from this one, I will publish it as a separate PR.
Closing this PR as #93 cover it already with retro-compatible config to avoid breaking changes
closes https://github.com/ardeois/graphql-codegen-typescript-mock-data/issues/90
What
Switch casual with faker, which was used in the generation process of the mocked temporary values.
Context
casual dependents on the node API(e.g. fs) and cannot be made to work in the browser. ref: https://github.com/ardeois/graphql-codegen-typescript-mock-data/issues/90
Problem
This library has the feature for custom generators to embed in casual property calls, and switching to faker would be a breaking change. Since it is not good to force many users to migrate for the dynamicValues feature that few users use yet, I think it is better to migrate only the other mock functions on a temporary basis.