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

All Models are nested deeper under "type" #2530

Open
ideen1 opened this issue May 7, 2024 · 5 comments
Open

All Models are nested deeper under "type" #2530

ideen1 opened this issue May 7, 2024 · 5 comments
Assignees
Labels
data-schema Gen 2 investigating question Further information is requested

Comments

@ideen1
Copy link

ideen1 commented May 7, 2024

Environment information

System:
  OS: macOS 13.6.6
  CPU: (10) arm64 Apple M1 Pro
  Memory: 196.94 MB / 16.00 GB
  Shell: /bin/zsh
Binaries:
  Node: 20.10.0 - /usr/local/bin/node
  Yarn: 1.22.22 - /usr/local/bin/yarn
  npm: 10.2.3 - /usr/local/bin/npm
  pnpm: undefined - undefined
NPM Packages:
  @aws-amplify/backend: 1.0.0
  @aws-amplify/backend-cli: 1.0.1
  aws-amplify: 6.2.0
  aws-cdk: Not Found
  aws-cdk-lib: 2.138.0
  typescript: 5.4.5
AWS environment variables:
  AWS_STS_REGIONAL_ENDPOINTS = regional
  AWS_NODEJS_CONNECTION_REUSE_ENABLED = 1
  AWS_SDK_LOAD_CONFIG = 1
No CDK environment variables

Description

After updating @aws-amplify/backend to 1.0.0, all of my model's data is now nested one level deeper under a field called type. For Example, before I could go client.models.list().data.id whereas now I must go client.models.list().data.type.id

Potential cause: It seems to be introduced by a version bump of data-schema in PR aws-amplify/amplify-backend#1399
A type field has been added to the InternalClientSchema type within data-schema.

@ykethan
Copy link

ykethan commented May 7, 2024

Hey👋 thanks for raising this! I'm going to transfer this over to our API repository for better assistance 🙂

@ykethan ykethan transferred this issue from aws-amplify/amplify-backend May 7, 2024
@ykethan ykethan added the Gen 2 label May 7, 2024
@renebrandel
Copy link
Contributor

@ideen1 - can you confirm your package.json file? I can't seem to reproduce your issue

@renebrandel
Copy link
Contributor

I don't see the "type.id" being suggested:
image

@chrisbonifacio chrisbonifacio added question Further information is requested pending-response and removed pending-triage labels May 7, 2024
@ideen1
Copy link
Author

ideen1 commented May 8, 2024

Hey @renebrandel I have also reproduced this on a brand new app setup with: npm create amplify@latest

My package JSON contains the following relevant modules:

  "name": "bin",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "@aws-amplify/backend": "^1.0.0",
    "@aws-amplify/backend-cli": "^1.0.1",
    "aws-cdk": "^2.140.0",
    "aws-cdk-lib": "^2.140.0",
    "constructs": "^10.3.0",
    "esbuild": "^0.21.1",
    "tsx": "^4.9.3",
    "typescript": "^5.4.5"
  },
  "dependencies": {
    "aws-amplify": "^6.3.0"
  }
}

Here is an image with the type of the default project Schema, also showing the issue:
Screenshot 2024-05-07 at 11 30 53 PM

@ideen1
Copy link
Author

ideen1 commented May 8, 2024

@renebrandel Okay I found something significant: Even the amplify-next-pages-template has this issue. See: Line #8 on https://github.com/aws-samples/amplify-next-pages-template/blob/main/pages/index.tsx

The Official Gen 2 docs do not reflect this change but, it seems as though the creator of the template also encountered the issue and adjusted for it. This template and the docs are inconsistent with each other. The issue does not seem to be consistent though because you are not seeing it.

A quick look at the PR mentioned in my original message shows that the data-schema module changed these lines potentially causing this issue:

type InternalClientSchema<Schema extends GenericModelSchema<any>, NonModelTypes extends NonModelTypesShape = ExtractNonModelTypes<Schema>, ResolvedSchema = ResolveSchema<Schema>, ResolvedFields extends Record<string, unknown> = Schema extends RDSModelSchema<any, any> ? ResolveStaticFieldProperties<Schema, NonModelTypes, object> : ResolveFieldProperties<Schema, NonModelTypes>, IdentifierMeta extends Record<string, any> = ModelIdentifier<SchemaTypes<Schema>>, SecondaryIndexes extends Record<string, any> = Schema extends RDSModelSchema<any, any> ? object : ModelSecondaryIndexes<SchemaTypes<Schema>>> = CustomOperationHandlerTypes<ResolveCustomOperations<Schema, ResolvedFields, NonModelTypes>['customOperations']> & {
    [K in keyof ResolvedFields]: {
        type: ResolvedFields[K];
    };
} & {
    [__modelMeta__]: IdentifierMeta & SecondaryIndexes & RelationalMetadata<ResolvedSchema, ResolvedFields, IdentifierMeta> & NonModelTypes & ResolveCustomOperations<Schema, ResolvedFields, NonModelTypes>;
}

^This excerpt is from @aws-amplify/data-schema/dist/esm/ClientSchema.d.ts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
data-schema Gen 2 investigating question Further information is requested
Projects
None yet
Development

No branches or pull requests

5 participants