Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,14 @@ const schema = a.schema({
.identifier(["intAsId", "fieldA", "fieldB"])
.authorization((allow) => [allow.owner()]),

CpkTemporalPrimaryKey: a
.model({
hwid: a.string().required(),
sessionStart: a.datetime().required(),
})
.identifier(["hwid", "sessionStart"])
.authorization((allow) => [allow.authenticated()]),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is this used in the modified tests? If we want to extend e2e, we should also modify the test itself (example/integration_test/graphql/user_pools_test.dart).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added an e2e test that exercises it, along with the generated example model it needs.

lowerCase: a
.model({
id: a.id().required(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,9 @@ class GraphQLRequestFactory {
// codegen. Instead, just write the value to the document.
final bLowerOutput = StringBuffer(_openParen);
for (final field in modelIndex.fields) {
var value = modelIdentifier!.serializeAsMap()[field];
var value = _getSerializedValue(
modelIdentifier!.serializeAsMap()[field],
);
if (value is String) {
value = '"$value"';
}
Expand Down Expand Up @@ -256,6 +258,14 @@ class GraphQLRequestFactory {
};
}

Map<String, dynamic> buildVariablesForGetRequest({
required ModelIdentifier modelIdentifier,
}) {
return modelIdentifier.serializeAsMap().map(
(key, dynamic value) => MapEntry(key, _getSerializedValue(value)),
);
}

Map<String, dynamic> buildVariablesForMutationRequest({
required Map<String, dynamic> input,
Map<String, dynamic>? condition,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ class ModelQueriesFactory {
APIAuthorizationType? authorizationMode,
Map<String, String>? headers,
}) {
final variables = modelIdentifier.serializeAsMap();
final variables = GraphQLRequestFactory.instance
.buildVariablesForGetRequest(modelIdentifier: modelIdentifier);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this need to be added to delete operations too.

@cadivus cadivus Aug 12, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And do we need to adapt test models (e.g. test/test_models/schema.graphql)? Do we need to add something like

type CpkTemporalPrimaryKey @model {
  hwid: String! @primaryKey(sortKeyFields: ["sessionStart"])
  sessionStart: AWSDateTime!
}

@VarshithaPamisetty VarshithaPamisetty Aug 12, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added the delete operation and the CpkTemporalPrimaryKey type to the test schema (as suggested).

return GraphQLRequestFactory.instance.buildRequest<T>(
modelType: modelType,
modelIdentifier: modelIdentifier,
Expand Down
24 changes: 24 additions & 0 deletions packages/api/amplify_api_dart/test/graphql_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,30 @@ void main() {
expect(res.errors, isEmpty);
});

test('Query for a model with a TemporalDateTime in its custom identifier '
'serializes without throwing (regression test for #6298)', () {
const hwid = '94B216FCC67F';
final sessionStart = TemporalDateTime.fromString(
'2025-03-28T23:07:34.000Z',
);
final serializedDate = sessionStart.toString();
final expectedDoc =
'query getCpkTemporalPrimaryKey { getCpkTemporalPrimaryKey(hwid: "$hwid", sessionStart: "$serializedDate") { hwid sessionStart createdAt updatedAt } }';

final req = ModelQueries.get<CpkTemporalPrimaryKey>(
CpkTemporalPrimaryKey.classType,
CpkTemporalPrimaryKeyModelIdentifier(
hwid: hwid,
sessionStart: sessionStart,
),
);

// request asserts
expect(req.document, expectedDoc);
expect(() => json.encode(req.variables), returnsNormally);
expect(req.variables['sessionStart'], equals(serializedDate));
});

test(
'Mutation.create returns proper response.data for Models with custom types',
() async {
Expand Down
Loading
Loading