Closed zainab404 closed 3 months ago
Hi @zainab404 👋 thanks for raising this issue. If you are experiencing issues with the return value in mutation resolvers, you might be running into the behavior explained in a warning in our docs for relational data:
With versions of Amplify CLI @aws-amplify/cli@12.12.2 and API Category@aws-amplify/amplify-category-api@5.11.5, an improvement was made to how relational field data is handled in subscriptions when different authorization rules apply to related models in a schema. The improvement redacts the values for the relational fields, displaying them as null or empty, to prevent unauthorized access to relational data. This redaction occurs whenever it cannot be determined that the child model will be protected by the same permissions as the parent model.
Because subscriptions are tied to mutations and the selection set provided in the result of a mutation is then passed through to the subscription, relational fields in the result of mutations must be redacted.
If an authorized end-user needs access to the redacted relational field they should perform a query to read the relational data.
Additionally, subscriptions will inherit related authorization when relational fields are set as required. To better protect relational data, consider modifying the schema to use optional relational fields.
Based on the security posture of your application, you can choose to revert to the subscription behavior before this improvement was made.
To do so, use the
subscriptionsInheritPrimaryAuth
feature flag undergraphqltransformer
in theamplify/backend/cli.json
file.
- If enabled, subscriptions will inherit the primary model authorization rules for the relational fields.
- If disabled, relational fields will be redacted in mutation response when there is a difference between auth rules between primary and related models.
Ah I see, that worked, thanks so much!
Before opening, please confirm:
JavaScript Framework
React
Amplify APIs
GraphQL API
Amplify Version
Older than v5
Amplify Categories
api
Backend
None
Environment information
Describe the bug
I'm having an issue with a GraphQL mutation using amplify. The mutation itself completes successfully, but an error is thrown when the resolver tries to return the mutated item. It's fetching a connection, which returns null despite the connection existing and working in queries
Expected behavior
What's expected to happen, and what has been working for the last 2 years is that the connection fetches as expected (with it's existing values). Thus, the return of the mutated item does not throw any errors as all expected fields exist and aren't null for any required fields.
Reproduction steps
Code Snippet
Log output
aws-exports.js
No response
Manual configuration
No response
Additional configuration
No response
Mobile Device
No response
Mobile Operating System
No response
Mobile Browser
No response
Mobile Browser Version
No response
Additional information and screenshots
Mutation from AppSync console
My workaround has been to create custom mutations that do not fetch the connection, this allows for the mutation to run without throwing error.
Please let me know if any other information is needed, help is much appreciated :')