ardeois / graphql-codegen-typescript-mock-data

[GraphQL Codegen Plugin](https://github.com/dotansimha/graphql-code-generator) for building mock data based on the schema.
MIT License
134 stars 46 forks source link

feat(deps): switch to faker from casual #92

Closed MH4GF closed 2 years ago

MH4GF commented 2 years ago

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.

MH4GF commented 2 years ago

✅ TODO:

📝 memo:

Check compatibility

casual 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'
MH4GF commented 2 years ago

@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.

ardeois commented 2 years ago

Closing this PR as #93 cover it already with retro-compatible config to avoid breaking changes