-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Relay 10: difficulty with optimistic response and @raw_response_type #3129
Comments
The
So your optimistic response should include |
This warning seems like a false positive, the optimistic response you provided looks correct. |
@josephsavona I see, thank you very much for the explanation. The optimisticResponse: {
updateLead: {
__typename: 'Lead',
__isNode: 'Lead',
id: leadID,
wasSeen: true,
},
}, In this case, the generated types are OK. But I am getting the following false positive (?) warning: BTW the mutation actually returns a union so the transformed query looks like this (prolly not important in this case): mutation SidebarLayoutMarkAsSeenMutation(
$leadID: ID!
) {
updateLead(input: {id: $leadID, wasSeen: true}) {
__typename
... on Lead {
wasSeen
}
... on Node {
__isNode: __typename
id
}
}
} |
Sounds like a bug in the optimistic response validation code, the warning looks incorrect in your case |
@josephsavona hitting something similar. Is there a way to suppress these warnings, to mitigate? |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
I am afraid this is still valid and should not be closed. |
So we are facing a similar problem with using unions and extending the error interface. mutation useCreateNoteMutation($input: CreateNoteInput!, $connections: [ID!]!) @raw_response_type {
createNote(input: $input) {
... on CreateNoteSuccess {
note @appendNode(connections: $connections, edgeTypeName: "NoteEdge") {
id
text
}
}
... on ForbiddenTermError {
blockedTerms
code
message
}
... on Error {
code
message
}
}
} and with generated typescript code export type useCreateNoteMutationRawResponse = {
readonly createNote: {
readonly __typename: "CreateNoteSuccess";
readonly __isError: "CreateNoteSuccess";
readonly code: unknown;
readonly message: string;
readonly note: {
readonly id: string;
readonly text: string;
};
} | {
readonly __typename: "ForbiddenTermError";
readonly __isError: "ForbiddenTermError";
readonly code: unknown;
readonly message: string;
readonly blockedTerms: ReadonlyArray<string | null> | null;
} | {
readonly __typename: string;
readonly __isError: string;
readonly code: unknown;
readonly message: string;
};
}; Where we can see that export type useCreateNoteMutationRawResponse = {
readonly createNote: {
readonly __typename: "CreateNoteSuccess";
readonly note: {
readonly id: string;
readonly text: string;
};
} | {
readonly __typename: "ForbiddenTermError";
readonly code: unknown;
readonly message: string;
readonly blockedTerms: ReadonlyArray<string | null> | null;
} | {
readonly __typename: 'Error';
readonly code: unknown;
readonly message: string;
};
}; |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
@huv1k Do you have some workaround? |
We're seeing something similar to @hub1k's comment with fields from one member of a union being added to other members that do not provide those fields. In our case, our union type contains both |
Hi, we have an issue with an optimistic response when using the new Relay 10. This is our mutation:
And here is how we do the optimistic response:
This works fine with Relay 9, however, Relay 10 generates different Flow (or in our case TS) types which forces us to write also
__isNode
into the optimistic response. That's however also not okay because Relay complains with the following error:Here are the generated types for Flow:
Or for TypeScript which looks fairly similar so I don't think that's the problem:
My question is: how should we handle this situation? I am not sure what is the right strategy here and what does
__isNode
exactly mean in this case. 🤔Thank you very much for having a look!
The text was updated successfully, but these errors were encountered: