Skip to content
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

Accept nested partials #50

Open
ertrzyiks opened this issue May 3, 2022 · 1 comment
Open

Accept nested partials #50

ertrzyiks opened this issue May 3, 2022 · 1 comment
Labels
enhancement New feature or request

Comments

@ertrzyiks
Copy link
Contributor

ertrzyiks commented May 3, 2022

Another DX improvement idea, what I have in the code now is similar to this:

createBlogListQueryQueryMock_node({
  parsedHeadline: createBlogListQueryQueryMock_parsedHeadline({
    childMarkdownRemark: createBlogListQueryQueryMock_parsedHeadline_childMarkdownRemark({
      html: 'This is pizza',
    })
  })
})

What would be more convenient and much less verbose is if the factory function accepted a nested partial param, like

createBlogListQueryQueryMock_node({
  parsedHeadline: {
    childMarkdownRemark: {
      html: 'This is pizza',
    }
  }
})

but currently it requires me to pass all the data necessary for the operation mock. I would need to add missing __typename and all other fields that are selected even if the example/story/test doesn't care about them.

The factories are already kinda recursive, it shouldn't require drastic changes.

Tricky cases that I anticipate:

  • arrays, could be ignore and keep them full-speced
  • unions, __typename would need to be required
@zhouzi
Copy link
Owner

zhouzi commented May 3, 2022

That makes a lot of sense and would also make our code simpler. To add to your observations, we also need to introduce a helper type DeepPartial:

- export function createUserMock(props: Partial<User>): User {
+ export function createUserMock(props: DeepPartial<User>): User {
}

We can probably take the implementation from ts-essentials/ts-essentials or sindresorhus/type-fest. The simpler the better I guess.

@zhouzi zhouzi added the enhancement New feature or request label May 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants