Closed Benthem closed 1 year ago
There is a couple of reason for not doing it like this:
interface Common {
id: String
}
type Resource implements Common { id: String! }
implicit interfaces would disable this possibility, as it would always be auto-implemented with a nullable `String`.
By forcing the caller to implement it themselves this is possible:
<table>
<thead>
<tr>
<th>
Source GraphQXL
</th>
<th>
Compiled GraphQL
</th>
</tr>
</thead>
<tbody>
<tr>
<td>
```graphql
interface Common {
id: String
}
type Resource implements Common {
...Required<Common>
}
#GraphQXL
interface Common {
id: String
}
type Resource implements Common {
id: String!
}
#GraphQL
With an implicit interface implementation, users are bound to have the implemented fields at the beginning.
Source GraphQXL | Compiled GraphQL |
---|---|
```graphql interface Common { id: String } type Resource implements Common { thisMustComeFirst: Int thisMustBeTheLast: Int } #GraphQXL ``` | ```graphql interface Common { id: String } type Resource implements Common { id: String thisMustComeFirst: Int thisMustBeTheLast: Int } #GraphQL ``` |
But if the implementer uses the spread operator, it is able to choose the position of the implemented fields:
Source GraphQXL | Compiled GraphQL |
---|---|
```graphql interface Common { id: String } type Resource implements Common { thisMustComeFirst: Int ...Common thisMustBeTheLast: Int } #GraphQXL ``` | ```graphql interface Common { id: String } type Resource implements Common { thisMustComeFirst: Int id: String thisMustBeTheLast: Int } #GraphQL ``` |
Honestly, I doubt that this last reason would bother anyone, but who knows 🤷🏼♂️
I have not done a deep research of why the original GraphQL language is not already supporting this, but they may have a reason maybe? here they say something https://github.com/graphql/graphql-spec/issues/335 about it .
Thanks for the great response 😊 Looking forward to using graphqxl in a project
It would seem like a nice step towards DRY if inheritance did not require the spread operator for the exact interface that is implemented.
Would compile to