amplify-cli: owner subscriptions causing error: '...of type "String!" is required but not provided.'

Framework: Angular 8 Amplify Cli - fresh install today

The responses in regards to the issue that follows have not been useful at all, and i feel maybe I am not explaining well.

I have a messaging system (realtime chat) in which a a conversation (model) links a business and a user together and messages are stored as a connection within this conversation.

On the business website I was expecting to use Amplify subscriptions to implement a real time chat system, however I have been unable to do so using many approaches.

I have implemented authentication rules and multiple owners so as a user generated message will still be streamed into the subscription, given the user will be the owner and not the business. If the business creates the message, then there is no problem as they are the owner. Hence I then followed the docs by creating an owners array which will have owner auth rules applied.

However the only way I can get the subscription to fire is by making the subscription public, which is not ideal.

Could one of the amazon team (@mikeparisstuff @kaustavghosh06 etc) perhaps give some pointers here on how I can achieve the firing of subscriptions.

The models:

Conversation:

type ConvoLink @model(subscriptions: null) {
  id: ID!
  status: String
  createdAt: Float!
  updatedAt: Float!
  messages: [Message] @connection(name: "ConvoMsgs", sortField: "createdAt")
  user: User @connection(name: "UserConversations")
  entity: Entity @connection(name: "EntityConversations")
}

The message

type Message @model
  @auth(rules: [
    { allow: owner },
    { allow: owner, ownerField: "owners" }
  ])
{
  id: ID!
  messageConversationId: ID!
  conversation: ConvoLink @connection(name: "ConvoMsgs")
  content: String!
  contentType: String
  author: String!
  entity: String!
  receiver: String!
  owner: String!
  owners: [String]!
  status: String
  createdAt: Float!
  updatedAt: Float!
}

This completed the push operation to the API, however on graphQL codegen, it fails to create the subsections with the following errors:

…/Ariba/src/graphql/mutations.ts: Field “onCreateMessage” argument “owners” of type “String!” is required but not provided. …/Ariba/src/graphql/mutations.ts: Field “onUpdateMessage” argument “owner” of type “String!” is required but not provided. …/Ariba/src/graphql/mutations.ts: Field “onUpdateMessage” argument “owners” of type “String!” is required but not provided. …/Ariba/src/graphql/mutations.ts: Field “onDeleteMessage” argument “owner” of type “String!” is required but not provided. …/Ariba/src/graphql/mutations.ts: Field “onDeleteMessage” argument “owners” of type “String!” is required but not provided. …/Ariba/src/graphql/mutations.ts: Field “onCreateMessage” argument “owner” of type “String!” is required but not provided. …/Ariba/src/graphql/mutations.ts: Field “onCreateMessage” argument “owners” of type “String!” is required but not provided. …/Ariba/src/graphql/mutations.ts: Field “onUpdateMessage” argument “owner” of type “String!” is required but not provided. …/Ariba/src/graphql/mutations.ts: Field “onUpdateMessage” argument “owners” of type “String!” is required but not provided.

These seem to be warnings however as after, the API file displays the subscription I need:

export const onCreateMessage = `subscription OnCreateMessage($owner: String!, $owners: String!) {
  onCreateMessage(owner: $owner, owners: $owners) {
    id
    messageConversationId
    conversation {
      id.....

And finally my angular service call:

   this.amplify.api().graphql(graphqlOperation(onCreateMessage, { owner: id}))
      .subscribe((newMessage: any) => {
         console.log('NEW MESSAGE RECEIEVED');
         console.log(newMessage)
      }, 
      err => console.log(err))

However it never fires, and the only time I have got it to fire is when I changed the subscriptions to public.

This has been a blocker for weeks now, so any help would be great!

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 20 (5 by maintainers)

Commits related to this issue

Most upvoted comments

@kaustavghosh06 still nothing when trying all the solutions above - it simply wont detect the booking creation. Any help would be great