-
Notifications
You must be signed in to change notification settings - Fork 1k
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
fix: Fixes support for Mocking GraphQL Queries in Storybook when using GraphQL Fragments #10825
Conversation
Am running into some type issues having added Error: 25hsrc/components/AuthorCell/AuthorCell.test.tsx(39,23): error TS2322: Type '{ __typename: string; id: number; email: string; fullName: string; }' is not assignable to type '{ __typename?: "User"; email: string; fullName: string; }'.
Types of property '__typename' are incompatible.
Type 'string' is not assignable to type '"User"'. Perhaps due to /**
* @params TData = Type of data based on your graphql query. This can be imported from 'types/graphql'
* @example
* import type { FindPosts } from 'types/graphql'
*
* const { post }: CellSuccessData<FindPosts> = props
*/
export type CellSuccessData<TData = any> = ConditionallyGuaranteed<
Omit<TData, '__typename'>
> Investigating. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a couple minor comments but otherwise looks good. We paired on this and I seen how this change fixed the issue.
|
||
### Mock Data | ||
|
||
To satisfy the query as well as the fragment needs your mock data should include the `Book` typename: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't know if this just needs a comma somewhere but I can't wrap my head around this sentence sorry.
Co-authored-by: Josh GM Walker <56300765+Josh-Walker-GM@users.noreply.github.com>
Co-authored-by: Josh GM Walker <56300765+Josh-Walker-GM@users.noreply.github.com>
Will re-review docs for clarity.
…g GraphQL Fragments (#10825) Fixes #10807 If one used GraphQL fragments, when mocking the GraphQL query for use in Storybook, the `typename` for the data object must be included otherwise Apollo client cannot properly map the data. This PR * adds the typename to the cell generator templates * updates the testing and graphql mock and fragments documentation to show how properly defines mock data --- From issue #10807 ### What's not working? When mocking a graphql query inside a component to be able to render Cell children, it breaks when using fragments inside the Cell Query. My query in `ChatMessagesCell.tsx`: ```typescript export const QUERY: TypedDocumentNode< ChatMessagesQuery, ChatMessagesQueryVariables > = gql` query ChatMessagesQuery($chatRoomId: String!) { chatMessages(chatRoomId: $chatRoomId) { id body createdAt user { id displayName } } } ` ``` Then I mock this query inside a parent component `Chatbox.stories.tsx`: ```tsx mockGraphQLQuery<ChatMessagesQuery, ChatMessagesQueryVariables>( 'ChatMessagesQuery', (_variables) => { console.log('standard().chatMessages', standard().chatMessages) return { chatMessages: standard().chatMessages, } } ) ``` This works as it should, mocks the list using the standard values ![image](https://github.com/redwoodjs/redwood/assets/47559427/01e5701c-f873-4ecf-97f3-40b9da665c32) BUT THEN: My query with fragments in `ChatMessagesCell.tsx`: ```typescript registerFragment(gql` fragment ChatMessageFragment on ChatMessage { id body createdAt user { id displayName } } `) export const QUERY: TypedDocumentNode< ChatMessagesQuery, ChatMessagesQueryVariables > = gql` query ChatMessagesQuery($chatRoomId: String!) { chatMessages(chatRoomId: $chatRoomId) { ...ChatMessageFragment } } ` ``` With the same mock. The list is created from the `standard()` function but the inner objects are empty ![image](https://github.com/redwoodjs/redwood/assets/47559427/0fd4cb6c-73b6-442d-aeec-815069d63a28) --------- Co-authored-by: Josh GM Walker <56300765+Josh-Walker-GM@users.noreply.github.com>
**Problem** The rebuild-test-project-fixture script was broken locally - and probably on CI too. **Changes** 1. Move generation of user sdl ahead of dbauth setup 2. Updates general version bumps in fixure 3. Updates for fragment type fix (on or around #10825 4. Updates for useBlocker in contact us form #10873 5. Updates to remove unused imports and have lint check complete successfully
Fixes #10807
If one used GraphQL fragments, when mocking the GraphQL query for use in Storybook, the
typename
for the data object must be included otherwise Apollo client cannot properly map the data.This PR
From issue #10807
What's not working?
When mocking a graphql query inside a component to be able to render Cell children, it breaks when using fragments inside the Cell Query.
My query in
ChatMessagesCell.tsx
:Then I mock this query inside a parent component
Chatbox.stories.tsx
:This works as it should, mocks the list using the standard values
BUT THEN:
My query with fragments in
ChatMessagesCell.tsx
:With the same mock. The list is created from the
standard()
function but the inner objects are empty