Closed
Description
I'm working on a Chat Application which have several types of Messages.
Our graphql schema is defined as below. (we call a chat as 'counsel' in this project)
interface Message {
id: ID!
author: User!
counsel: Counsel!
createdAt: DateTime!
}
type TextMessage implements Message {
id: ID!
author: User!
counsel: Counsel!
createdAt: DateTime!
body: String!
}
type FileMessage implements Message {
id: ID!
author: User!
counsel: Counsel!
createdAt: DateTime!
file: File!
}
type ShopMessage implements Message {
id: ID!
author: User!
counsel: Counsel!
createdAt: DateTime!
shop: Shop!
}
type InvoiceMessage implements Message {
id: ID!
author: User!
counsel: Counsel!
createdAt: DateTime!
order: Order!
}
# etc...
For the frontend react application, I wanted to add local only field status
on Message
interface to control UI of message sending status.
Expected Behavior
// src/utils/cache.ts
// use local only 'status' field on every type of Messages!
export const typeDefs = gql`
enum MessageStatus {
PENDING
SENT
FAILED
}
extend interface Message {
status: MessageStatus!
}
`;
When I run graphql codegenerator after writing code as above, it gave me Error log as below.
Error: Type EndWarningMessage must only implement Interface types, it
cannot implement Message.
Type EnterMessage must only implement Interface types, it cannot impl
ement Message.
Type FileMessage must only implement Interface types, it cannot imple
ment Message.
Type InvoiceMessage must only implement Interface types, it cannot im
plement Message.
Type LeaveMessage must only implement Interface types, it cannot impl
ement Message.
Type RestartMessage must only implement Interface types, it cannot im
plement Message.
Type ShopMessage must only implement Interface types, it cannot imple
ment Message.
Type TextMessage must only implement Interface types, it cannot imple
ment Message.
What I had to do to work
After reading Error log and trying several times, I've succeed to let Application work, but I had to add status
field for every implemented Message types as described below.
// src/utils/cache.ts
export const typeDefs = gql`
enum MessageStatus {
PENDING
SENT
FAILED
}
extend type TextMessage {
status: MessageStatus!
}
extend type FileMessage {
status: MessageStatus!
}
extend type ShopMessage {
status: MessageStatus!
}
extend type InvoiceMessage {
status: MessageStatus!
}
`;
Question
Is there any cool way to extend my Message interface, which can add my status
field to every type of Messages at once?