Can a GraphQL input type inherit from another type or interface?

后端 未结 3 1985
清歌不尽
清歌不尽 2020-12-15 15:00

Is it possible to use inheritance with GraphQL input types?

Something like that (this, of course, doesn\'t work with input types):

interface UserInpu         


        
3条回答
  •  佛祖请我去吃肉
    2020-12-15 15:34

    If you came here looking for an explanation for the "implements", keyword, here it is:

    An object type must be a super‐set of all interfaces it implements. The object type must include a field of the same name for every field defined in an interface.

    (Excerpt taken from the June 2018 GraphQL spec.)

    Here's an example

    
    interface Foo {
      id: ID!
      foo: Int!
    }
    
    type Bar implements Foo @entity {
      id: ID!;
      foo: Int!;
      bar: Int!;
    }
    

    So the Bar type doesn't inherit from the Foo interface, but it implements it. The former must include all the fields that are listed in the latter.

    I think that this is a nice way to annotate types that should be like other types.

提交回复
热议问题