api-platform icon indicating copy to clipboard operation
api-platform copied to clipboard

Mutation returns wrong payload

Open phtmgt opened this issue 3 years ago • 0 comments

API Platform version(s) affected: 2.6.8

Description

We have a Message in a ManyToOne with Conversation (one conversation -> many messages). I create a message with a mutation, but the result of the mutation is wrong. Instead of returning the actual Messages in the toMany relationship, it returns all messages from the database.

If I manually refresh the query, the result is correct. The wrong result is shown only in the response of the mutation.

type Message implements Node {
  id: ID!
  content: String!
  unread: Boolean
  user: User
  conversation: Conversation
  createdAt: String!
}

type Conversation implements Node {
  id: ID!
  _id: Int!
  participants: [Participant]
  lastMessage: Message
  messages: [Message]
}

type updateMessagePayload {
  message: Message
  clientMutationId: String
}
const mutation = graphql`
  mutation ConversationMutation(
    $input: createMessageInput!
  ) {
    createMessage(input: $input) {
      message {
        conversation {
          id
          messages {
            createdAt
            content
            user {
              _id
            }
          }
        }
      }
    }
  }
`;

commit({
      variables: {
        input: {
          content: message,
          conversation: conversation.id,
          user: user.id,
        },
      },
      onCompleted: () => {
        // refresh();
        setMessage('');
        messagesEndRef.current.scrollIntoView({ behavior: 'smooth' });
      }
    });

phtmgt avatar Feb 22 '22 13:02 phtmgt