type-graphql: formatArgumentValidationError causing typescript error
Following along with @benawad fantastic tutorial. On the validation video.
I’m running into an issue when attempting to use formatArgumentValidationError.
import { ApolloServer } from 'apollo-server-express';
import Express from 'express';
import 'reflect-metadata';
import { buildSchema, formatArgumentValidationError } from 'type-graphql';
import { createConnection } from 'typeorm';
import { RegisterResolver } from './modules/user/Register';
const main = async () => {
await createConnection();
const schema = await buildSchema({
resolvers: [RegisterResolver]
});
const apolloServer = new ApolloServer({ schema, formatError: formatArgumentValidationError });
const app = Express();
apolloServer.applyMiddleware({ app });
app.listen(4000, () => {
// tslint:disable-next-line:no-console
console.log('Server started on http://localhost:4000/graphql');
});
};
// tslint:disable-next-line:no-floating-promises
main();
This is resulting in the TS error below
$ ts-node-dev --respawn src/index.ts
Using ts-node version 8.0.2, typescript version 3.3.3333
[ERROR] 09:59:16 ⨯ Unable to compile TypeScript:
src/index.ts(16,51): error TS2322: Type '(err: GraphQLError) => { [key: string]: any; }' is not assignable to type '(error: GraphQLError) => GraphQLFormattedError'.
Type '{ [key: string]: any; }' is missing the following properties from type 'GraphQLFormattedError': message, locations, path
I haven’t seen anyone else complain of this, so it feels like an issue with my setup. But I cannot for the life of me figure out why I am getting it while no one else is.
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 18 (10 by maintainers)
Commits related to this issue
- fix(validation): remove `formatArgumentValidationError` helper — committed to MichalLytek/type-graphql by MichalLytek 5 years ago
@venatir Please check twice before starting to complain:
It was clearly released as the new major version with a “breaking change” notice 😠
I’ve tested that so I will remove the
formatArgumentValidationError
at all as it’s not needed anymore. The first version of ApolloServer, as well as GraphQLYoga, stripped off additional properties, so I had to provide a format helper for that:Fixed via 526886c 🔒
Released in
0.17.0-beta.9
🎉Basically, looks like in new ApolloServer the
formatArgumentValidationError
is not needed anymore as the original error is reflected inextensions
:In the meantime, this is the custom implementation of
formatError
I use with the last version (2.4.6) ofapollo-server-express
:You can’t simply remove functionality. This is a breaking change. Please either maintain compatibility with previous minor versions or bump the major.
There is a lot of weird type changes in
apollo-server
right now: https://github.com/apollographql/apollo-server/pull/2346I will wait for it to settle down and then re-investigate whether it really changed the signature or the API.
for newcommer from this toutorial u van add this
I can confirm this works however add the following lines to your code:
My bad. Was aware of the above (0 Major different behaviour), but I read the version from a different package (apollo-server-core) and somehow was convinced this was v2.10.0 😃 Please ignore me 😃 Either way it’s great too see you guys are so active and answer this fast. Great maintenance work!
@git-no Please read this thread once more - this helper was removed.
@Myiyk See #133 - nested inputs are not an instance, so they can’t be validated using
class-validator
. It’s not a format error fault.