Input extend other input on graphql schema

Input extend other input on graphql schema


2

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?

2 Answers
2


2

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.

1

  • Thank you for your answer.

    – Dilermando Lima

    Nov 29, 2021 at 18:57


0

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.



Leave a Reply

Your email address will not be published. Required fields are marked *