aws-amplify / amplify-studio

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

Autogenerated code has relationship ID in queries #1065

Open fistofzen opened 10 months ago

fistofzen commented 10 months ago

Before opening, please confirm:

App Id

d22h1kgc6xq1y7

Region

eu-central-1

Environment name

rescue

Figma File Version (if applicable)

No response

Amplify CLI Version

No response

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

No response

What operating system are you using?

No response

Browser type?

No response

Describe the bug

Hello, when I pull the UI Library code, it also generates the relationship ID under queries. for example abcTypesByAbcID is not in queries file.

import { abcTypesByAbcID, getAbc, listTypes, listUsers,

} from "../graphql/queries";

Regards.

Expected behavior

Not create abcTypesByAbcID,

Reproduction steps

pull UI-Library on react.

Project Identifier

No response

Additional information

No response

ykethan commented 10 months ago

Hey @fistofzen, thank you for reaching out. To further dive deeper into the issue, could you provide some additional information. Are you observing the abcTypesByAbcID being generated in the UI components such as forms? is Relationship fields enabled on the UI Library settings? if yes and the use case does not require relationship fields, could you try disabling this and run amplify pull

fistofzen commented 10 months ago

Hello Yes, generated ui has abcTypesByAbcID . It was enabled. I disabled it but the same happened after amplify pull. you can check generated code for WorkoutUpdateForm.jsx.

import { challengeWorkoutsByWorkoutID, coachWorkoutsByWorkoutID, . . . . programWorkoutsByWorkoutID, } from "../graphql/queries";

fistofzen commented 10 months ago

The problem is with relationships flag. when I enable it, it generates the wrong form code as I mentioned above. Is there any workaroubnd for it?

ykethan commented 10 months ago

Hey @fistofzen, to better understand i will need to reproduce the behavior. If the these are auto-generated forms due to data models(GraphQL API). Can you run amplify diagnose --send-report and provide us the Project Identifier output from your terminal.

fistofzen commented 10 months ago

Project Identifier: bcba48597721297b52afcb62d9794b69

fistofzen commented 10 months ago

And also when I debug the code on amplify studio ->Content page. it has the same problem

ykethan commented 10 months ago

Hey @fistofzen, thank you for the information. Tried reproducing the issue but i did not observe the error message or import in the workout update form. the form generated locally had

import { getWorkout } from "../graphql/queries";

was the data model updated?

What is the local Amplify CLI version(amplify -v) and aws-amplify, @aws-amplify/ui-react in the package.json present? i tested the forms using the latest version of cli 12.8.2 and "aws-amplify": "^6.0.3" ,"@aws-amplify/ui-react": "^6.0.2", Could you try upgrading the cli and packages, then run amplify pull to regenerate the components?

fistofzen commented 10 months ago

Hello, I am using relationships.

amplify version is 12.8.2, and versions are : "@aws-amplify/ui-react": "^6.0.2", "@aws-amplify/ui-react-storage": "^1.2.4", "aws-amplify": "^6.0.3",

when you check WorkoutUpdateForm.jsx you will see the challengeWorkoutsByWorkoutId, coachWorkoutsByWorkoutId and others in the jsx file.

import { challengeWorkoutsByWorkoutId, coachWorkoutsByWorkoutId, ... programWorkoutsByWorkoutId, workoutMusleGroupsByWorkoutId, workoutTrainingTypesByWorkoutId, } from "../graphql/queries";

I observed the same issue in UI Library on Amplify Console also. when you check the F12 console as in screenshot image

ykethan commented 10 months ago

Hey @fistofzen, thank you for the information. On enabling the relationship fields in the UI builder did notice some behaviours and errors but wasnt able to replicate the same error message about the ID field not being defined. in my case it was TypeError: record.muscleGroups.toArray is not a function

fistofzen commented 10 months ago

Hello ykethan, will be happy if you delete the screenshots. By the way how can I clear all forms and rebuild them again from ampliy console. maybe this is a cache issue.

ykethan commented 10 months ago

@fistofzen dived into the error message and noticed I was actually running into auth errors on modifying the default auth I was able to mitigate the errors.

Addditonally, locally, I had previously ran amplify update codegen with depth level 3 which may be the reason why i am not experiencing the errors. Could you try modifying as following?

 amplify update codegen
