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.

(core) - Fix ssrExchange not serializing extensions or path on G… (#607)

* Serialise path and extensions on ssrExchange for GraphQLError

* Add changeset

* Update next-urql type

authored by

Phil Plückthun and committed by
GitHub
f9fb49b3 f1a6267a

+50 -5
+6
.changeset/green-owls-pump.md
··· 1 + --- 2 + '@urql/core': patch 3 + 'next-urql': patch 4 + --- 5 + 6 + Add missing GraphQLError serialization for extensions and path field to ssrExchange
+29
packages/core/src/exchanges/ssr.test.ts
··· 71 71 }); 72 72 }); 73 73 74 + it('caches complex GraphQLErrors in query results correctly', () => { 75 + output.mockReturnValueOnce({ 76 + ...queryResponse, 77 + data: null, 78 + error: new CombinedError({ 79 + graphQLErrors: [ 80 + { 81 + message: 'Oh no!', 82 + path: ['Query'], 83 + extensions: { test: true }, 84 + }, 85 + ], 86 + }), 87 + }); 88 + 89 + const ssr = ssrExchange(); 90 + const { source: ops$, next } = input; 91 + const exchange = ssr(exchangeInput)(ops$); 92 + 93 + publish(exchange); 94 + next(queryOperation); 95 + 96 + const error = ssr.extractData()[queryOperation.key].error; 97 + 98 + expect(error).toHaveProperty('graphQLErrors.0.message', 'Oh no!'); 99 + expect(error).toHaveProperty('graphQLErrors.0.path', ['Query']); 100 + expect(error).toHaveProperty('graphQLErrors.0.extensions.test', true); 101 + }); 102 + 74 103 it('resolves cached query results correctly', () => { 75 104 const onPush = jest.fn(); 76 105
+12 -3
packages/core/src/exchanges/ssr.ts
··· 1 + import { GraphQLError } from 'graphql'; 1 2 import { pipe, share, filter, merge, map, tap } from 'wonka'; 2 3 import { Exchange, OperationResult, Operation } from '../types'; 3 4 import { CombinedError } from '../utils'; ··· 5 6 export interface SerializedResult { 6 7 data?: any; 7 8 error?: { 9 + graphQLErrors: Array<Partial<GraphQLError> | string>; 8 10 networkError?: string; 9 - graphQLErrors: string[]; 10 11 }; 11 12 } 12 13 ··· 35 36 error, 36 37 }: OperationResult): SerializedResult => { 37 38 const result: SerializedResult = { data, error: undefined }; 38 - if (error !== undefined) { 39 + if (error) { 39 40 result.error = { 40 - graphQLErrors: error.graphQLErrors.map(x => x.message), 41 + graphQLErrors: error.graphQLErrors.map(error => { 42 + if (!error.path && !error.extensions) return error.message; 43 + 44 + return { 45 + message: error.message, 46 + path: error.path, 47 + extensions: error.extensions, 48 + }; 49 + }), 41 50 networkError: error.networkError ? '' + error.networkError : undefined, 42 51 }; 43 52 }
+1 -1
packages/core/src/utils/error.ts
··· 50 50 response, 51 51 }: { 52 52 networkError?: Error; 53 - graphQLErrors?: Array<string | GraphQLError | Error>; 53 + graphQLErrors?: Array<string | Partial<GraphQLError> | Error>; 54 54 response?: any; 55 55 }) { 56 56 const normalizedGraphQLErrors = (graphQLErrors || []).map(
+2 -1
packages/next-urql/src/types.ts
··· 1 + import { GraphQLError } from 'graphql'; 1 2 import { NextPageContext } from 'next'; 2 3 import { ClientOptions, Exchange, Client } from 'urql'; 3 4 import { AppContext } from 'next/app'; ··· 38 39 export interface SerializedResult { 39 40 data?: any; 40 41 error?: { 42 + graphQLErrors: Array<Partial<GraphQLError> | string>; 41 43 networkError?: string; 42 - graphQLErrors: string[]; 43 44 }; 44 45 } 45 46