Skip to content

Commit

Permalink
update secondaryIndexes to new DX
Browse files Browse the repository at this point in the history
  • Loading branch information
iartemiev committed Mar 21, 2024
1 parent 5160bcc commit 9a2e9d5
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 34 deletions.
6 changes: 3 additions & 3 deletions packages/api-graphql/__tests__/fixtures/modeled/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ const schema = a.schema({
viewCount: a.integer(),
status: a.enum(['draft', 'pending', 'published']),
})
.secondaryIndexes([
a.index('title'),
a.index('description').sortKeys(['viewCount']),
.secondaryIndexes(index => [
index('title'),
index('description').sortKeys(['viewCount']),
]),
Product: a
.model({
Expand Down
55 changes: 24 additions & 31 deletions packages/api-graphql/src/internals/APIClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import {
ListArgs,
QueryArgs,
V6Client,
V6ClientSSRRequest,
__authMode,
__authToken,
__headers,
Expand Down Expand Up @@ -138,9 +137,7 @@ export function initializeModel(
options?: LazyLoadOptions,
) => {
if (record[targetNames[0]]) {
return (
client as V6ClientSSRRequest<Record<string, any>>
).models[relatedModelName].get(
return (client as any).models[relatedModelName].get(
contextSpec,
{
[relatedModelPKFieldName]: record[targetNames[0]],
Expand All @@ -160,9 +157,7 @@ export function initializeModel(
options?: LazyLoadOptions,
) => {
if (record[targetNames[0]]) {
return (client as V6Client<Record<string, any>>).models[
relatedModelName
].get(
return (client as any).models[relatedModelName].get(
{
[relatedModelPKFieldName]: record[targetNames[0]],
...sortKeyValues,
Expand Down Expand Up @@ -213,15 +208,16 @@ export function initializeModel(
options?: LazyLoadOptions,
) => {
if (record[parentPk]) {
return (
client as V6ClientSSRRequest<Record<string, any>>
).models[relatedModelName].list(contextSpec, {
filter: { and: hasManyFilter },
limit: options?.limit,
nextToken: options?.nextToken,
authMode: options?.authMode || authMode,
authToken: options?.authToken || authToken,
});
return (client as any).models[relatedModelName].list(
contextSpec,
{
filter: { and: hasManyFilter },
limit: options?.limit,
nextToken: options?.nextToken,
authMode: options?.authMode || authMode,
authToken: options?.authToken || authToken,
},
);
}

return [];
Expand All @@ -231,9 +227,7 @@ export function initializeModel(
options?: LazyLoadOptions,
) => {
if (record[parentPk]) {
return (client as V6Client<Record<string, any>>).models[
relatedModelName
].list({
return (client as any).models[relatedModelName].list({
filter: { and: hasManyFilter },
limit: options?.limit,
nextToken: options?.nextToken,
Expand Down Expand Up @@ -265,15 +259,16 @@ export function initializeModel(
options?: LazyLoadOptions,
) => {
if (record[parentPk]) {
return (
client as V6ClientSSRRequest<Record<string, any>>
).models[relatedModelName].list(contextSpec, {
filter: { and: hasManyFilter },
limit: options?.limit,
nextToken: options?.nextToken,
authMode: options?.authMode || authMode,
authToken: options?.authToken || authToken,
});
return (client as any).models[relatedModelName].list(
contextSpec,
{
filter: { and: hasManyFilter },
limit: options?.limit,
nextToken: options?.nextToken,
authMode: options?.authMode || authMode,
authToken: options?.authToken || authToken,
},
);
}

return [];
Expand All @@ -283,9 +278,7 @@ export function initializeModel(
options?: LazyLoadOptions,
) => {
if (record[parentPk]) {
return (client as V6Client<Record<string, any>>).models[
relatedModelName
].list({
return (client as any).models[relatedModelName].list({
filter: { and: hasManyFilter },
limit: options?.limit,
nextToken: options?.nextToken,
Expand Down

0 comments on commit 9a2e9d5

Please sign in to comment.