aws-amplify / amplify-studio

AWS Amplify Studio (Formerly Admin UI)
136 stars 31 forks source link

Getting "Cannot return null for non-nullable type: 'AWSDateTime' within parent" #1111

Open fadone8 opened 3 months ago

fadone8 commented 3 months ago

Description

I am getting the following error in onUpdate when subscribed to real-time events on both onCreate and onUpdate. When an object is created, I am successfully receiving event.data in onCreate subscription but I am receiving an error in onUpdate subscription. Here is the error event in onUpdate:

I/flutter ( 3828): GraphQLResponse<Order>: {
I/flutter ( 3828):   "data": null,
I/flutter ( 3828):   "errors": [
I/flutter ( 3828):     {
I/flutter ( 3828):       "message": "Cannot return null for non-nullable type: 'AWSDateTime' within parent 'Order' (/onUpdateOrder/createdAt)",
I/flutter ( 3828):       "path": [
I/flutter ( 3828):         "onUpdateOrder",
I/flutter ( 3828):         "createdAt"
I/flutter ( 3828):       ]
I/flutter ( 3828):     },
I/flutter ( 3828):     {
I/flutter ( 3828):       "message": "Cannot return null for non-nullable type: 'AWSDateTime' within parent 'Order' (/onUpdateOrder/updatedAt)",
I/flutter ( 3828):       "path": [
I/flutter ( 3828):         "onUpdateOrder",
I/flutter ( 3828):         "updatedAt"
I/flutter ( 3828):       ]
I/flutter ( 3828):     }
I/flutter ( 3828):   ]
I/flutter ( 3828): }

Code:

void subscribeToOrderCreate() {
    final subscriptionRequest = ModelSubscriptions.onCreate(Order.classType);

    final Stream<GraphQLResponse<Order>> operation = Amplify.API.subscribe(
      subscriptionRequest,
      onEstablished: () => safePrint('Order create subscription established'),
    );

    subscription = operation.listen(
      (event) {
        safePrint(event);
      },
      onError: (Object e) =>
          safePrint('Error in order create subscription stream: $e'),
    );
  }
void subscribeToOrderUpdate() {
    final subscriptionRequest = ModelSubscriptions.onUpdate(Order.classType);

    final Stream<GraphQLResponse<Order>> operation = Amplify.API.subscribe(
      subscriptionRequest,
      onEstablished: () => safePrint('Order update subscription established'),
    );

    subscription = operation.listen(
      (event) {
        safePrint(event);
      },
      onError: (Object e) =>
          safePrint('Error in order update subscription stream: $e'),
    );
  }

Categories

Steps to Reproduce

  1. Subscribe to onCreate and onUpdate on a model.
  2. Create an object in that model.
  3. onUpdate subscription will receive the above error:

Screenshots

No response

Platforms

Flutter Version

Flutter 3.22.1

Amplify Flutter Version

2.4.0

Deployment Method

Amplify CLI (Gen 1)

Schema

enum DubbingType {
  ORIGNAL
  REPLACED
}

enum OrderStatus {
  TRANSCRIBE
  TRANSCRIBING
  TRANSCRIBE_COMPLETED
  TRANSLATE
  TRANSLATING
  TRANSLATE_COMPLETED
  GENERATE_MERGE_AUDIO
  GENERATE_MERGE_AUDIO_COMPLETED
  PURCHASE
  COMPLETED
  FAILED
  CANCELLED
}

type Order @model @auth(rules: [{ allow: public }]) {
  id: ID!
  userId: ID
  title: String
  url: AWSURL
  status: OrderStatus
  duration: Int
  fps: Float
  orgLanguageIso: String
  newLanguageName: String
  newLanguageIso: String
  cost: Int
  orgVideoKey: String
  orgLanguageName: String
  orgSrtKey: String
  newSrtKey: String
  orgTranscriptKey: String
  newTranscriptKey: String
  orgWaveformKey: String
  newWaveformKey: String
  newAudioKey: String
  paid: Boolean
  newVideoKey: String
  dubbingType: DubbingType
  configKey: String
  retryCount: Int
  progress: Float
  failedReason: String
}

type Subscription {
  onOrderById(id: ID!): Order @aws_subscribe(mutations: ["updateOrder"])
}
  1. Why onUpdate subscription is receiving this event in the first place when an item is created only?
  2. Both the createdAt and updatedAt are helper fields and not explicitly overwritten. These fields are populated by Amplify.
Jordan-Nelson commented 2 months ago

@fadone8 - Thanks for taking the time to open this issue. It is expected that the event is received on all devices including the device that creates or updates the model.

For the issue you are seeing, can you let me know if you have enabled conflict resolution so that we can reproduce this? Thanks.

fadone8 commented 2 months ago

It error occurs only when an item is created in Amplify Studio manage content. The conflict resolution is disabled.

Jordan-Nelson commented 2 months ago

Okay. I am going to transfer this to Amplify Studio then. It seems like the issue is that models create in Amplify Studio are not getting all the required field.

fistofzen commented 2 months ago

@Jordan-Nelson Is there any solution ? I am also getting the error when I create something from Content in studio. Cannot return null for non-nullable type: 'AWSDateTime' within parent

fistofzen commented 1 month ago

Hello, so is there any solution ?