Skip to content

Commit

Permalink
Remove formatErrors from Apollo server (#6198)
Browse files Browse the repository at this point in the history
  • Loading branch information
timleslie authored Jul 27, 2021
1 parent 5cd8ffd commit 9d361c1
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 121 deletions.
5 changes: 5 additions & 0 deletions .changeset/happy-seals-cheat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@keystone-next/keystone': major
---

Removed the `uid` and `name` properties from the errors returned by the GraphQL API.
2 changes: 0 additions & 2 deletions packages/keystone/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,7 @@
"react": "^17.0.2",
"react-dom": "^17.0.2",
"resolve": "^1.20.0",
"serialize-error": "^8.1.0",
"source-map-support": "^0.5.19",
"stack-utils": "^2.0.3",
"typescript": "^4.3.5",
"uid-safe": "^2.1.5",
"uuid": "^8.3.2"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ export function GraphQLErrorNotice({ errors, networkError }: GraphQLErrorNoticeP
<Stack gap="small">
{errors.map(err => {
const errButAny: any = err;
if (err.name === 'ValidationFailureError' && errButAny.data?.messages?.length) {
if (
err.message === 'You attempted to perform an invalid mutation' &&
errButAny.data?.messages?.length
) {
return errButAny.data.messages.map((message: string) => (
<Notice tone="negative">{message}</Notice>
));
Expand Down
2 changes: 0 additions & 2 deletions packages/keystone/src/lib/server/createApolloServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { ApolloServer as ApolloServerExpress } from 'apollo-server-express';
import type { Config } from 'apollo-server-express';
import type { CreateContext, SessionStrategy } from '@keystone-next/types';
import { createSessionContext } from '../../session';
import { formatError } from './format-error';

export const createApolloServerMicro = ({
graphQLSchema,
Expand Down Expand Up @@ -87,7 +86,6 @@ const _createApolloServerConfig = ({
return {
uploads: false,
schema: graphQLSchema,
formatError, // TODO: this needs to be discussed
// FIXME: support for apollo studio tracing
// ...(process.env.ENGINE_API_KEY || process.env.APOLLO_KEY
// ? { tracing: true }
Expand Down
99 changes: 0 additions & 99 deletions packages/keystone/src/lib/server/format-error.ts

This file was deleted.

14 changes: 4 additions & 10 deletions tests/api-tests/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,10 @@ export const apiTestConfig = (
});

const unpackErrors = (errors: readonly any[] | undefined) =>
(errors || []).map(
({ locations, uid, extensions: { exception, ...extensions }, ...unpacked }) => ({
extensions,
...unpacked,
})
);
(errors || []).map(({ locations, extensions: { exception, ...extensions }, ...unpacked }) => ({
extensions,
...unpacked,
}));

export const expectInternalServerError = (
errors: readonly any[] | undefined,
Expand All @@ -32,7 +30,6 @@ export const expectInternalServerError = (
expect(unpackedErrors).toEqual(
args.map(({ path, message }) => ({
extensions: { code: 'INTERNAL_SERVER_ERROR' },
name: 'GraphQLError',
path,
message,
}))
Expand All @@ -47,7 +44,6 @@ export const expectGraphQLValidationError = (
expect(unpackedErrors).toEqual(
args.map(({ message }) => ({
extensions: { code: 'GRAPHQL_VALIDATION_FAILED' },
name: 'ValidationError',
message,
}))
);
Expand Down Expand Up @@ -91,7 +87,6 @@ export const expectPrismaError = (
expect(unpackedErrors).toEqual(
args.map(({ path, message }) => ({
extensions: { code: 'INTERNAL_SERVER_ERROR' },
name: 'GraphQLError',
path,
message,
}))
Expand Down Expand Up @@ -121,7 +116,6 @@ export const expectBadUserInput = (
expect(unpackedErrors).toEqual(
args.map(({ path, message }) => ({
extensions: { code: 'INTERNAL_SERVER_ERROR' },
name: 'GraphQLError',
path,
message,
}))
Expand Down
7 changes: 0 additions & 7 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -11895,13 +11895,6 @@ [email protected]:
range-parser "~1.2.1"
statuses "~1.5.0"

serialize-error@^8.1.0:
version "8.1.0"
resolved "https://registry.yarnpkg.com/serialize-error/-/serialize-error-8.1.0.tgz#3a069970c712f78634942ddd50fbbc0eaebe2f67"
integrity sha512-3NnuWfM6vBYoy5gZFvHiYsVbafvI9vZv/+jlIigFn4oP4zjNPK3LhcY0xSCgeb1a5L8jO71Mit9LlNoi2UfDDQ==
dependencies:
type-fest "^0.20.2"

[email protected]:
version "1.14.1"
resolved "https://registry.yarnpkg.com/serve-static/-/serve-static-1.14.1.tgz#666e636dc4f010f7ef29970a88a674320898b2f9"
Expand Down

1 comment on commit 9d361c1

@vercel
Copy link

@vercel vercel bot commented on 9d361c1 Jul 27, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.