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
Add option to initialize nullables, instead of setting them to null #62
Comments
Hey! I'm happy to bring in any improvement 👍 I just had a look at the fork but it seems to implement a few different things so I am not sure to identify the changes you are interested in. Would you like for all nullable fields to be treated as non-nullable from the schema? Should it also be reflected in the types or only in the factories' return value? So given the following schema: type Post {
id: ID
title: String
excerpt: String
} It should generate: interface Post {
id: string;
title: string;
excerpt: string;
}
function createPostMock(props: Partial<Post>): Post {
return {
id: "",
title: "",
excerpt: "",
...props,
};
} Or the fields should remain nullable in the type but filled with default values in the factory: interface Post {
id: string | null;
title: string | null;
excerpt: string | null;
}
function createPostMock(props: Partial<Post>): Post {
return {
id: "",
title: "",
excerpt: "",
...props,
};
} |
Hey! The first thing you discussed would be amazing - so basically add a flag to treat nullables as non-nullable if you request - allowing generation of non-nullable data. I know this is a problem with my schema but it would really help me for testing and I think would be a great QOL improvement! |
Thanks for the suggestion, I can definitely see how that would be useful. It should be straightforward to implement, I'll look into it 👍 |
@elibosley I just released v1.2.0 with this feature. See the documentation for an example of how you can configure it: https://gabinaureche.com/graphql-codegen-factories/configuration/schema#configmaybevaluedefault The gist is to set the Let me know if you have any feedback 🙏 |
It would be awesome if you could merge this fork: https://github.com/immuta/graphql-codegen-factories (not my code) in order to allow nullable values to be treated as non-null when generating mocks. This would greatly improve the usefulness of this library for me.
Thanks a ton, awesome work on this!
The text was updated successfully, but these errors were encountered: