Git Product home page Git Product logo

Comments (4)

zhouzi avatar zhouzi commented on May 12, 2024

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.

elibosley avatar elibosley commented on May 12, 2024

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.

zhouzi avatar zhouzi commented on May 12, 2024

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.

zhouzi avatar zhouzi commented on May 12, 2024

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.