Skip to content

feat: add includedTypes and excludedTypes options for selective mock generation #179

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

Merged
merged 7 commits into from
Feb 26, 2025

Conversation

huseyinbuyukdere
Copy link
Contributor

This PR introduces two new configuration options, includedTypes and excludedTypes, to the graphql-codegen-typescript-mock-data plugin for enhanced control over mock data generation:

Changes Introduced:

  1. includedTypes (Array of strings):

    • Allows specifying an array of types to include in the mock generation.
    • Only the types listed in includedTypes will have mock data generated.
  2. excludedTypes (Array of strings):

    • Allows specifying an array of types to exclude from the mock generation.
    • Types listed in excludedTypes will not have mock data generated.
  3. Precedence:

    • If both includedTypes and excludedTypes are provided, includedTypes takes precedence over excludedTypes.

Examples:

1. includedTypes Example:

plugins:
  - typescript-mock-data:
      includedTypes:
        - User
        - Avatar

In this configuration, mock data will be generated only for User and Avatar types.

2. excludedTypes Example:

plugins:
  - typescript-mock-data:
      excludedTypes:
        - User
        - Avatar

In this configuration, User and Avatar types will be excluded from mock data generation.

3. Combined includedTypes and excludedTypes:

plugins:
  - typescript-mock-data:
      includedTypes:
        - User
      excludedTypes:
        - User
        - Avatar

In this example, despite being listed in excludedTypes, User will still have mock data generated because includedTypes takes precedence.

Documentation Updates:

  • Added descriptions for includedTypes and excludedTypes in the README.md.
  • Added examples demonstrating how to use these options.

Tests:

  • Added unit tests to validate the behavior of includedTypes and excludedTypes:
    • Mock generation for included types.
    • Exclusion of specific types.
    • Precedence handling when both options are provided.

This update provides flexibility for users to selectively include or exclude types, making mock data generation more efficient and tailored to specific testing needs.

Copy link
Owner

@ardeois ardeois left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea seems fine, thanks for your contribution !

I have one concern about non-types definitions that we should probably support.

Also, if a type uses other types, should we automatically include them? Or should we leave that decision to the user ?

@huseyinbuyukdere
Copy link
Contributor Author

The idea seems fine, thanks for your contribution !

I have one concern about non-types definitions that we should probably support.

Also, if a type uses other types, should we automatically include them? Or should we leave that decision to the user ?

Quote reply

Hmm we can include that but it will increase the complexity for now IMO. For now that lets keep it like that, if there will be a problem (And also I will use it :) ), if it is getting a problem in the future we can do that. But for now we do not need imo.

@ardeois
Copy link
Owner

ardeois commented Jan 13, 2025

Hmm we can include that but it will increase the complexity for now IMO. For now that lets keep it like that, if there will be a problem (And also I will use it :) ), if it is getting a problem in the future we can do that. But for now we do not need imo.

I agree it would indeed increase the complexity, so let's keep it like that.

So just add allow the non-types definitions and add snapshots please
Thanks !

@hugotiger
Copy link

This looks amazing! Will be very beneficial for us since the amount of generated mocks in our application really slows things down (IDE, Typescript etc).

Is there anything I can help with to get this out soon? 😄

@thomasobrien99
Copy link
Contributor

This would be helpful for us too until the oneOf directive is supported

@ardeois ardeois self-assigned this Feb 26, 2025
@ardeois ardeois added the minor Increment the minor version when merged label Feb 26, 2025
@ardeois ardeois merged commit 0b69f0f into ardeois:main Feb 26, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
minor Increment the minor version when merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants