Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Typings for grapqhl interfaces #307

Unanswered
dqunbp asked this question in Q&A
Discussion options

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?

image

PS I have checked the same case with genql library and it works as expected
image

You must be logged in to vote

Replies: 4 comments

Comment options

Check the example in examples/typescript-node/index.ts I can't help seeing part of the schema and part of the code

You must be logged in to vote
0 replies
Comment options

I tested interfaces right now and they work as as expected @dqunbp please provide schema URL to test your case

You must be logged in to vote
0 replies
Comment options

@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

You must be logged in to vote
0 replies
Comment options

@aexol Any updates?

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants

AltStyle によって変換されたページ (->オリジナル) /