@@ -2,6 +2,8 @@ import { describe, it, expect } from 'vitest';
22import { OperationResult } from '../types' ;
33import { queryOperation , subscriptionOperation } from '../test-utils' ;
44import { makeResult , mergeResultPatch } from './result' ;
5+ import { GraphQLError } from '@0no-co/graphql.web' ;
6+ import { CombinedError } from './error' ;
57
68describe ( 'makeResult' , ( ) => {
79 it ( 'adds extensions and errors correctly' , ( ) => {
@@ -180,6 +182,62 @@ describe('mergeResultPatch (defer/stream pre June-2023)', () => {
180182 expect ( merged . hasNext ) . toBe ( true ) ;
181183 } ) ;
182184
185+ it ( 'should work with the payload property' , ( ) => {
186+ const prevResult : OperationResult = {
187+ operation : subscriptionOperation ,
188+ data : {
189+ __typename : 'Subscription' ,
190+ event : 1 ,
191+ } ,
192+ stale : false ,
193+ hasNext : true ,
194+ } ;
195+
196+ const merged = mergeResultPatch ( prevResult , {
197+ payload : {
198+ data : {
199+ __typename : 'Subscription' ,
200+ event : 2 ,
201+ } ,
202+ } ,
203+ } ) ;
204+
205+ expect ( merged . data ) . not . toBe ( prevResult . data ) ;
206+ expect ( merged . data . event ) . toBe ( 2 ) ;
207+ expect ( merged . hasNext ) . toBe ( true ) ;
208+ } ) ;
209+
210+ it ( 'should work with the payload property and errors' , ( ) => {
211+ const prevResult : OperationResult = {
212+ operation : subscriptionOperation ,
213+ data : {
214+ __typename : 'Subscription' ,
215+ event : 1 ,
216+ } ,
217+ stale : false ,
218+ hasNext : true ,
219+ } ;
220+
221+ const merged = mergeResultPatch ( prevResult , {
222+ payload : {
223+ data : {
224+ __typename : 'Subscription' ,
225+ event : 2 ,
226+ } ,
227+ } ,
228+ errors : [ new GraphQLError ( 'Something went horribly wrong' ) ] ,
229+ } ) ;
230+
231+ expect ( merged . data ) . not . toBe ( prevResult . data ) ;
232+ expect ( merged . data . event ) . toBe ( 2 ) ;
233+ expect ( merged . error ) . toEqual (
234+ new CombinedError ( {
235+ graphQLErrors : [ new GraphQLError ( 'Something went horribly wrong' ) ] ,
236+ } )
237+ ) ;
238+ expect ( merged . hasNext ) . toBe ( true ) ;
239+ } ) ;
240+
183241 it ( 'should ignore invalid patches' , ( ) => {
184242 const prevResult : OperationResult = {
185243 operation : queryOperation ,
0 commit comments