1
1
import { ApolloError } from ".." ;
2
- import { ExecutableDefinitionNode , GraphQLError , parse , Source } from "graphql" ;
3
2
4
3
describe ( "ApolloError" , ( ) => {
5
4
it ( "should construct itself correctly" , ( ) => {
6
5
const graphQLErrors = [
7
- new GraphQLError ( "Something went wrong with GraphQL" ) ,
8
- new GraphQLError ( "Something else went wrong with GraphQL" ) ,
6
+ { message : "Something went wrong with GraphQL" } ,
7
+ { message : "Something else went wrong with GraphQL" } ,
9
8
] ;
10
9
const protocolErrors = [
11
10
{
@@ -41,7 +40,7 @@ describe("ApolloError", () => {
41
40
} ) ;
42
41
43
42
it ( "should add a graphql error to the message" , ( ) => {
44
- const graphQLErrors = [ new GraphQLError ( "this is an error message" ) ] ;
43
+ const graphQLErrors = [ { message : "this is an error message" } ] ;
45
44
const apolloError = new ApolloError ( {
46
45
graphQLErrors,
47
46
} ) ;
@@ -51,8 +50,8 @@ describe("ApolloError", () => {
51
50
52
51
it ( "should add multiple graphql errors to the message" , ( ) => {
53
52
const graphQLErrors = [
54
- new GraphQLError ( "this is new" ) ,
55
- new GraphQLError ( "this is old" ) ,
53
+ { message : "this is new" } ,
54
+ { message : "this is old" } ,
56
55
] ;
57
56
const apolloError = new ApolloError ( {
58
57
graphQLErrors,
@@ -64,7 +63,7 @@ describe("ApolloError", () => {
64
63
} ) ;
65
64
66
65
it ( "should add both network and graphql errors to the message" , ( ) => {
67
- const graphQLErrors = [ new GraphQLError ( "graphql error message" ) ] ;
66
+ const graphQLErrors = [ { message : "graphql error message" } ] ;
68
67
const networkError = new Error ( "network error message" ) ;
69
68
const apolloError = new ApolloError ( {
70
69
graphQLErrors,
@@ -77,7 +76,7 @@ describe("ApolloError", () => {
77
76
} ) ;
78
77
79
78
it ( "should add both protocol and graphql errors to the message" , ( ) => {
80
- const graphQLErrors = [ new GraphQLError ( "graphql error message" ) ] ;
79
+ const graphQLErrors = [ { message : "graphql error message" } ] ;
81
80
const protocolErrors = [
82
81
{
83
82
message : "cannot read message from websocket" ,
@@ -99,46 +98,12 @@ describe("ApolloError", () => {
99
98
} ) ;
100
99
101
100
it ( "should contain a stack trace" , ( ) => {
102
- const graphQLErrors = [ new GraphQLError ( "graphql error message" ) ] ;
101
+ const graphQLErrors = [ { message : "graphql error message" } ] ;
103
102
const networkError = new Error ( "network error message" ) ;
104
103
const apolloError = new ApolloError ( {
105
104
graphQLErrors,
106
105
networkError,
107
106
} ) ;
108
107
expect ( apolloError . stack ) . toBeDefined ( ) ;
109
108
} ) ;
110
-
111
- it ( "will revive `GraphQLError` instances from `graphQLErrors`" , ( ) => {
112
- const source = new Source ( `
113
- {
114
- field
115
- }
116
- ` ) ;
117
- const ast = parse ( source ) ;
118
- const operationNode = ast . definitions [ 0 ] as ExecutableDefinitionNode ;
119
- const fieldNode = operationNode . selectionSet . selections [ 0 ] ;
120
- const original = new GraphQLError ( "msg" /* message */ , {
121
- nodes : [ fieldNode ] ,
122
- source,
123
- positions : [ 1 , 2 , 3 ] ,
124
- path : [ "a" , "b" , "c" ] ,
125
- originalError : new Error ( "test" ) ,
126
- extensions : { foo : "bar" } ,
127
- } ) ;
128
-
129
- const apolloError = new ApolloError ( {
130
- graphQLErrors : [ JSON . parse ( JSON . stringify ( original ) ) ] ,
131
- } ) ;
132
- const graphQLError = apolloError . graphQLErrors [ 0 ] ;
133
-
134
- console . log ( {
135
- graphQLError,
136
- original,
137
- serialized : JSON . stringify ( original ) ,
138
- } ) ;
139
-
140
- expect ( graphQLError ) . toBeInstanceOf ( GraphQLError ) ;
141
- // test equality of enumberable fields. non-enumerable fields will differ
142
- expect ( { ...graphQLError } ) . toStrictEqual ( { ...original } ) ;
143
- } ) ;
144
109
} ) ;
0 commit comments