typegql icon indicating copy to clipboard operation
typegql copied to clipboard

Any plans for adding interface support?

Open ruhnowg opened this issue 7 years ago • 2 comments

Do you currently have any plans for adding support for GraphQLInterfaceType?

ruhnowg avatar Apr 11 '18 20:04 ruhnowg

I'll add such support hopefully this or next week.

pie6k avatar Apr 12 '18 08:04 pie6k

I have a suggestion for this but that may entail a breaking change:

const IPerson = InterfaceType("IPerson", { ... })
const Person = ObjectType({ ... }) // Or ObjectType("Person", { ... })

@IPerson.Type()
@Person.Type()
class Person  {

    @IPerson.Field()
    @Person.Field()
    name: string;

    @Person.Field({type: GraphQLDate})
    dob: Date

    @IPerson.Field()
    @Person.Field()
    age() {
         return moment(this.dob).diff(moment(), 'year');
    }
}

This allows using the same implementation as a basis for multiple Object types, interface types or input types.

When implementing just an object type, this verbosity can be reduced by destructuring:

const {Type, Field} = ObjectType({... });

@Type()
class Person {
    @Field() 
    name: string;

    // ....
}

Let me know what you think.

lorefnon avatar Apr 28 '18 04:04 lorefnon