graphql: Error: Abstract methods can only appear within an abstract class

I’m submitting a…


[ ] Regression 
[x] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.

Current behavior

  1. Define parameters in property of the type, like this:
type Cat {
  ...
  food(brand: String): [Food]
}
  1. Restart your server to apply changes. This will add the abstract method to the class of the type in src/graphql.schema.ts:
export class Cat {
    ...
    abstract food(brand?: string): Food[] | Promise<Food[]>;
}
  1. Restart server (to apply any other changes, for example) and you will get the error:

TSError: ⨯ Unable to compile TypeScript: src/graphql.schema.ts(11,5): error TS1244: Abstract methods can only appear within an abstract class.

Expected behavior

Error must not be thrown on server start after src/graphql.schema.ts update

Minimal reproduction of the problem with instructions

https://github.com/biryukvy/nest-gql-abstract-method-issue (Changes, that have been added to reproduce the issue can be found in the commit: 87053d)

What is the motivation / use case for changing the behavior?

It is needed to pass parameters to subqueries

Environment


Nest version: 5.5.0

 
For Tooling issues:
- Node version: 8.14.1  
- Platform: Linux Ubuntu 18.04 

Others:

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 15 (3 by maintainers)

Most upvoted comments

@kamilmysliwiec, the problem is not fixed, could you reopen the issue?

@triedal I just leave auto generation deactivated and turn it on after a change is made on queries or schema, an then fix the types manually. I’d be annoying to do this when the schema/queries are not stable but well 🤷

It actually should be fixed in 5.5.0+