Storybook: if mock data structure does not match QUERY exactly, wrong error is thrown
See original GitHub issueUpdate: https://github.com/redwoodjs/redwood/issues/1380#issuecomment-990482233
If you have a QUERY
in a cell like:
export const QUERY = gql`
query BlogPostsQuery {
posts {
id
title
body
createdAt
}
}
`
But in the associated story mock, the return data is missing one or more fields:
export const standard = (/* vars, { ctx, req } */) => ({
posts: [
{
id: 1,
title: 'First post',
body: 'Neutra tacos hot chicken prism raw denim...',
},
]
})
(createdAt
is missing) you’ll get a weird error in the story that data
is missing completely:
This literal error is coming from withCell
(which is thrown when data
is indeed null) but it appears that something we’re doing somewhere is swallowing the real error and we’re left with this.
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
GraphQL schema basics - Apollo GraphQL Docs
This schema defines a hierarchy of types with fields that are populated from your back-end data stores. The schema also specifies exactly which...
Read more >Frequently Asked Questions - Storybook - JS.ORG
Why are my mocked GraphQL queries failing with Storybook's MSW addon? Can I use other GraphQL providers with Storybook's MSW addon? Can I...
Read more >Match query | Elasticsearch Guide [8.5] | Elastic
Returns documents that match a provided text, number, date or boolean value. The provided text is analyzed before matching. The match query is...
Read more >Testing | RedwoodJS Docs
Try running that code again and you should see "fail: no error thrown" in the ... went wrong (the expected and actual values...
Read more >sqlmock: expectations do not match (being exactly the same ...
Why you mock SQL queries? It's better to write a real integration test to check queries with a real database. Mocking is a...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I think we should add it to the queue - it would make dev/ testing/ storybook so much nicer.
While I don’t see this issue happening anymore, the idea of wrapping a Cell in a dev-friendlier error boundary is still worthwhile, so I’ll leave this issue open but remove it’s bug/v1 status.