Skip to content

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