-
Notifications
You must be signed in to change notification settings - Fork 63
Nested Custom Types generate invalid code #952
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
Comments
Hi @csmith-rtr , Thanks for reporting this, I will transfer this issue to amplify-data team for further assistance. |
I'm trying to reproduce the described experience. When I setup the schema described above: const schema = a.schema({
Foo: a.customType({ bar: a.ref('Bar'), qux: a.integer() }),
Bar: a.customType({ baz: a.integer() }),
MyModel: a
.model({ id: a.id(), foo: a.ref('Foo') })
.authorization(a => [a.authenticated()]),
}).authorization((allow) => [allow.publicApiKey()]); and then generate the client code I get API.ts generated file includes types for both Foo and Bar. Open to see full file./* tslint:disable */
/* eslint-disable */
// This file was automatically generated and should not be edited.
export type MyModel = {
__typename: "MyModel",
createdAt: string,
foo?: Foo | null,
id: string,
updatedAt: string,
};
export type Foo = {
__typename: "Foo",
bar?: Bar | null,
qux?: number | null,
};
export type Bar = {
__typename: "Bar",
baz?: number | null,
};
export type ModelMyModelFilterInput = {
and?: Array< ModelMyModelFilterInput | null > | null,
createdAt?: ModelStringInput | null,
id?: ModelIDInput | null,
not?: ModelMyModelFilterInput | null,
or?: Array< ModelMyModelFilterInput | null > | null,
updatedAt?: ModelStringInput | null,
};
export type ModelStringInput = {
attributeExists?: boolean | null,
attributeType?: ModelAttributeTypes | null,
beginsWith?: string | null,
between?: Array< string | null > | null,
contains?: string | null,
eq?: string | null,
ge?: string | null,
gt?: string | null,
le?: string | null,
lt?: string | null,
ne?: string | null,
notContains?: string | null,
size?: ModelSizeInput | null,
};
export enum ModelAttributeTypes {
_null = "_null",
binary = "binary",
binarySet = "binarySet",
bool = "bool",
list = "list",
map = "map",
number = "number",
numberSet = "numberSet",
string = "string",
stringSet = "stringSet",
}
export type ModelSizeInput = {
between?: Array< number | null > | null,
eq?: number | null,
ge?: number | null,
gt?: number | null,
le?: number | null,
lt?: number | null,
ne?: number | null,
};
export type ModelIDInput = {
attributeExists?: boolean | null,
attributeType?: ModelAttributeTypes | null,
beginsWith?: string | null,
between?: Array< string | null > | null,
contains?: string | null,
eq?: string | null,
ge?: string | null,
gt?: string | null,
le?: string | null,
lt?: string | null,
ne?: string | null,
notContains?: string | null,
size?: ModelSizeInput | null,
};
export enum ModelSortDirection {
ASC = "ASC",
DESC = "DESC",
}
export type ModelMyModelConnection = {
__typename: "ModelMyModelConnection",
items: Array<MyModel | null >,
nextToken?: string | null,
};
export type ModelMyModelConditionInput = {
and?: Array< ModelMyModelConditionInput | null > | null,
createdAt?: ModelStringInput | null,
not?: ModelMyModelConditionInput | null,
or?: Array< ModelMyModelConditionInput | null > | null,
updatedAt?: ModelStringInput | null,
};
export type CreateMyModelInput = {
foo?: FooInput | null,
id?: string | null,
};
export type FooInput = {
bar?: BarInput | null,
qux?: number | null,
};
export type BarInput = {
baz?: number | null,
};
export type DeleteMyModelInput = {
id: string,
};
export type UpdateMyModelInput = {
foo?: FooInput | null,
id: string,
};
export type ModelSubscriptionMyModelFilterInput = {
and?: Array< ModelSubscriptionMyModelFilterInput | null > | null,
createdAt?: ModelSubscriptionStringInput | null,
id?: ModelSubscriptionIDInput | null,
or?: Array< ModelSubscriptionMyModelFilterInput | null > | null,
updatedAt?: ModelSubscriptionStringInput | null,
};
export type ModelSubscriptionStringInput = {
beginsWith?: string | null,
between?: Array< string | null > | null,
contains?: string | null,
eq?: string | null,
ge?: string | null,
gt?: string | null,
in?: Array< string | null > | null,
le?: string | null,
lt?: string | null,
ne?: string | null,
notContains?: string | null,
notIn?: Array< string | null > | null,
};
export type ModelSubscriptionIDInput = {
beginsWith?: string | null,
between?: Array< string | null > | null,
contains?: string | null,
eq?: string | null,
ge?: string | null,
gt?: string | null,
in?: Array< string | null > | null,
le?: string | null,
lt?: string | null,
ne?: string | null,
notContains?: string | null,
notIn?: Array< string | null > | null,
};
export type GetMyModelQueryVariables = {
id: string,
};
export type GetMyModelQuery = {
getMyModel?: {
__typename: "MyModel",
createdAt: string,
foo?: {
__typename: "Foo",
qux?: number | null,
} | null,
id: string,
updatedAt: string,
} | null,
};
export type ListMyModelsQueryVariables = {
filter?: ModelMyModelFilterInput | null,
id?: string | null,
limit?: number | null,
nextToken?: string | null,
sortDirection?: ModelSortDirection | null,
};
export type ListMyModelsQuery = {
listMyModels?: {
__typename: "ModelMyModelConnection",
items: Array< {
__typename: "MyModel",
createdAt: string,
id: string,
updatedAt: string,
} | null >,
nextToken?: string | null,
} | null,
};
export type CreateMyModelMutationVariables = {
condition?: ModelMyModelConditionInput | null,
input: CreateMyModelInput,
};
export type CreateMyModelMutation = {
createMyModel?: {
__typename: "MyModel",
createdAt: string,
foo?: {
__typename: "Foo",
qux?: number | null,
} | null,
id: string,
updatedAt: string,
} | null,
};
export type DeleteMyModelMutationVariables = {
condition?: ModelMyModelConditionInput | null,
input: DeleteMyModelInput,
};
export type DeleteMyModelMutation = {
deleteMyModel?: {
__typename: "MyModel",
createdAt: string,
foo?: {
__typename: "Foo",
qux?: number | null,
} | null,
id: string,
updatedAt: string,
} | null,
};
export type UpdateMyModelMutationVariables = {
condition?: ModelMyModelConditionInput | null,
input: UpdateMyModelInput,
};
export type UpdateMyModelMutation = {
updateMyModel?: {
__typename: "MyModel",
createdAt: string,
foo?: {
__typename: "Foo",
qux?: number | null,
} | null,
id: string,
updatedAt: string,
} | null,
};
export type OnCreateMyModelSubscriptionVariables = {
filter?: ModelSubscriptionMyModelFilterInput | null,
};
export type OnCreateMyModelSubscription = {
onCreateMyModel?: {
__typename: "MyModel",
createdAt: string,
foo?: {
__typename: "Foo",
qux?: number | null,
} | null,
id: string,
updatedAt: string,
} | null,
};
export type OnDeleteMyModelSubscriptionVariables = {
filter?: ModelSubscriptionMyModelFilterInput | null,
};
export type OnDeleteMyModelSubscription = {
onDeleteMyModel?: {
__typename: "MyModel",
createdAt: string,
foo?: {
__typename: "Foo",
qux?: number | null,
} | null,
id: string,
updatedAt: string,
} | null,
};
export type OnUpdateMyModelSubscriptionVariables = {
filter?: ModelSubscriptionMyModelFilterInput | null,
};
export type OnUpdateMyModelSubscription = {
onUpdateMyModel?: {
__typename: "MyModel",
createdAt: string,
foo?: {
__typename: "Foo",
qux?: number | null,
} | null,
id: string,
updatedAt: string,
} | null,
}; Did you build the related backend for your latest schema before generating the graphql files? Thanks, |
It looks like you are still only seeing the types in a subset of the generated code - for example
the above |
Very interesting. I'm pretty sure these files are generated by the codegen. I'm transferring this to that repository for further review. |
Not sure its related but I originally found this because the subscriptions for nested custom types weren't working - after calling the update mutation the values were always null though dynamo would update correctly. For now I've reverted to using |
Before opening, please confirm:
JavaScript Framework
React
Amplify APIs
GraphQL API
Amplify Version
v6
Amplify Categories
api
Backend
Amplify Gen 2
Environment information
Describe the bug
I have nested custom types I am trying to use in a model. When I then generate code with
ampx generate graphql-client-code
the types are missing the nested custom types in some instances.generates
you can see
CreateMyModelInput
has the full set of types butCreateMyModelMutation
andcreateMyModel
do not. This occurs whetherfoo.bar
is assigneda.ref('Bar')
or directly integrates another custom typeconst Foo = a.customType({ bar: a.customType({ baz: a.integer() }), qux: a.integer() });
Expected behavior
The nested types are included in the generated code.
Reproduction steps
npx ampx generate graphql-client-code
Code Snippet
// Put your code below this line.
Log output
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
The text was updated successfully, but these errors were encountered: