Skip to content

Commit d4abb02

Browse files
committed
adjustments
1 parent 4a3bdc0 commit d4abb02

File tree

2 files changed

+11
-47
lines changed

2 files changed

+11
-47
lines changed

.changeset/slimy-berries-yawn.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ to begin with, and the `GraphQLError` class has additional properties that can
99
never be correctly rehydrated from a GraphQL result.
1010
The correct type to use here is `GraphQLFormattedError`.
1111

12-
Similarly, please ensure to use types like
13-
* `FormattedExecutionResult` instead of `ExecutionResult`
14-
the non-"Formatted" versions are for use on the server only,
15-
not for use in client code.
12+
Similarly, please ensure to use the type `FormattedExecutionResult`
13+
instead of `ExecutionResult` - the non-"Formatted" versions of these types
14+
are for use on the server only, but don't get transported over the network.

src/errors/__tests__/ApolloError.ts

Lines changed: 8 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import { ApolloError } from "..";
2-
import { ExecutableDefinitionNode, GraphQLError, parse, Source } from "graphql";
32

43
describe("ApolloError", () => {
54
it("should construct itself correctly", () => {
65
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" },
98
];
109
const protocolErrors = [
1110
{
@@ -41,7 +40,7 @@ describe("ApolloError", () => {
4140
});
4241

4342
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" }];
4544
const apolloError = new ApolloError({
4645
graphQLErrors,
4746
});
@@ -51,8 +50,8 @@ describe("ApolloError", () => {
5150

5251
it("should add multiple graphql errors to the message", () => {
5352
const graphQLErrors = [
54-
new GraphQLError("this is new"),
55-
new GraphQLError("this is old"),
53+
{ message: "this is new" },
54+
{ message: "this is old" },
5655
];
5756
const apolloError = new ApolloError({
5857
graphQLErrors,
@@ -64,7 +63,7 @@ describe("ApolloError", () => {
6463
});
6564

6665
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" }];
6867
const networkError = new Error("network error message");
6968
const apolloError = new ApolloError({
7069
graphQLErrors,
@@ -77,7 +76,7 @@ describe("ApolloError", () => {
7776
});
7877

7978
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" }];
8180
const protocolErrors = [
8281
{
8382
message: "cannot read message from websocket",
@@ -99,46 +98,12 @@ describe("ApolloError", () => {
9998
});
10099

101100
it("should contain a stack trace", () => {
102-
const graphQLErrors = [new GraphQLError("graphql error message")];
101+
const graphQLErrors = [{ message: "graphql error message" }];
103102
const networkError = new Error("network error message");
104103
const apolloError = new ApolloError({
105104
graphQLErrors,
106105
networkError,
107106
});
108107
expect(apolloError.stack).toBeDefined();
109108
});
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-
});
144109
});

0 commit comments

Comments
 (0)