It does work in appsync (using subscription directly in appsync works but not in my react ionic app). Ive tried everything.. here is the code:
const onCreateUserConversation = /* GraphQL */ `
subscription OnCreateUserConversation(
$filter: ModelSubscriptionUserConversationFilterInput
) {
onCreateUserConversation(filter: $filter) {
id
}
}
`;
const subscribeUserConversationCreate = () => {
const subscription = API.graphql<
GraphQLSubscription<OnCreateUserConversationSubscription>
>({
query: subscriptions.onCreateUserConversation,
authMode: "API_KEY",
}).subscribe({
next: ({ value }) => console.log(value),
error: (error) => console.error(error),
});
return subscription;
};
useEffect(() => {
getConversations();
console.log("subscribing to convo create");
const subscription = subscribeUserConversationCreate();
return () => subscription.unsubscribe();
}, []);
The mutation from appsync
mutation MyMutation {
createUserConversation(
input: {
userId: "adeldueast",
conversationId: "9f80911e-c221-4474-b92d-922d4d8b2174"
}) {
id
}
}
And finally my schema:
type User @model {
id: ID!
username: String
conversations: [Conversation] @manyToMany(relationName: "UserConversation")
}
type Conversation @model {
id: ID!
name: String!
users: [User] @manyToMany(relationName: "UserConversation")
messages: [Message] @hasMany(indexName: "byConversation", fields: ["id"])
}
type Message @model {
id: ID!
conversationID: ID!
@index(name: "byConversation", sortKeyFields: ["createdAt"])
owner: String!
content: MessageContent!
createdAt: AWSDateTime
}
type MessageContent {
text: String
media: S3Object
}
type S3Object {
bucket: String!
region: String!
key: String!
}