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

Generated models with fields with @connection directive form invalid GraphQLRequest when attempting to update #828

Closed
sandasai opened this issue Oct 15, 2020 · 3 comments
Labels
api Issues related to the API category bug Something isn't working pending-release Code has been merged but pending release Code has been merged but pending release
Milestone

Comments

@sandasai
Copy link

Describe the bug
After generating models via amplify codegen models from a schema model with @connection directive, the update mutations will fail. This is due to the fact that the @connection fields are defined on the models and will be passed into the mutation.

An error will occur along of the lines of: The variables input contains a field name \'notes\' that is not defined for input object type \'UpdateTaskInput\'

To Reproduce
Steps to reproduce the behavior from scratch:

  1. Setup base project amplify with API
  2. Create and deploy schema:
type Task @model {
  id: ID!
  title: String!
  description: String
  status: String
  notes: [Note] @connection(keyName: "byTask", fields: ["id"])
}

type Note
  @model
  @key(name: "byTask", fields: ["taskId"])
{
  id: ID!
  content: String!
  taskId: ID!
  task: Task @connection(fields: ["id"])
}
  1. Create a basic Task:
let task = Task() // ... 
Amplify.API.mutate(request: .create(task))  { // ...
  1. Attempt to update the task
Amplify.API.mutate(request: .update(task))

Observed Behavior
The update results in a GraphQL error since notes will be passed into the mutation, even though it's only used to establish a one-to-many relationship.

Resulting error message:

GraphQLResponseError<Task>: GraphQL service returned a successful response containing errors: [Amplify.GraphQLError(message: "The variables input contains a field name \'notes\' that is not defined for input object type \'UpdateTaskInput\' ", locations: nil, path: nil, extensions: nil)]

Expected Behavior
The update should be successful

Environment(please complete the following information):
Xcode Version: 12.0.1

Device Information (please complete the following information):
Tested in simulators

@diegocstn diegocstn transferred this issue from aws-amplify/aws-sdk-ios Oct 15, 2020
@lawmicha lawmicha added api Issues related to the API category investigating This issue is being investigated labels Oct 16, 2020
drochetti added a commit that referenced this issue Oct 17, 2020
**Notes:**

In some scenarios the fields of type `.collection` were not being
correctly excluded from the `input` of the `GraphQLRequest`.

This change makes sure the fields of type `.collection` are not added to
the input variable.
@drochetti drochetti added the bug Something isn't working label Oct 17, 2020
@drochetti
Copy link
Contributor

Hey @sandasai thanks for reporting this and for providing all the useful details of your use case.

I was able to reproduce it using your schema and I have put a fix out in the PR #837

I wasn't able to reproduce the issue in our unit tests schema though, which is something intriguing. I'm still trying to find the difference between your schema and ours. Regardless, the code change in that PR is a valid one and will be part of the next release.

@drochetti drochetti added pending-release Code has been merged but pending release Code has been merged but pending release and removed investigating This issue is being investigated labels Oct 20, 2020
@drochetti
Copy link
Contributor

The PR #837 was merged, this issue will be closed after a release with the fix it out.

@drochetti drochetti reopened this Oct 20, 2020
@drochetti drochetti added this to the 1.4.0 milestone Oct 20, 2020
@drochetti
Copy link
Contributor

Hey @sandasai, 1.4.0 was released and contains the fix to this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api Issues related to the API category bug Something isn't working pending-release Code has been merged but pending release Code has been merged but pending release
Projects
None yet
Development

No branches or pull requests

3 participants