? Choose the code generation language target javascript
? Enter the file name pattern of graphql queries, mutations and subscriptions src/graphql/**/*.js
? Enter maximum statement depth [increase from default if your schema is deeply nested] 3

then run amplify pull

fistofzen commented 9 months ago

Hello, didnt worked. Still seeing the queries with ID ,

import { challengeWorkoutsByWorkoutID, ''' programWorkoutsByWorkoutID, ''' } from "../graphql/queries";

Regards

ykethan commented 9 months ago

Hey @fistofzen, on further diving into the project noticed the cli.json seems to missing some flags, specifically enableAutoIndexQueryNames is missing which may be causing this behavior. Is this project built on a older version of Amplify CLI?

could you update the cli.json to as follows then run push to update the api. could you then check if the challengeWorkoutsByWorkoutID does appear in form queries.

{
    "features": {
        "graphqltransformer": {
            "addmissingownerfields": true,
            "improvepluralization": false,
            "validatetypenamereservedwords": true,
            "useexperimentalpipelinedtransformer": true,
            "enableiterativegsiupdates": true,
            "secondarykeyasgsi": true,
            "skipoverridemutationinputtypes": true,
            "transformerversion": 2,
            "suppressschemamigrationprompt": true,
            "securityenhancementnotification": false,
            "showfieldauthnotification": false,
            "usesubusernamefordefaultidentityclaim": true,
            "usefieldnameforprimarykeyconnectionfield": false,
            "enableautoindexquerynames": true,
            "respectprimarykeyattributesonconnectionfield": true,
            "shoulddeepmergedirectiveconfigdefaults": false,
            "populateownerfieldforstaticgroupauth": true
        },
        "frontend-ios": {
            "enablexcodeintegration": true
        },
        "auth": {
            "enablecaseinsensitivity": true,
            "useinclusiveterminology": true,
            "breakcirculardependency": true,
            "forcealiasattributes": false,
            "useenabledmfas": true
        },
        "codegen": {
            "useappsyncmodelgenplugin": true,
            "usedocsgeneratorplugin": true,
            "usetypesgeneratorplugin": true,
            "cleangeneratedmodelsdirectory": true,
            "retaincasestyle": true,
            "addtimestampfields": true,
            "handlelistnullabilitytransparently": true,
            "emitauthprovider": true,
            "generateindexrules": true,
            "enabledartnullsafety": true,
            "generatemodelsforlazyloadandcustomselectionset": false
        },
        "appsync": {
            "generategraphqlpermissions": true
        },
        "latestregionsupport": {
            "pinpoint": 1,
            "translate": 1,
            "transcribe": 1,
            "rekognition": 1,
            "textract": 1,
            "comprehend": 1
        },
        "project": {
            "overrides": true
        }
    },
    "debug": {}
}
fistofzen commented 9 months ago

Hello, when I replace the cli.json I am getting error when I "amplify push" as below.

Resolution: Please report this issue at https://github.com/aws-amplify/amplify-cli/issues and include the project identifier from: 'amplify diagnose --send-report' Learn more at: https://docs.amplify.aws/cli/project/troubleshooting/ ⠹ Uploading files.🛑 EMFILE: too many open files, open '/Users/XXXX/Technology_Works/XXX/amplify/backend/api/XXX/build/states/initial-stack/resolvers/Workout.muscleGroups.req.vtl'

Resolution: Please report this issue at https://github.com/aws-amplify/amplify-cli/issues and include the project identifier from: 'amplify diagnose --send-report' Learn more at: https://docs.amplify.aws/cli/project/troubleshooting/ ⠏ Uploading files.🛑 Inaccessible host: amplify-XXXXXX-rescued-223335-deployment.s3.eu-central-1.amazonaws.com' at portundefined'. This service may not be available in the `eu-central-1' region.

fistofzen commented 9 months ago

Hello, After adding the line "enableAutoIndexQueryNames" everything worked. Before the amplify version is older but later I upgraded it. How can I also update cli.json file ? Is there a command for it ?

ykethan commented 9 months ago

Hey @fistofzen, typically running amplify update for a resource should prompt you to migrate a resource if built on a older version of cli and and update it. updating the cli.json file and running push should update the resource as well. But diving into the error message it appears to be occurring on a API resource resolver files, i have forwarded the GitHub issue open on the CLI repository to the API repository for further investigation.