From d4abb0258116837fee1c4d703b4e73ace99ff271 Mon Sep 17 00:00:00 2001 From: Lenz Weber-Tronic Date: Tue, 9 Jul 2024 16:55:53 +0200 Subject: [PATCH] adjustments --- .changeset/slimy-berries-yawn.md | 7 ++-- src/errors/__tests__/ApolloError.ts | 51 +++++------------------------ 2 files changed, 11 insertions(+), 47 deletions(-) diff --git a/.changeset/slimy-berries-yawn.md b/.changeset/slimy-berries-yawn.md index 6bb557dfce..d2564d6d04 100644 --- a/.changeset/slimy-berries-yawn.md +++ b/.changeset/slimy-berries-yawn.md @@ -9,7 +9,6 @@ to begin with, and the `GraphQLError` class has additional properties that can never be correctly rehydrated from a GraphQL result. The correct type to use here is `GraphQLFormattedError`. -Similarly, please ensure to use types like -* `FormattedExecutionResult` instead of `ExecutionResult` -the non-"Formatted" versions are for use on the server only, -not for use in client code. +Similarly, please ensure to use the type `FormattedExecutionResult` +instead of `ExecutionResult` - the non-"Formatted" versions of these types +are for use on the server only, but don't get transported over the network. diff --git a/src/errors/__tests__/ApolloError.ts b/src/errors/__tests__/ApolloError.ts index 1f60c22590..e672536f66 100644 --- a/src/errors/__tests__/ApolloError.ts +++ b/src/errors/__tests__/ApolloError.ts @@ -1,11 +1,10 @@ import { ApolloError } from ".."; -import { ExecutableDefinitionNode, GraphQLError, parse, Source } from "graphql"; describe("ApolloError", () => { it("should construct itself correctly", () => { const graphQLErrors = [ - new GraphQLError("Something went wrong with GraphQL"), - new GraphQLError("Something else went wrong with GraphQL"), + { message: "Something went wrong with GraphQL" }, + { message: "Something else went wrong with GraphQL" }, ]; const protocolErrors = [ { @@ -41,7 +40,7 @@ describe("ApolloError", () => { }); it("should add a graphql error to the message", () => { - const graphQLErrors = [new GraphQLError("this is an error message")]; + const graphQLErrors = [{ message: "this is an error message" }]; const apolloError = new ApolloError({ graphQLErrors, }); @@ -51,8 +50,8 @@ describe("ApolloError", () => { it("should add multiple graphql errors to the message", () => { const graphQLErrors = [ - new GraphQLError("this is new"), - new GraphQLError("this is old"), + { message: "this is new" }, + { message: "this is old" }, ]; const apolloError = new ApolloError({ graphQLErrors, @@ -64,7 +63,7 @@ describe("ApolloError", () => { }); it("should add both network and graphql errors to the message", () => { - const graphQLErrors = [new GraphQLError("graphql error message")]; + const graphQLErrors = [{ message: "graphql error message" }]; const networkError = new Error("network error message"); const apolloError = new ApolloError({ graphQLErrors, @@ -77,7 +76,7 @@ describe("ApolloError", () => { }); it("should add both protocol and graphql errors to the message", () => { - const graphQLErrors = [new GraphQLError("graphql error message")]; + const graphQLErrors = [{ message: "graphql error message" }]; const protocolErrors = [ { message: "cannot read message from websocket", @@ -99,7 +98,7 @@ describe("ApolloError", () => { }); it("should contain a stack trace", () => { - const graphQLErrors = [new GraphQLError("graphql error message")]; + const graphQLErrors = [{ message: "graphql error message" }]; const networkError = new Error("network error message"); const apolloError = new ApolloError({ graphQLErrors, @@ -107,38 +106,4 @@ describe("ApolloError", () => { }); expect(apolloError.stack).toBeDefined(); }); - - it("will revive `GraphQLError` instances from `graphQLErrors`", () => { - const source = new Source(` - { - field - } - `); - const ast = parse(source); - const operationNode = ast.definitions[0] as ExecutableDefinitionNode; - const fieldNode = operationNode.selectionSet.selections[0]; - const original = new GraphQLError("msg" /* message */, { - nodes: [fieldNode], - source, - positions: [1, 2, 3], - path: ["a", "b", "c"], - originalError: new Error("test"), - extensions: { foo: "bar" }, - }); - - const apolloError = new ApolloError({ - graphQLErrors: [JSON.parse(JSON.stringify(original))], - }); - const graphQLError = apolloError.graphQLErrors[0]; - - console.log({ - graphQLError, - original, - serialized: JSON.stringify(original), - }); - - expect(graphQLError).toBeInstanceOf(GraphQLError); - // test equality of enumberable fields. non-enumerable fields will differ - expect({ ...graphQLError }).toStrictEqual({ ...original }); - }); });