Closed Glognus closed 5 months ago
I've discovered a potential lead on the issue, It appears to be related to conflict resolution settings. Disabling conflict resolution on my API allows the nested relational data to be correctly fetched.
This suggests a potential bug or interoperability issue between AWS Amplify DataStore and AWS Amplify API when conflict resolution is enabled. It seems to interfere with fetching and returning nested relational data.
Is there a workaround or a fix planned for this issue? Any guidance would be appreciated.
Hi @Glognus thanks for raising this issue and providing detailed repro steps! Can you try running the same query in the AppSync console with conflict resolution enabled? This will help rule out whether the DataStore client is the source of the issue.
We'll try to reproduce this internally with the steps given and provide an update soon.
Also, inconsequential to the issue, but were you using conflict detection/resolution purposely? Or do you not need it in your application?
Hi @chrisbonifacio, it return the same result with basicinfos null, i need to use it for my app at least optimistic or merge conflict resolution. Thanks !
Hi @Glognus thank you for the update.
Unfortunately I haven't been able to reproduce this issue.
I tried with the following schema
# This "input" configures a global authorization rule to enable public access to
# all models in this schema. Learn more about authorization rules here: https://docs.amplify.aws/cli/graphql/authorization-rules
input AMPLIFY {
globalAuthRule: AuthRule = { allow: public }
} # FOR TESTING ONLY!
type User @model @auth(rules: [{ allow: private }, { allow: owner }]) {
id: ID!
name: String!
basicInfos: BasicInfos @hasOne
}
enum Gender {
MALE
FEMALE
}
type BasicInfos @model @auth(rules: [{ allow: private }, { allow: owner }]) {
id: ID!
gender: Gender
}
I created a BasicInfo record, then a User with a basicInfoId
to make the relationship.
I received both the User record and BasicInfo nested data on mutation
I then tried the same GetUser
query and received the same response with nested data.
Can you share how you are creating the records? Are you making sure to include a _version
in the mutation arguments when creating a User? This is required for DataStore-enabled APIs (conflict detection enabled) and not including the version can result in no update to the record.
If you are creating a user first, then a BasicInfo, and finally updating a User with the basicInfoId, this might explain why disabling conflict detection results in updates seeming to work normally and able to retrieve the updated User record.
But to be sure, we'd have to see how you are trying to establish the connection between the records.
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!
Before opening, please confirm:
JavaScript Framework
React, React Native
Amplify APIs
GraphQL API
Amplify Version
v6
Amplify Categories
api
Backend
Amplify CLI
Environment information
Describe the bug
I am experiencing an issue with a GraphQL API managed by AWS Amplify, where a
@hasOne
relationship fails to return the expected data. Despite correctly setting up my GraphQL schema with two types,User
andBasicInfos
, and establishing a@hasOne
relationship between them, queries to fetch aUser
along with its relatedBasicInfos
consistently returnnull
for thebasicInfos
field. This occurs even though theuserBasicInfosId
correctly references an existingBasicInfos
record. The issue persists despite confirming data integrity in the database and ensuring appropriate authentication and authorization rules are in place. This unexpected behavior suggests a potential bug in handling@hasOne
relationships within AWS Amplify's GraphQL API.Here's a brief overview of the relevant part of my GraphQL schema:
And the API response where the issue is observed:
The expected behavior is for the
basicInfos
field to return the associatedBasicInfos
object, notnull
. This issue hampers the application's functionality, as it relies on the complete data model for user profiles.Expected behavior
Upon querying the
User
type with its associatedBasicInfos
through a@hasOne
relationship, I expect the API response to include a populatedbasicInfos
object corresponding to theuserBasicInfosId
. The response should detail theBasicInfos
fields such asgender
, etc., reflecting the existing relational data stored in the database. This behavior is anticipated based on the GraphQL schema definition and the established@hasOne
relationship, ensuring a comprehensive retrieval of user profiles, including their basic information, in a single query. The expected response structure would resemble:This outcome is crucial for the application's functionality, as it allows for efficient data retrieval and manipulation, providing a seamless user experience by fetching related data in a single request.
Reproduction steps
Set up the Schema: Start by defining the GraphQL schema with the
User
andBasicInfos
models, ensuring a@hasOne
relationship fromUser
toBasicInfos
. Both models are configured with@auth
directives for private access and ownership.Deploy the API: Deploy the GraphQL API using AWS Amplify. Ensure that the deployment completes successfully and that the database is initialized with the schema defined in step 1.
Create Records: Using the AWS Amplify Console or a GraphQL client, create a
User
record along with a correspondingBasicInfos
record. Ensure to link theBasicInfos
record to theUser
by setting theuserBasicInfosId
field.Query the Data: Execute a GraphQL query to fetch a
User
along with itsbasicInfos
. The query should look something like this:Replace
"user_id_here"
with the actual ID of theUser
record you created in step 3.Observe the Issue: Despite the correct setup and existence of the related
BasicInfos
record, the response for thebasicInfos
field returnsnull
instead of the expected populated object.Code Snippet
No response
Log output
No response
aws-exports.js
No response
Manual configuration
No response
Additional configuration
No response
Mobile Device
iPhone 15 Pro
Mobile Operating System
IOS 17.2
Mobile Browser
No response
Mobile Browser Version
No response
Additional information and screenshots
No response