Skip to content

Added support for custom generator function #39

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
Jan 25, 2021

Conversation

marucjmar
Copy link
Contributor

Hi,

I need to generate a specific value for mock. This implementation enables me to use my custom value generator. eg.

config:

src/test/factory/graphql.ts:
   plugins:
       - add: "import { generateArrayBuffer } from '../generators';"
       - typescript-mock-data:
              typesFile: "../../shared/graphql/generated.ts"
              enumValues: upper-case#upperCase
              typenames: keep
              addTypename: true
              scalars:
                 ArrayBuffer:  generateArrayBuffer()

src/test/factory/graphql.ts

import { generateArrayBuffer } from '../generators;

export const anPakeProtocol = (overrides?: Partial<PakeProtocol>): PakeProtocol => {
    return {
        id: overrides && overrides.hasOwnProperty('id') ? overrides.id! : '1d6a9360-c92b-4660-8e5f-04155047bddc',
        message: overrides && overrides.hasOwnProperty('message') ? overrides.message! : generateArrayBuffer(),
    };
};

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.

Great thanks for the PR!

Could you maybe update the readme?

@marucjmar
Copy link
Contributor Author

@ardeois Done :)

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.

LGTM, thanks for the updates !

@ardeois ardeois added the minor Increment the minor version when merged label Jan 25, 2021
@ardeois ardeois self-assigned this Jan 25, 2021
@ardeois ardeois merged commit 58d01c3 into ardeois:master Jan 25, 2021
@ardeois
Copy link
Owner

ardeois commented Jan 28, 2021

@marucjmar I've just noticed the npm publish failed when I merged.
It's now fixed https://www.npmjs.com/package/graphql-codegen-typescript-mock-data
Your PR is included in version 1.4.0

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.

2 participants