Open Gsciarra opened 1 month ago
Hey @Gsciarra, thank you for reaching out. I was able to reproduce the issue, marking as bug.
I ran into this issue as well. I would like to add type annotation to the schema const, but I can't figure out which type definition to use, and I'm not sure a definition is exported anyway.
It seems like it could be:
import { type DerivedModelSchema } from "@aws-amplify/data-schema-types"
const schema: DerivedModelSchema = a.schema({...})
But then I run into an issue on this line:
export type Schema = ClientSchema<typeof schema>;
Type 'DerivedModelSchema' does not satisfy the constraint 'GenericModelSchema<any> | CombinedModelSchema<any>'.
Type 'DerivedModelSchema' is not assignable to type 'GenericModelSchema<any>'.
Property 'models' is missing in type 'DerivedModelSchema' but required in type 'BaseSchema<any, false>'.ts(2344)
ModelSchema.d.ts(39, 5): 'models' is declared here.
Running into the same issue, not following:
` import { type ClientSchema, a, defineData } from "@aws-amplify/backend"; import { postConfirmation } from "../auth/post-confirmation/resource";
const schema = a
.schema({
UserProfile: a
.model({
email: a.string(),
profileOwner: a.string(),
})
.authorization((allow) => [
allow.ownerDefinedIn("profileOwner"),
]),
})
.authorization((allow) => [allow.resource(postConfirmation)]);
export type Schema = ClientSchema
export const data = defineData({ schema, authorizationModes: { defaultAuthorizationMode: "apiKey", apiKeyAuthorizationMode: { expiresInDays: 30, }, }, } );`
--error later in amplify cli in) $ amplify codegen add --apiId hpnak7nalvekhc6lvlqhuj2eua --region us-east-1 --debug ? Choose the type of app that you're building javascript ? What javascript framework are you using react √ Getting API details ? Choose the code generation language target typescript ? Enter the file name pattern of graphql queries, mutations and subscriptions sr c\graphql*\.ts ? Do you want to generate/update all possible GraphQL operations - queries, muta tions and subscriptions Yes ? Enter maximum statement depth [increase from default if your schema is deeply nested] 2 ? Enter the file name for the generated code src/API.ts ? Do you want to generate code for your newly created GraphQL API Yes × Downloading schema failed errors=[InvalidSyntaxError{ message=Invalid Syntax ,locations=[SourceLocation{line=1, column=0}]}]
Environment information
Description
To reproduce:
You will get:
You can "fix" this with
export const auth: ReturnType<typeof defineAuth> = defineAuth({
, and then you will end up with