amplify-codegen
amplify-codegen copied to clipboard
Generating GraphQL code, customType is not included in Query.List
Environment information
System:
OS: macOS 14.5
CPU: (8) x64 Apple M2
Memory: 9.96 MB / 16.00 GB
Shell: Unknown
Binaries:
Node: 18.18.0 - ~/.nvm/versions/node/v18.18.0/bin/node
Yarn: undefined - undefined
npm: 10.8.2 - ~/.nvm/versions/node/v18.18.0/bin/npm
pnpm: 8.15.4 - ~/.nvm/versions/node/v18.18.0/bin/pnpm
NPM Packages:
@aws-amplify/auth-construct: 1.3.0
@aws-amplify/backend: 1.2.0
@aws-amplify/backend-auth: 1.1.3
@aws-amplify/backend-cli: 1.2.5
@aws-amplify/backend-data: 1.1.3
@aws-amplify/backend-deployer: 1.1.0
@aws-amplify/backend-function: 1.3.4
@aws-amplify/backend-output-schemas: 1.2.0
@aws-amplify/backend-output-storage: 1.1.1
@aws-amplify/backend-secret: 1.1.0
@aws-amplify/backend-storage: 1.1.2
@aws-amplify/cli-core: 1.1.2
@aws-amplify/client-config: 1.3.0
@aws-amplify/deployed-backend-client: 1.4.0
@aws-amplify/form-generator: 1.0.1
@aws-amplify/model-generator: 1.0.5
@aws-amplify/platform-core: 1.0.7
@aws-amplify/plugin-types: 1.2.1
@aws-amplify/sandbox: 1.2.0
@aws-amplify/schema-generator: 1.2.1
aws-amplify: 6.5.3
aws-cdk: 2.154.1
aws-cdk-lib: 2.154.1
typescript: 5.5.4
AWS environment variables:
AWS_STS_REGIONAL_ENDPOINTS = regional
AWS_NODEJS_CONNECTION_REUSE_ENABLED = 1
AWS_SDK_LOAD_CONFIG = 1
No CDK environment variables
Describe the bug
Overview
The Query.List generated by the generate graphql-client-code command doesn't seem to include customType.
Note that while the customType is not present in the generated GraphQL code, the schema registered in AppSync includes customType. Therefore, manually adding the customType attribute to the generated GraphQL code allows for successful retrieval of customType, but we want this to be generated automatically.
Please let me know if there are any settings that can solve this problem.
Reproduction steps
Step
1.Execute the sandbox and reflect this schema in data/resource.ts.
- Get/List queries for the Test model
- List query for secondaryIndexes
- List query for customListTest
will be generated.
File: amplify/data/resource.ts
const schema = a
.schema({
// Model
Test: a
.model({
some_id: a.string(),
attachment: a.customType({
key: a.string(),
}),
})
// secondary index
.secondaryIndexes((index) => [index("some_id")])
.authorization((allow) => allow.authenticated()),
// Custom Query
CustomListTestResponse: a.customType({
some_id: a.string(),
attachment: a.customType({
key: a.string(),
}),
}),
customListTest: a
.query()
.arguments({})
.returns(a.ref("CustomListTestResponse").array())
.authorization((allow) => allow.authenticated())
.handler(a.handler.function(customListTestHandler)),
})
.authorization((allow) => [allow.resource(customListTestHandler).to(["query"])]);
2.Using graphql-client-code, generate GraphQL code from the SandBox's StackName.
npx ampx generate graphql-client-code --stack amplify-xxx-xxxxxxx-sandbox-xxxxxxx --profile xxxxxxxx
3.When checking queries.ts, it becomes apparent that the attachment attribute is missing in two out of the three Queries that retrieve lists: Query.getTest: attachment exists Query.listTests: attachment does not exist Query.listTestBySome_id: attachment does not exist Query.customListTest: attachment exists
File: queries.ts
export const customListTest = /* GraphQL */ `query CustomListTest {
customListTest {
attachment {
key
__typename
}
some_id
__typename
}
}
` as GeneratedQuery<
APITypes.CustomListTestQueryVariables,
APITypes.CustomListTestQuery
>;
export const getTest = /* GraphQL */ `query GetTest($id: ID!) {
getTest(id: $id) {
attachment {
key
__typename
}
createdAt
id
some_id
updatedAt
__typename
}
}
` as GeneratedQuery<APITypes.GetTestQueryVariables, APITypes.GetTestQuery>;
export const listTestBySome_id = /* GraphQL */ `query ListTestBySome_id(
$filter: ModelTestFilterInput
$limit: Int
$nextToken: String
$some_id: String!
$sortDirection: ModelSortDirection
) {
listTestBySome_id(
filter: $filter
limit: $limit
nextToken: $nextToken
some_id: $some_id
sortDirection: $sortDirection
) {
items {
createdAt
id
some_id
updatedAt
__typename
}
nextToken
__typename
}
}
` as GeneratedQuery<
APITypes.ListTestBySome_idQueryVariables,
APITypes.ListTestBySome_idQuery
>;
export const listTests = /* GraphQL */ `query ListTests(
$filter: ModelTestFilterInput
$limit: Int
$nextToken: String
) {
listTests(filter: $filter, limit: $limit, nextToken: $nextToken) {
items {
createdAt
id
some_id
updatedAt
__typename
}
nextToken
__typename
}
}
` as GeneratedQuery<APITypes.ListTestsQueryVariables, APITypes.ListTestsQuery>;
Hey,👋 thanks for raising this! I'm going to transfer this over to our codegen repository for better assistance 🙂