-
Notifications
You must be signed in to change notification settings - Fork 108
-
Hi there!
I tried to use zeus-graphql with interfaces like this
interface Message { createdAt: DateTime! conversation: Conversation! sender: User! readBy: [User!] deliveredTo: [User!] } type TextMessage implements Message { id: ID! createdAt: DateTime! conversation: Conversation! sender: User! readBy: [User!] deliveredTo: [User!] body: String! }
const getConversationMessages = (conversationId: string) => { return thunder('query')({ messagesByConversation: [ { conversationId, last: 20, orderBy: { field: MessageOrderField.CREATED_AT, direction: OrderDirection.ASC, }, }, { pageInfo: { hasPreviousPage: true, startCursor: true, }, edges: { node: { __typename: true, id: true, createdAt: true, sender: { apiId: true, }, conversation: { id: true, }, '...on TextMessage': { body: true }, }, }, }, ], }) }
I wanted to check the __typename and then get the body of TextMessage
But the result type doesn't contain __typename field, it event does't contain body field
Only non-fragment types was inferred: id, createdAt, sender
Does typing works correctly for result types of queries with the fragments?
PS I have checked the same case with genql library and it works as expected
image
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 4 comments
-
Check the example in examples/typescript-node/index.ts I can't help seeing part of the schema and part of the code
Beta Was this translation helpful? Give feedback.
All reactions
-
I tested interfaces right now and they work as as expected @dqunbp please provide schema URL to test your case
Beta Was this translation helpful? Give feedback.
All reactions
-
@aexol Sorry for the long answer
interface Node { id: ID! } interface Message { createdAt: String! } type TextMessage implements Node & Message { id: ID! createdAt: String! body: String! } type MessageEdge { cursor: String! node: Message } type MessageConnection { edges: [MessageEdge]! } type Query { messages: MessageConnection }
Then zeus schema.graphql ./generated
import { Chain } from "./generated/zeus/index"; const chain = Chain("url"); const query = await chain("query")({ messages: { edges: { node: { __typename: true, id: true, createdAt: true, "...on TextMessage": { body: true }, }, }, }, }); query.messages?.edges.map(({ node }) => { node?.id; //exists node?.createdAt; //exists node?.__typename; // <= Property '__typename' does not exist on type '{ id: unknown; createdAt: string; }'. });
zeus --version
5.1.7
Beta Was this translation helpful? Give feedback.
All reactions
-
@aexol Any updates?
Beta Was this translation helpful? Give feedback.