Skip to content
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

Got null data in subscription callback if data is changed inside a lambda function #2974

Closed
2 tasks done
nam-truong-le opened this issue Oct 22, 2024 · 10 comments
Closed
2 tasks done
Assignees
Labels
data-schema pending-community-response Issue is pending a response from the author or community. to-be-reproduced Pending reproduction

Comments

@nam-truong-le
Copy link

How did you install the Amplify CLI?

pnpm

If applicable, what version of Node.js are you using?

20

Amplify CLI Version

1.2.9

What operating system are you using?

Mac

Did you make any manual changes to the cloud resources managed by Amplify? Please describe the changes made.

No

Describe the bug

I follow this Grant Lambda function access to API and Data to update data inside a lambda function.

My subscription in UI is triggered but it gets null data:

Bildschirmfoto 2024-10-22 um 16 25 40

Expected behavior

The callback in the UI should get data.

Reproduction steps

  • Change data in lambda using sth similar to this:
  const { errors: updateApplicationErrors } = await client.graphql({
    query: updateApplication,
    variables: {
      input: {
        id: applicationId,
        status: ApplicationStatus.PAID,
        refundLink,
        paidAt: new Date().toISOString(),
        paymentMethod: PaymentMethod.PAYPAL,
      },
    },
  });
  • subscribe for data update in UI:
useEffect(() => {
    const sub = client.models.Application.onUpdate({
      selectionSet: [...SELECTION],
      authMode: "userPool",
    }).subscribe({
      next: function (application) {
        dispatch(updateApplication(application));
      },
      error: (err) => {
        const { errors } = err;
        console.error("Error update applications triggered by default update", err);
        dispatch(setApplications([]));
        dispatch(setError(errors.map((e: any) => e.message).join("\n\n\n")));
      },
    });
    return () => sub.unsubscribe();
  }, [dispatch]);

Project Identifier

No response

Log output

# Put your logs below this line


Additional information

No response

Before submitting, please confirm:

  • I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.
  • I have removed any sensitive information from my code snippets and submission.
@chrisbonifacio
Copy link
Member

Hi @nam-truong-le can you provide the selection set of the outgoing mutation that is meant to trigger the subscription? I'm curious to see what fields the mutation returns and what fields the subscription is expecting. There might be some conflict between them that is potentially causing an error that makes it seem like the data is null.

You can verify this by checking the network tab, filtering for WS and checking the incoming messages. You should be able to see what data and/or errors were returned from the subscription.

@chrisbonifacio chrisbonifacio added the pending-community-response Issue is pending a response from the author or community. label Oct 24, 2024
@nam-truong-le
Copy link
Author

This is my selection set:

const SELECTION = [
  "id",
  "number",
  "status",
  "billingItems.*",
  "summary.*",
  "data.*",
  "data.applicants.*",
  "data.billing.*",
  "data.options.*",
  "paymentLink",
  "secret",
  "createdAt",
  "updatedAt",
  "paidAt",
  "paymentMethod",
] as const;

@chrisbonifacio
Copy link
Member

@nam-truong-le were you able to check the subscription messages in the network logs?

Also, i noticed your selection set is expecting relational data. Maybe try removing the relational fields. Gen 2 automatically redacts relational data from mutations. That might be causing some conflict with the subscription.

Try only getting the top level, non-relational fields on the model.

@nam-truong-le
Copy link
Author

were you able to check the subscription messages in the network logs?

I will try.

Maybe try removing the relational fields

I don't have relational fields, they are just custom types.

@nam-truong-le
Copy link
Author

I do see data in WS message:

Bildschirmfoto 2024-10-29 um 06 35 33

@chrisbonifacio
Copy link
Member

@nam-truong-le can you check the outgoing mutation and what fields are in its selection set, then compare that to the fields the subscription has in its selection set? please share them as well.

curious to see if there is a mismatch between them. the mutation selection set should be at least a subset of the subscription's.

@nam-truong-le
Copy link
Author

I return full object in mutation and the select set is a sub set of it.

@github-actions github-actions bot added pending-maintainer-response Issue is pending a response from the Amplify team. and removed pending-community-response Issue is pending a response from the author or community. labels Nov 12, 2024
@chrisbonifacio
Copy link
Member

chrisbonifacio commented Nov 15, 2024

@nam-truong-le are you able to share what the mutation selection set looks like for us to reproduce the issue more accurately? i'm not sure what you mean by "full object."

it would help to have the full schema for that model as well.

I'm also curious if you have tried using the subscription + mutation in the appsync console? or if you have tried the subscription with different or no selection sets.

@chrisbonifacio chrisbonifacio added pending-community-response Issue is pending a response from the author or community. and removed pending-maintainer-response Issue is pending a response from the Amplify team. labels Nov 15, 2024
@chrisbonifacio
Copy link
Member

Hi 👋 Closing this as we have not heard back from you. If you are still experiencing this issue and in need of assistance, please feel free to comment and provide us with any information previously requested by our team members so we can re-open this issue and be better able to assist you.

Thank you!

@chrisbonifacio chrisbonifacio closed this as not planned Won't fix, can't repro, duplicate, stale Nov 22, 2024
Copy link

This issue is now closed. Comments on closed issues are hard for our team to see.
If you need more assistance, please open a new issue that references this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
data-schema pending-community-response Issue is pending a response from the author or community. to-be-reproduced Pending reproduction
Projects
None yet
Development

No branches or pull requests

3 participants