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

Type Error with Custom Identifier in Amplify Data Model Schema - .identifier is not assignable to referenced customType #14000

Closed
3 tasks done
MATTiVOLTARii opened this issue Nov 11, 2024 · 3 comments
Assignees
Labels
Gen 2 Issues related to Gen 2 Amplify projects GraphQL Related to GraphQL API issues

Comments

@MATTiVOLTARii
Copy link

Before opening, please confirm:

JavaScript Framework

Next.js

Amplify APIs

DataStore

Amplify Version

v6

Amplify Categories

No response

Backend

Amplify Gen 2

Environment information

# Put output below this line
  System:
    OS: Windows 11 10.0.22631
    CPU: (8) x64 Intel(R) Core(TM) i7-1065G7 CPU @ 1.30GHz
    Memory: 11.99 GB / 31.60 GB
  Binaries:
    Node: 20.16.0
    npm: 9.9.3
  npmPackages:
    @aws-amplify/adapter-nextjs: ^1.2.26 => 1.2.26
    @aws-amplify/adapter-nextjs/api:  undefined ()
    @aws-amplify/adapter-nextjs/data:  undefined ()
    @aws-amplify/backend: ^1.6.0 => 1.6.0
    @aws-amplify/backend-cli: ^1.2.2 => 1.2.2
    @aws-crypto/sha256-js: ^5.2.0 => 5.2.0 (1.2.2)
    @aws-sdk/client-cognito-identity-provider: ^3.654.0 => 3.654.0
    @aws-sdk/client-s3: ^3.654.0 => 3.654.0
    amazon-cognito-identity-js: ^6.1.2 => 6.3.12
    aws-amplify: ^6.5.0 => 6.5.0
    aws-cdk: ^2.165.0 => 2.165.0
    aws-cdk-lib: ^2.151.0 => 2.165.0
    aws-sdk: ^2.1691.0 => 2.1691.0
  npmGlobalPackages:
    @aws-amplify/cli: 12.13.0
    aws-cdk: 2.165.0

Describe the bug

I’m encountering an error when attempting to define a custom identifier for my model in Amplify’s data schema. Despite using the recommended syntax, the error persists. Below are the details of the setup and the error message.

Expected behavior

The custom identifier customId should be accepted as the primary identifier for the Shop model without type conflicts.

Reproduction steps

Shop: a.model({
customId: a.id().required(),
items: a.ref('Items'),
content: a.string(),
})
.identifier(['customId'])

Code Snippet

import { type ClientSchema, a, defineData } from '@aws-amplify/backend';

const schema = a.schema({
Items: a.customType({
name: a.string(),
price: a.string(),
}),

Shop: a.model({
customId: a.id().required(),
items: a.ref('Items'),
content: a.string(),
})
.identifier(['customId'])
.authorization((allow) => [allow.guest()]),
});

export type Schema = ClientSchema;

export const data = defineData({
schema,
authorizationModes: {
defaultAuthorizationMode: "userPool",
},
});

Log output

// Put your logs below this line
Type error: Type '"customId"' is not assignable to type '"items"'.

  13 |   items: a.ref('Items'),
  14 |   content: a.string(),
> 15 | }).identifier(['customId']) // Only for models
     |                ^
  16 | .authorization((allow) => [allow.guest()]),


aws-exports.js

No response

Manual configuration

No response

Additional configuration

No response

Mobile Device

No response

Mobile Operating System

No response

Mobile Browser

No response

Mobile Browser Version

No response

Additional information and screenshots

No response

@github-actions github-actions bot added pending-triage Issue is pending triage pending-maintainer-response Issue is pending a response from the Amplify team. labels Nov 11, 2024
@MATTiVOLTARii MATTiVOLTARii changed the title Type Error with Custom Identifier in Amplify Data Model Schema - .identifier is not assignable to type Type Error with Custom Identifier in Amplify Data Model Schema - .identifier is not assignable to customType Nov 11, 2024
@MATTiVOLTARii MATTiVOLTARii changed the title Type Error with Custom Identifier in Amplify Data Model Schema - .identifier is not assignable to customType Type Error with Custom Identifier in Amplify Data Model Schema - .identifier is not assignable to referenced customType Nov 11, 2024
@cwomack cwomack added DataStore Related to DataStore category GraphQL Related to GraphQL API issues and removed DataStore Related to DataStore category labels Nov 11, 2024
@MATTiVOLTARii
Copy link
Author

MATTiVOLTARii commented Nov 11, 2024

I don't know exactly why but with "as any" it seems to work:

  Items: a.customType({
    name: a.string(),
    price: a.string(),
    }),
    
    Shop: a.model({
    customId: a.id().required() as any,
    items: a.ref('Items'),
    content: a.string(),
    })
    .identifier(['customId'])
    .authorization((allow) => [allow.guest()]),

@chrisbonifacio
Copy link
Member

Hi @MATTiVOLTARii 👋 thanks for raising this issue.

can you please share the dependencies listed in your package.json file?

also, curious what version of @aws-amplify/data-schema you have installed. you can check this by running:

npm list @aws-amplify/data-schema

@github-actions github-actions bot removed the pending-maintainer-response Issue is pending a response from the Amplify team. label Nov 12, 2024
@chrisbonifacio chrisbonifacio added pending-community-response Issue is pending a response from the author or community. and removed pending-triage Issue is pending triage labels Nov 13, 2024
@chrisbonifacio chrisbonifacio self-assigned this Nov 13, 2024
@chrisbonifacio chrisbonifacio added the Gen 2 Issues related to Gen 2 Amplify projects label Nov 13, 2024
@chrisbonifacio
Copy link
Member

Hi 👋 Closing this as we have not heard back from you. If you are still experiencing this issue and in need of assistance, please feel free to comment and provide us with any information previously requested by our team members so we can re-open this issue and be better able to assist you.

Thank you!

@chrisbonifacio chrisbonifacio closed this as not planned Won't fix, can't repro, duplicate, stale Nov 18, 2024
@github-actions github-actions bot removed the pending-community-response Issue is pending a response from the author or community. label Nov 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Gen 2 Issues related to Gen 2 Amplify projects GraphQL Related to GraphQL API issues
Projects
None yet
Development

No branches or pull requests

3 participants