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

importing Schema model into lambda function is not recognised by typescript #428

Open
cookiejest opened this issue Dec 31, 2024 · 5 comments

Comments

@cookiejest
Copy link

Environment information

Using gen2. Want to import the schema into a lambda function. It is not recognised.

Describe the bug

Using gen2. Want to import the schema into a lambda function. It is not recognised.

Reproduction steps

Define a model:

  Connection: a
    .model({
      owner: a.string(),
      institutionId: a.string(),
      max_access_valid_for_days: a.integer(),
      transaction_total_days: a.integer(),
      refreshExpireTimestamp: a.integer(),
      connectionIdentifier: a.string(),
      status: a.string(),
      errorCounter: a.integer(),
      creationTimestamp: a.timestamp(),
      connectionTTL: a.integer()
    })
    .authorization((allow) => [allow.owner()]),

Try and use the schema definition in a lambda function:

import type { Schema } from '../../data/resource';

const connection = event.arguments.connection as Schema["Connection"];

Field types are not recognised:
Screenshot 2024-12-31 at 16 48 22

@ykethan
Copy link
Member

ykethan commented Dec 31, 2024

Hey @cookiejest, thank you for reaching out. Refer to the following documentation providing an example on using the data client in a lambda function.
https://docs.amplify.aws/react/build-a-backend/functions/examples/create-user-profile-record/

@cookiejest
Copy link
Author

cookiejest commented Dec 31, 2024

while this approach allows for the function to execute against the schema, it still doesn't allow for the Schema definition to be used like Schema["Connection"] for defining types. At least for me.

@ykethan
Copy link
Member

ykethan commented Jan 2, 2025

thank you for the information. I will transfer the issue to our API repository for further assistance.

@ykethan ykethan transferred this issue from aws-amplify/amplify-backend Jan 2, 2025
@ykethan ykethan added the Gen 2 label Jan 2, 2025
@chrisbonifacio chrisbonifacio self-assigned this Jan 2, 2025
@chrisbonifacio
Copy link
Member

chrisbonifacio commented Jan 2, 2025

Hi @cookiejest have you tried using Schema["Connection"]["type"]? There are also mutation types like createType, updateType, etc that you can use if your Lambda is intended to perform a mutation.

Can you share a little more information on the handler code and the version of the @aws-amplify/backend package you are currently using which reproduces this issue? These might help expedite reproduction of the issue.

This part of the documentation might be helpful but I will also look into potential options that might be better suited for using the types in a Lambda.
https://docs.amplify.aws/react/build-a-backend/data/query-data/#typescript-type-helpers-for-amplify-data

@stocaaro stocaaro transferred this issue from aws-amplify/amplify-category-api Jan 8, 2025
@chrisbonifacio
Copy link
Member

Hi @cookiejest have you been able to try my suggestion above? Just want to be sure you're unblocked on this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants