awslabs / aws-mobile-appsync-sdk-js

JavaScript library files for Offline, Sync, Sigv4. includes support for React Native
Apache License 2.0
916 stars 265 forks source link

App sync Mutations Arguments are all { Null: true} Suddenly without any code change #720

Closed NiksanJP closed 1 year ago

NiksanJP commented 2 years ago

Note: If your issue/feature-request/question is regarding the AWS AppSync service, please log it in the official AWS AppSync forum

Do you want to request a feature or report a bug? Bug

What is the current behavior? When I run a mutation from my react-native, all the args are turn to "NULL": true. But all the extra ones like Username from identity stay the same!

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem. The $ctx.args should be able to add proper data into dynamodb

What is the expected behavior? The Dynamodb table should not have null values

Which versions and which environment (browser, react-native, nodejs) / OS are affected by this issue? Did this work in previous versions? React-native, when I woke up the next morning I stopped working, everything was working fine until last night (no changes)

SCHEMA

type Item {
    id: ID!
    Title: String
    Available: Boolean
    PublishDate: String
    Description: String
    Location: String
    Price: String
    Type: String
    Images: String
    tags: String
    UserName: String
    user: User
}

Mutation

`#set($ctx.args.UserName = $ctx.identity.username)
#set($ctx.args.PublishDate = $util.time.nowISO8601())

{
    "version" : "2017-02-28",
    "operation" : "PutItem",
    "key" : {
        "id": $util.dynamodb.toDynamoDBJson($util.autoId()),
    },
    "attributeValues" : $util.dynamodb.toMapValuesJson($ctx.args),
}`

I also tried using $util.dynamodb.toMapValuesJson($context.arguments) but it does not seem to work! $util.dynamodb.toMapValuesJson($ctx.args dynamodb output: image $util.dynamodb.toMapValuesJson($context.arguments) output: image

Native Code

export async function addItem(title, available, description, price, type, images) {
    try{
        console.log(title, available, description, price, type, images)
        let res = await API.graphql(graphqlOperation(createItem, {
            input: {
                Title: title,
                Available: true,
                Description: description,
                Location: "Auburn, Sydney",
                Price: price,
                Type: "rent",
                Images: images,
                tags: ["electronic"]
            }
        }));
        console.log(res)

        return res.data
    }catch(err){
        console.log('error creating item', err)
        return false;
    }
}

Just did some printing, the query that is going to be executed:

{query: '\n  mutation CreateItem(\n    $Available: Boolean\n  …     UserType\n        Verified\n      }\n    }\n  }\n', variables: {…}}
query: "\n  mutation CreateItem(\n    $Available: Boolean\n    $Description: String\n    $Images: String\n    $Location: String\n    $Price: String\n    $Title: String\n    $Type: ItemAdType\n    $tags: [ItemTags]\n  ) {\n    createItem(\n      Available: $Available\n      Description: $Description\n      Images: $Images\n      Location: $Location\n      Price: $Price\n      Title: $Title\n      Type: $Type\n      tags: $tags\n    ) {\n      Available\n      Description\n      Images\n      Location\n      Price\n      PublishDate\n      Title\n      Type\n      UserName\n      id\n      tags\n      user {\n        Address\n        Email\n        FullName\n        MFA\n        PhoneNumber\n        ShowEmail\n        ShowNumber\n        SuburbNo\n        UserJoinDate\n        UserName\n        UserType\n        Verified\n      }\n    }\n  }\n"
variables:
input:
Available: true
Description: "Random description"
Images: "None"
Location: "Sydney"
Price: "2.0"
Title: "No title LMAO"
Type: "rent"
[[Prototype]]: Object
[[Prototype]]: Object
[[Prototype]]: Object

image

From Web image

Logs image

This all worked until last night and suddenly stopped log-events-viewer-result.csv working! No Error Message or anything! But when running on App sync's platform it runs fine!

NiksanJP commented 2 years ago

So basically I created a new table using "Create Resource" button as a test which actually worked.| There is something with graphql not liking other tables ahaha

dperlowaia commented 2 years ago

Mutations and Queries stopped working for me as well. I'm using a lambda function with my own stuff behind it. Was working just fine.

NiksanJP commented 2 years ago

Mutations and Queries stopped working for me as well. I'm using a lambda function with my own stuff behind it. Was working just fine.

Try making the whole DB again from using the "Create Resource" Button. It looks like AWS had a refresh on its functions (maybe) and it uses $ctx.args.input instead of $ctx.args

dperlowaia commented 2 years ago

@NiksanJP Do you queries/mutations work localhost? Mine actually works localhost, but not once pushed to Amplify. So odd. It feels like a permission issue changed.

NiksanJP commented 2 years ago

@NiksanJP Do you queries/mutations work localhost? Mine actually works localhost, but not once pushed to Amplify. So odd. It feels like a permission issue changed.

Nope, mine were fully on server side. Plus, when I used AWS UI, the queries went through without fail hahaha.

iartemiev commented 1 year ago

Glad you were able to resolve this. Appears to have been an issue with the Data Source and/or resolvers you have configured in the service, which are outside the purview of this library.