-
Notifications
You must be signed in to change notification settings - Fork 199
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
Create mutation fails with datastore - not adding belongsTo parent id to input #298
Comments
Hey onlybakam@, thank you so much for the detailed step through of this issue. Unfortunately, I was unable to get started because I was unable to reproduce the issue. I'm getting stuck when trying to generate the graphql schema. While generating, I get the following error:
|
hey. need to add the field: type Entry @model {
id: ID!
comments: [Comment] @connection(name: "EntryComments", sortField: "createdAt")
}
type Comment @model {
id: ID!
createdAt: AWSDateTime
entry: Entry @connection(name: "EntryComments", sortField: "createdAt")
} |
Hi @onlybakam I investigated this one and it looks like an issue in the GraphQL Transformer in the Amplify CLI (aws-amplify/amplify-cli#3702). I opened an issue in their repo and we will continua to investigate this as we move towards a stable release. |
Issue was closed there but for me the problem was not addressed ... |
Hi @amuresia I tried to reproduce the issue, please let me know if these are the steps followed?
func createEntry(_ sender: Any) {
let entry = Entry()
Amplify.DataStore.save(entry) { (result) in
switch(result) {
case .success(let savedItem):
print("Saved entry: \(savedItem.id)")
self.addComment(entryId: savedItem.id)
case .failure(let error):
print("Could not save item to datastore: \(error)")
}
}
}
func addComment(entryId: String) {
Amplify.DataStore.query(Entry.self, where: Entry.keys.id.eq(entryId)) { result in
switch result {
case .success(let entries):
guard entries.count == 1, let entry = entries.first else {
return
}
let comment = Comment(entry: entry)
Amplify.DataStore.save(comment) { (commentResult) in
switch(commentResult) {
case .success(let savedItem):
print("Saved Comment : \(savedItem.id) \(savedItem.entry?.id)")
case .failure(let error):
print("Could not save item to datastore: \(error)")
}
}
case .failure(let error):
print (error)
}
}
}
Everything worked as expected. |
Hi @royjit, thank you for looking into it. Yes, I believe this was addressed in 1.0.0 and is now working for model types, but not for non-model types. I'll track a separate issue for that though. |
Thank you for verifying. Closing this issue. |
Describe the bug
simple schema:
generates
create a comment with
then do
the resulting generated input variable does not contain commentEntryId; so the mutation fails
this happens because the
entry
field is actually nil in the model at this linehttps://github.com/aws-amplify/amplify-ios/blob/461c3cfd8923fbbb6eb10b60495b0f4594879cf4/AmplifyPlugins/Core/AWSPluginsCore/Model/Support/Model%2BGraphQL.swift#L39
digging into it, it seems like something is off with the Model.from function here:
https://github.com/aws-amplify/amplify-ios/blob/461c3cfd8923fbbb6eb10b60495b0f4594879cf4/Amplify/Categories/DataStore/Model/Model%2BCodable.swift#L39
that is called by
https://github.com/aws-amplify/amplify-ios/blob/461c3cfd8923fbbb6eb10b60495b0f4594879cf4/Amplify/Categories/DataStore/Model/ModelRegistry.swift#L30
You'll notice that the json string being decoded contains all the necessary data to properly reconstruct the model. Also in Modal+codable, if a breakpoint is added, you can do
po try resolvedDecoder.decode(Self.self, from: data)
will show a properly constructed Comment Model with an entry field. However, in ModelRegistry, this field is now nil.Expected behavior
input should be properly created for the mutation to succeed
Environment(please complete the following information):
Device Information (please complete the following information):
The text was updated successfully, but these errors were encountered: