import { graphql } from 'msw' ; type Maybe < T > = T | null ; type Exact < T extends { [ key ] : unknown ; } > = { [ K in keyof T ] : T [ K ] ; } ; type User = { id : string ; firstName : string ; lastName : string ; } ; type Message = { id : string ; message : string ; } ; export type UserInfoQueryVariables = Exact < { id : string ; } > ; export type UserInfoQuery = { __typename ? : 'Query' ; user : Maybe < { __typename ? : 'User' ; } & Pick < User , 'id' | 'firstName' | 'lastName' > > ; } ; export type LoginMutationVariables = Exact < { username : string ; } > ; export type LoginMutation = { __typename ? : 'Mutation' ; login : Maybe < { __typename ? : 'User' ; } & Pick < User , 'id' | 'firstName' | 'lastName' > > ; } ; export type OnMessageAddedSubscriptionVariables = Exact < { channel : string ; } > ; export type OnMessageAddedSubscription = { __typename ? : 'Subscription' ; messageAdded : Maybe < { __typename ? : 'Message' ; } & Pick < Message , 'id' | 'message' > > ; } ; const USERS = [ { id : '1' , firstName : 'Cathaline' , lastName : 'McCoy' } , { id : '2' , firstName : 'Joth' , lastName : 'Maverick' } ] ; export const handlers = [ graphql . query < UserInfoQuery , UserInfoQueryVariables > ( 'UserInfo' , ( req , res , ctx ) => { const user = USERS [ Number ( req . variables . id . charAt ( 0 ) ) - 1 ] ; if ( user && req . variables . id . includes ( 'with-error' ) ) { return res ( ctx . errors ( [ { message : 'Data With Error' } ] ) , ctx . data ( { user : { __typename : 'User' , ... user } } ) ) ; } else if ( user ) { return res ( ctx . data ( { user : { __typename : 'User' , ... user } } ) ) ; } else { return res ( ctx . errors ( [ { message : 'User not found' } ] ) ) ; } } ) , graphql . mutation ( 'Login' , ( req , res , ctx ) => { const { username } = req . variables ; if ( username === 'non-existing' ) { return res ( ctx . errors ( [ { message : 'User not found with given username' } ] ) ) ; } if ( username === 'with-error' ) { return res ( ctx . errors ( [ { message : 'Error with Data' } ] ) , ctx . data ( { login : { __typename : 'User' , ... USERS [ 1 ] } } ) ) ; } return res ( ctx . data ( { login : { __typename : 'User' , ... USERS [ 1 ] } } ) ) ; } ) , graphql . query ( 'GetUserInfo' , ( _ , res , ctx ) => { return res ( ctx . delay ( 2000 ) , ctx . data ( { user : { __typename : 'User' , id : '1' , firstName : 'John' , lastName : 'Maverick' , username : 'joth' } } ) ) ; } ) ] ;