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

SQL - Type instantiation is excessively deep and possibly infinite.ts(2589) #2551

Open
kekami opened this issue May 11, 2024 · 2 comments
Open
Labels

Comments

@kekami
Copy link

kekami commented May 11, 2024

Environment information

System:
  OS: macOS 14.4.1
  CPU: (10) arm64 Apple M1 Max
  Memory: 109.48 MB / 32.00 GB
  Shell: /bin/zsh
Binaries:
  Node: 20.12.2 - ~/.nvm/versions/node/v20.12.2/bin/node
  Yarn: 1.22.22 - ~/.nvm/versions/node/v20.12.2/bin/yarn
  npm: 10.5.0 - ~/.nvm/versions/node/v20.12.2/bin/npm
  pnpm: 9.1.0 - ~/.nvm/versions/node/v20.12.2/bin/pnpm
NPM Packages:
  @aws-amplify/backend: 1.0.1
  @aws-amplify/backend-cli: 1.0.2
  aws-amplify: 6.3.0
  aws-cdk: 2.137.0
  aws-cdk-lib: 2.137.0
  typescript: 5.4.5
AWS environment variables:
  AWS_SDK_LOAD_CONFIG = 1
  AWS_STS_REGIONAL_ENDPOINTS = regional
  AWS_NODEJS_CONNECTION_REUSE_ENABLED = 1
No CDK environment variables

Description

Keep on hitting Type instantiation is excessively deep and possibly infinite.ts(2589) while working with the sql schema.

Repro:

// schema.sql.ts

/* eslint-disable */
/* THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. */
import { a } from "@aws-amplify/data-schema";
import { configure } from "@aws-amplify/data-schema/internals";
import { secret } from "@aws-amplify/backend";

export const schema = configure({
  database: {
    identifier: "foobar",
    engine: "postgresql",
    connectionUri: secret("SQL_CONNECTION_STRING"),
  },
}).schema({
  customers: a
    .model({
      id: a.id().required(),
      first_name: a.string(),
      last_name: a.string(),
      date_of_birth: a.string(),
      email: a.string(),
      phone: a.string(),
      owner: a.string(),
      stripe_customer_id: a.string(),
    })
    .identifier(["id"]),
  employees: a
    .model({
      id: a.id().required(),
      first_name: a.string(),
      last_name: a.string(),
      date_of_birth: a.string(),
      phone: a.string(),
      owner: a.string().required(),
      email: a.string(),
    })
    .identifier(["id"]),
  retainers: a
    .model({
      id: a.id().required(),
      customer_id: a.string().required(),
      employee_id: a.string().required(),
      owners: a.string().required().array(),
    })
    .identifier(["id"]),
  shifts: a
    .model({
      id: a.id().required(),
      start_time: a.datetime().required(),
      end_time: a.datetime().required(),
      employee_id: a.string().required(),
      retainer_id: a.string().required(),
      owners: a.string().required().array(),
    })
    .identifier(["id"]),
  spatial_ref_sys: a
    .model({
      srid: a.integer().required(),
      auth_name: a.string(),
      auth_srid: a.integer(),
      srtext: a.string(),
      proj4text: a.string(),
    })
    .identifier(["srid"]),
});

// resource.ts

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

import { schema as generatedSqlSchema } from "./schema.sql.js";

const sqlSchema = generatedSqlSchema
  .renameModels(() => [
    ["employees", "Employee"],
    ["customers", "Customer"],
    ["shifts", "Shift"],
    ["retainers", "Retainer"],
  ])
  .setRelationships((models) => [
    models.Employee.relationships({
      retainers: a.hasMany("Retainer", "employee_id"),
      shifts: a.hasMany("Shift", "employee_id"),
    }),
    models.Customer.relationships({
      retainers: a.hasMany("Retainer", "customer_id"),
    }),
    models.Retainer.relationships({
      shifts: a.hasMany("Shift", "retainer_id"),
      employee: a.belongsTo("Employee", "employee_id"),
      customer: a.belongsTo("Customer", "customer_id"),
    }),
    models.Shift.relationships({
      retainer: a.belongsTo("Retainer", "retainer_id"),
      employee: a.belongsTo("Employee", "employee_id"),
    }),
  ])
  .setAuthorization((models) => [
    models.Employee.authorization((allow) => [allow.ownerDefinedIn("owner")]),
    models.Customer.authorization((allow) => [allow.ownerDefinedIn("owner")]),
    models.Retainer.authorization((allow) => [allow.ownersDefinedIn("owners")]),
    models.Shift.authorization((allow) => [allow.ownersDefinedIn("owners")]),
  ]);

export type Schema = ClientSchema<typeof sqlSchema>;

export const data = defineData({
  schema: sqlSchema,
});

Screenshot 2024-05-11 at 19 37 07

@dpilch dpilch transferred this issue from aws-amplify/amplify-backend May 13, 2024
@AnilMaktala
Copy link

Hey @kekami, Thanks for raising this. We made some improvements in our types internally and it will address this issue. We will let you know once it is released.

@AnilMaktala AnilMaktala added bug Something isn't working pending-release and removed pending-triage labels May 14, 2024
@kekami
Copy link
Author

kekami commented May 26, 2024

Hey @AnilMaktala how is it going with the fix?

If you want me to validate the fix against my schema, which has grown significantly since this issue was posted, just let me know. I'd be happy to try it.

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

No branches or pull requests

3 participants