Comments (4)
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,
};
}
from graphql-codegen-factories.
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!
from graphql-codegen-factories.
Thanks for the suggestion, I can definitely see how that would be useful. It should be straightforward to implement, I'll look into it 👍
from graphql-codegen-factories.
@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 maybeValueDefault
configuration option to "{defaultValue}"
.
Let me know if you have any feedback 🙏
from graphql-codegen-factories.
Related Issues (20)
- Operations plugin does not include fields from fragments HOT 9
- Nested factories for the operations plugin HOT 4
- Setup a realistic demo example HOT 4
- Use a better support for the documentation
- Add example on how to use with faker (or equivalent)
- Add a readme to the examples and list them on the website
- Generate factories for the fragments HOT 2
- Make the overrides optional HOT 4
- Support nonOptionalTypename: false HOT 3
- Accept nested partials HOT 1
- Document factories with JSDoc HOT 1
- schemaFactoriesPath should not resolve to local path when it starts with a tilde
- Union factory has type error in certain scenarios
- Warn when a factory would lead to an infinite loop HOT 6
- Add maybeValueDefault to customize the default value for nullables
- Omit optional properties by default? HOT 1
- compatability with `add` plugin HOT 5
- using `graphql-codegen-factories/operations` fails on `this.schema.getRootType` HOT 10
- Naming issues with custom Query root type HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from graphql-codegen-factories.