aws-amplify / amplify-category-api

The AWS Amplify CLI is a toolchain for simplifying serverless web and mobile development. This plugin provides functionality for the API category, allowing for the creation and management of GraphQL and REST based backends for your amplify project.
https://docs.amplify.aws/
Apache License 2.0
89 stars 79 forks source link

Nested attributes cannot be returned in updateMutation #2636

Closed jo2 closed 4 months ago

jo2 commented 4 months ago

How did you install the Amplify CLI?

npm

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

18.20.3

Amplify CLI Version

12.12.2

What operating system are you using?

Windows

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

no

Describe the bug

I can't run update mutations in my code because the mutation does not return existing nested objects. Although the nested objects do exist, they are not returned in the mutation.

Expected behavior

Allthough the update of the mutation is executed, I'd also expect the nested fields to be returned.

Reproduction steps

These are the query MyQuery and the mutation MyMutation I use:

query MyQuery {
  getBooking(id: "d8d815f9-cf12-475d-b728-1447d301ebbd") {
    id
    staffing {
      id
      project {
        id
      }
    }
    activityDescription
    bookingStatus
    endTime
    startTime
    _version
  }
}

mutation MyMutation {
  updateBooking(input: {id: "d8d815f9-cf12-475d-b728-1447d301ebbd", activityDescription: "TEst", bookingStatus: DRAFT, endTime: "2024-06-10T09:00:00.000+02:00", projectId: "8d49c4e3-870c-4b0a-9ca6-17edab7ae5ab", staffingId: "5e5358cf-e047-4875-9df9-43f2ab5fd145", startTime: "2024-06-10T07:00:00.000+02:00", _version: 45}) {
    id
    staffing {
      id
      project {
        id
      }
    }
    activityDescription
    bookingStatus
    endTime
    startTime
    _version
  }
}

This is the data returned by MyQuery:

{
  "data": {
    "getBooking": {
      "id": "d8d815f9-cf12-475d-b728-1447d301ebbd",
      "staffing": {
        "id": "5e5358cf-e047-4875-9df9-43f2ab5fd145",
        "project": {
          "id": "8d49c4e3-870c-4b0a-9ca6-17edab7ae5ab"
        }
      },
      "activityDescription": "Test",
      "bookingStatus": "DRAFT",
      "endTime": "2024-06-10T09:00:00.000+02:00",
      "startTime": "2024-06-10T07:00:00.000+02:00",
      "_version": 46
    }
  }
}

This is the data returned by MyMutation:

{
  "data": {
    "updateBooking": {
      "id": "d8d815f9-cf12-475d-b728-1447d301ebbd",
      "staffing": null,
      "activityDescription": "Test",
      "bookingStatus": "DRAFT",
      "endTime": "2024-06-10T09:00:00.000+02:00",
      "startTime": "2024-06-10T07:00:00.000+02:00",
      "_version": 47
    }
  },
  "errors": [
    {
      "path": [
        "updateBooking",
        "staffing",
        "id"
      ],
      "locations": null,
      "message": "Cannot return null for non-nullable type: 'ID' within parent 'Staffing' (/updateBooking/staffing/id)"
    }
  ]
}

This is a part of the schema I use, I removed the auth rules and only included the parts of the schema I think are relevant for this issue:

type Booking
@model
@auth(
  rules: [
    ..
  ]
) {
  id: ID!
  bookingStatus: BookingStatus!
  bookingType: BookingType!
  activityDescription: String
  staffingId: ID! @index(name: "byStaffing")
  startTime: AWSDateTime!
  endTime: AWSDateTime
  companyId: ID! @index(name: "byCompany")
  note: String
  reviewerIds: [String!]!
  violations: [ViolationType]
  groupId: ID
  staffing: Staffing @belongsTo(fields: ["staffingId"])
  projectId: ID! @index(name: "byProject")
  employeeId: ID! @index(name: "byEmployee")
  readPermissions: [String!]!
  writePermissions: [String!]!
  lastCheckedBy: ID
  owner: String!
}

type Staffing
@model
@auth(
  rules: [
    ..
  ]
) {
  id: ID!
  staffingType: StaffingType!
  projectId: ID! @index(name: "byProject")
  employeeId: ID! @index(name: "byEmployee")
  bookings: [Booking] @hasMany(indexName: "byStaffing", fields: ["id"])
  companyId: ID! @index(name: "byCompany")
  project: Project @belongsTo(fields: ["projectId"])
  employee: Employee @belongsTo(fields: ["employeeId"])
  readPermissions: [String!]!
  updatePermissions: [String!]!
  writePermissions: [String!]!
}

I can't provide a minimal example project for this issue because this issue happens in only one of my environments. Other environments build in the same way, do not face this issue. The only difference was, that my working environment hat its last build on 2024-06-10 12:48 pm and the build for my failing environment was on the same day at 01:44 pm.

I apreceate any help I can get on this issue because this is blocking me in my project. If you need any more information, I'll gladly provide it.

Project Identifier

7a15e020679dc93ffd0710267d909f36

Log output

``` # Put your logs below this line ```

Additional information

No response

Before submitting, please confirm:

pr0g commented 4 months ago

No joy unfortunately, it doesn't seem to be detecting the change. We're on Amplify Gen 1, V5 (we are using Transformer V2), not sure if that's related. If there's a trick other than making a whitespace change in amplify/cli.json (maybe I need to make a whitespace change in schema.graphql as well?) then do let me know, thank you!

dpilch commented 4 months ago

Oh yes, I should have been more explicit. Make a newline change to your schema.graphql file.

pr0g commented 4 months ago

Ah I see! 😅 The penny's dropped 😝 I'll give that a shot tomorrow, thanks for the info! 🙂

pr0g commented 4 months ago

That did the trick 🥳 Thank you @dpilch, wouldn't be the first time needing to make a whitespace change in schema.graphql has caught me out 🙈

DeezNutz2 commented 4 months ago

Adding this (along with a schema whitespace change and adding some useless fields to be extra-sure)

"subscriptionsInheritPrimaryAuth": true

with amplify version 12.12.4 is still not working for me if I just check it in and let console do a push.

I have to run "amplify push" from a computer, like a moron.

Is there a way to pass this variable that un-bricks my app to the "amplifyPush --simple" command in my amplify.yml?

Also, since this undocumented breaking change seems to be breaking customer prod apps, will the COE be public?

Joscha95 commented 4 months ago

does setting "subscriptionsInheritPrimaryAuth": true work for continous backend deployments as well? or do i need to do amplify push for every environment? it does not seem to propapagate from my dev env to my other environments when i merge the branches and the app gets deployed...

dpilch commented 3 months ago

You will need to do a push for each env.

DeezNutz2 commented 1 month ago

You will need to do a push for each env.

Has this been fixed?

DarylBeattie commented 1 month ago

You will need to do a push for each env.

Has this been fixed?

Not technically. The "subscriptionsInheritPrimaryAuth": true works, though, for now.