Reputation: 1180
Is it possible any input extend other input on graphql schema?
example below:
input PaginationInput{
pageSize: Int
pageNum: Int
}
# // example for extending input Pagination
input MyFilterInput implement_or_extend PaginationInput {
attr1: String
}
type Query {
usingMyFilter(filter: MyFilterInput): Any
}
Is there any way to do this?
Upvotes: 2
Views: 3240
Reputation: 24035
For me, the important part was that the @InputType()
is required even on the class that you're inheriting.
https://typegraphql.com/docs/inheritance.html says:
Note that both the subclass and the parent class must be decorated with the same type of decorator, like
@ObjectType()
in the example Person -> Student above. Mixing decorator types across parent and child classes is prohibited and might result in a schema building error, e.g. we can't decorate the subclass with@ObjectType()
and the parent with@InputType()
.
I had:
@InputType()
export class InputA extends InputB
but my InputB didn't have @InputType()
above it.
Adding it solved my problem.
Upvotes: 0
Reputation: 25649
Unfortunately, No. An ObjectType
can use Interfaces to extend abstract types, but an InputType
cannot.
GraphQL specs: Object types can contain fields that define arguments or contain references to interfaces and unions, neither of which is appropriate for use as an input argument. For this reason, input objects have a separate type in the system.
There is an input extends ExistingInputType
extension syntax in the specs, but this does not create a new type, but rather adds new fields to an existing input.
Upvotes: 2