Mirror: The highly customizable and versatile GraphQL client with which you add on features like normalized caching as you grow.
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

(react/preact/svelte) - add operation to the result (#924)

* add operation to the query, mutation and subscription result for react/preact/svelte

* add changeset

* update snapshots

* add operation to initialState

* add operation to svelte initialState

* update more snapshots

* update useMutation snapshot

Co-authored-by: Stephen Cook <stephen@stephencookdev.co.uk>

authored by

Jovi De Croock
Stephen Cook
and committed by
GitHub
7696323f 3a69fe4b

+58 -12
+7
.changeset/hot-turkeys-deliver.md
··· 1 + --- 2 + '@urql/preact': minor 3 + 'urql': minor 4 + '@urql/svelte': minor 5 + --- 6 + 7 + Add the operation to the query, mutation and subscription result.
+1 -1
exchanges/graphcache/default-storage/package.json
··· 15 15 "./package.json": "./package.json" 16 16 }, 17 17 "dependencies": { 18 - "@urql/core": ">=1.12.0", 18 + "@urql/core": ">=1.12.1", 19 19 "wonka": "^4.0.14" 20 20 } 21 21 }
+4 -1
packages/preact-urql/src/hooks/useMutation.ts
··· 2 2 import { DocumentNode } from 'graphql'; 3 3 import { pipe, toPromise } from 'wonka'; 4 4 import { 5 - OperationResult, 5 + Operation, 6 6 OperationContext, 7 7 CombinedError, 8 8 createRequest, 9 + OperationResult, 9 10 } from '@urql/core'; 10 11 import { useClient } from '../context'; 11 12 import { useImmediateState } from './useImmediateState'; ··· 17 18 data?: T; 18 19 error?: CombinedError; 19 20 extensions?: Record<string, any>; 21 + operation?: Operation; 20 22 } 21 23 22 24 export type UseMutationResponse<T, V> = [ ··· 56 58 data: result.data, 57 59 error: result.error, 58 60 extensions: result.extensions, 61 + operation: result.operation, 59 62 }); 60 63 return result; 61 64 });
+9 -1
packages/preact-urql/src/hooks/useQuery.ts
··· 1 1 import { DocumentNode } from 'graphql'; 2 2 import { pipe, subscribe, onEnd } from 'wonka'; 3 3 import { useRef, useCallback } from 'preact/hooks'; 4 - import { OperationContext, RequestPolicy, CombinedError } from '@urql/core'; 4 + import { 5 + OperationContext, 6 + RequestPolicy, 7 + CombinedError, 8 + Operation, 9 + } from '@urql/core'; 5 10 6 11 import { useClient } from '../context'; 7 12 import { useRequest } from './useRequest'; ··· 13 18 stale: false, 14 19 data: undefined, 15 20 error: undefined, 21 + operation: undefined, 16 22 extensions: undefined, 17 23 }; 18 24 ··· 31 37 data?: T; 32 38 error?: CombinedError; 33 39 extensions?: Record<string, any>; 40 + operation?: Operation; 34 41 } 35 42 36 43 export type UseQueryResponse<T> = [ ··· 75 82 error: result.error, 76 83 extensions: result.extensions, 77 84 stale: !!result.stale, 85 + operation: result.operation, 78 86 }); 79 87 }) 80 88 );
+3 -1
packages/preact-urql/src/hooks/useSubscription.ts
··· 1 1 import { DocumentNode } from 'graphql'; 2 2 import { useCallback, useRef } from 'preact/hooks'; 3 3 import { pipe, onEnd, subscribe } from 'wonka'; 4 - import { CombinedError, OperationContext } from '@urql/core'; 4 + import { CombinedError, OperationContext, Operation } from '@urql/core'; 5 5 import { useClient } from '../context'; 6 6 import { useRequest } from './useRequest'; 7 7 import { noop, initialState } from './useQuery'; ··· 23 23 data?: T; 24 24 error?: CombinedError; 25 25 extensions?: Record<string, any>; 26 + operation?: Operation; 26 27 } 27 28 28 29 export type UseSubscriptionResponse<T> = [ ··· 72 73 error: result.error, 73 74 extensions: result.extensions, 74 75 stale: !!result.stale, 76 + operation: result.operation, 75 77 })); 76 78 }) 77 79 );
+1
packages/react-urql/src/hooks/__snapshots__/useMutation.test.tsx.snap
··· 6 6 "error": undefined, 7 7 "extensions": undefined, 8 8 "fetching": false, 9 + "operation": undefined, 9 10 "stale": false, 10 11 } 11 12 `;
+1
packages/react-urql/src/hooks/__snapshots__/useQuery.test.tsx.snap
··· 6 6 "error": undefined, 7 7 "extensions": undefined, 8 8 "fetching": true, 9 + "operation": undefined, 9 10 "stale": false, 10 11 } 11 12 `;
+1
packages/react-urql/src/hooks/__snapshots__/useSubscription.test.tsx.snap
··· 6 6 "error": 5678, 7 7 "extensions": undefined, 8 8 "fetching": true, 9 + "operation": undefined, 9 10 "stale": false, 10 11 } 11 12 `;
+1
packages/react-urql/src/hooks/constants.ts
··· 4 4 error: undefined, 5 5 data: undefined, 6 6 extensions: undefined, 7 + operation: undefined, 7 8 };
+3
packages/react-urql/src/hooks/useMutation.ts
··· 7 7 OperationContext, 8 8 CombinedError, 9 9 createRequest, 10 + Operation, 10 11 } from '@urql/core'; 11 12 12 13 import { useClient } from '../context'; ··· 18 19 data?: T; 19 20 error?: CombinedError; 20 21 extensions?: Record<string, any>; 22 + operation?: Operation; 21 23 } 22 24 23 25 export type UseMutationResponse<T, V> = [ ··· 54 56 data: result.data, 55 57 error: result.error, 56 58 extensions: result.extensions, 59 + operation: result.operation, 57 60 }); 58 61 } 59 62 return result;
+9 -2
packages/react-urql/src/hooks/useQuery.ts
··· 1 1 import { DocumentNode } from 'graphql'; 2 2 import { useCallback, useMemo } from 'react'; 3 3 import { pipe, concat, fromValue, switchMap, map, scan } from 'wonka'; 4 - import { CombinedError, OperationContext, RequestPolicy } from '@urql/core'; 4 + import { 5 + CombinedError, 6 + OperationContext, 7 + RequestPolicy, 8 + Operation, 9 + } from '@urql/core'; 5 10 6 11 import { useClient } from '../context'; 7 12 import { useSource, useBehaviourSubject } from './useSource'; ··· 23 28 data?: T; 24 29 error?: CombinedError; 25 30 extensions?: Record<string, any>; 31 + operation?: Operation; 26 32 } 27 33 28 34 export type UseQueryResponse<T> = [ ··· 68 74 fromValue({ fetching: true, stale: false }), 69 75 pipe( 70 76 query$, 71 - map(({ stale, data, error, extensions }) => ({ 77 + map(({ stale, data, error, extensions, operation }) => ({ 72 78 fetching: false, 73 79 stale: !!stale, 74 80 data, 75 81 error, 82 + operation, 76 83 extensions, 77 84 })) 78 85 ),
+4 -2
packages/react-urql/src/hooks/useSubscription.ts
··· 1 1 import { DocumentNode } from 'graphql'; 2 2 import { useCallback, useRef, useMemo } from 'react'; 3 3 import { pipe, concat, fromValue, switchMap, map, scan } from 'wonka'; 4 - import { CombinedError, OperationContext } from '@urql/core'; 4 + import { CombinedError, OperationContext, Operation } from '@urql/core'; 5 5 6 6 import { useClient } from '../context'; 7 7 import { useSource, useBehaviourSubject } from './useSource'; ··· 23 23 data?: T; 24 24 error?: CombinedError; 25 25 extensions?: Record<string, any>; 26 + operation?: Operation; 26 27 } 27 28 28 29 export type UseSubscriptionResponse<T> = [ ··· 72 73 fromValue({ fetching: true, stale: false }), 73 74 pipe( 74 75 subscription$, 75 - map(({ stale, data, error, extensions }) => ({ 76 + map(({ stale, data, error, extensions, operation }) => ({ 76 77 fetching: true, 77 78 stale: !!stale, 78 79 data, 79 80 error, 80 81 extensions, 82 + operation, 81 83 })) 82 84 ), 83 85 // When the source proactively closes, fetching is set to false
+1
packages/svelte-urql/src/operations/constants.ts
··· 3 3 stale: false, 4 4 error: undefined, 5 5 data: undefined, 6 + operation: undefined, 6 7 extensions: undefined, 7 8 };
+9 -2
packages/svelte-urql/src/operations/query.ts
··· 14 14 toPromise, 15 15 } from 'wonka'; 16 16 17 - import { RequestPolicy, OperationContext, CombinedError } from '@urql/core'; 17 + import { 18 + RequestPolicy, 19 + OperationContext, 20 + CombinedError, 21 + Operation, 22 + } from '@urql/core'; 18 23 19 24 import { Readable } from 'svelte/store'; 20 25 import { DocumentNode } from 'graphql'; ··· 37 42 data?: T; 38 43 error?: CombinedError; 39 44 extensions?: Record<string, any>; 45 + operation?: Operation; 40 46 } 41 47 42 48 export interface QueryStore<T = any, V = object> ··· 67 73 pollInterval: args.pollInterval, 68 74 ...args.context, 69 75 }), 70 - map(({ stale, data, error, extensions }) => ({ 76 + map(({ stale, data, error, extensions, operation }) => ({ 71 77 fetching: false, 72 78 stale: !!stale, 73 79 data, 74 80 error, 75 81 extensions, 82 + operation, 76 83 })) 77 84 ), 78 85 // When the source proactively closes, fetching is set to false
+4 -2
packages/svelte-urql/src/operations/subscription.ts
··· 12 12 publish, 13 13 } from 'wonka'; 14 14 15 - import { OperationContext, CombinedError } from '@urql/core'; 15 + import { OperationContext, CombinedError, Operation } from '@urql/core'; 16 16 import { Readable } from 'svelte/store'; 17 17 import { DocumentNode } from 'graphql'; 18 18 ··· 24 24 variables?: V; 25 25 pause?: boolean; 26 26 context?: Partial<OperationContext>; 27 + operation?: Operation; 27 28 } 28 29 29 30 export type SubscriptionHandler<T, R> = (prev: R | undefined, data: T) => R; ··· 62 63 fromValue({ fetching: true, stale: false }), 63 64 pipe( 64 65 client.subscription<T>(args.query, args.variables, args.context), 65 - map(({ stale, data, error, extensions }) => ({ 66 + map(({ stale, data, error, extensions, operation }) => ({ 66 67 fetching: false, 67 68 stale: !!stale, 68 69 data, 69 70 error, 70 71 extensions, 72 + operation, 71 73 })) 72 74 ), 73 75 // When the source proactively closes, fetching is set to false