Skip to content

Commit

Permalink
feat(api-graphql): add model index query support
Browse files Browse the repository at this point in the history
  • Loading branch information
iartemiev committed Feb 6, 2024
1 parent ee77a41 commit 160f01c
Show file tree
Hide file tree
Showing 9 changed files with 718 additions and 160 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4613,6 +4613,102 @@ exports[`generateClient graphql default auth default iam produces expected signi
]
`;

exports[`generateClient index queries PK and SK index query 1`] = `
[
[
{
"abortController": AbortController {},
"options": {
"body": {
"query": "query ($description: String!, $viewCount: ModelIntKeyConditionInput, $filter: ModelSecondaryIndexModelFilterInput, $limit: Int, $nextToken: String) {
listByDescriptionAndViewCount(
description: $description
viewCount: $viewCount
filter: $filter
limit: $limit
nextToken: $nextToken
) {
items {
id
title
description
viewCount
status
createdAt
updatedAt
}
nextToken
__typename
}
}
",
"variables": {
"description": "something something",
"viewCount": {
"gt": 4,
},
},
},
"headers": {
"Authorization": "amplify-config-auth-token",
"X-Api-Key": "FAKE-KEY",
"x-amz-user-agent": "aws-amplify/latest api/latest framework/latest",
},
"signingServiceInfo": undefined,
"withCredentials": undefined,
},
"url": "https://localhost/graphql",
},
],
]
`;

exports[`generateClient index queries PK-only index query 1`] = `
[
[
{
"abortController": AbortController {},
"options": {
"body": {
"query": "query ($title: String!, $filter: ModelSecondaryIndexModelFilterInput, $limit: Int, $nextToken: String) {
listByTitle(
title: $title
filter: $filter
limit: $limit
nextToken: $nextToken
) {
items {
id
title
description
viewCount
status
createdAt
updatedAt
}
nextToken
__typename
}
}
",
"variables": {
"title": "Hello World",
},
},
"headers": {
"Authorization": "amplify-config-auth-token",
"X-Api-Key": "FAKE-KEY",
"x-amz-user-agent": "aws-amplify/latest api/latest framework/latest",
},
"signingServiceInfo": undefined,
"withCredentials": undefined,
},
"url": "https://localhost/graphql",
},
],
]
`;

exports[`generateClient observeQuery can paginate through initial results 1`] = `
[
[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -959,6 +959,108 @@ const amplifyConfig = {
sortKeyFieldNames: [],
},
},
SecondaryIndexModel: {
name: 'SecondaryIndexModel',
fields: {
id: {
name: 'id',
isArray: false,
type: 'ID',
isRequired: true,
attributes: [],
},
title: {
name: 'title',
isArray: false,
type: 'String',
isRequired: false,
attributes: [],
},
description: {
name: 'description',
isArray: false,
type: 'String',
isRequired: false,
attributes: [],
},
viewCount: {
name: 'viewCount',
isArray: false,
type: 'Int',
isRequired: false,
attributes: [],
},
status: {
name: 'status',
isArray: false,
type: {
enum: 'Status',
},
isRequired: false,
attributes: [],
},
createdAt: {
name: 'createdAt',
isArray: false,
type: 'AWSDateTime',
isRequired: true,
attributes: [],
},
updatedAt: {
name: 'updatedAt',
isArray: false,
type: 'AWSDateTime',
isRequired: true,
attributes: [],
},
},
syncable: true,
pluralName: 'SecondaryIndexModels',
attributes: [
{
type: 'model',
properties: {},
},
{
type: 'key',
properties: {
fields: ['id'],
},
},
{
type: 'key',
properties: {
name: 'secondaryIndexModelsByTitle',
queryField: 'listByTitle',
fields: ['title'],
},
},
{
type: 'key',
properties: {
name: 'secondaryIndexModelsByDescriptionAndViewCount',
queryField: 'listByDescriptionAndViewCount',
fields: ['description', 'viewCount'],
},
},
{
type: 'auth',
properties: {
rules: [
{
allow: 'public',
operations: ['create', 'update', 'delete', 'read'],
},
],
},
},
],
primaryKeyInfo: {
isCustomPrimaryKey: false,
primaryKeyFieldName: 'id',
sortKeyFieldNames: [],
},
},
},
enums: {
Status: {
Expand Down
11 changes: 11 additions & 0 deletions packages/api-graphql/__tests__/fixtures/modeled/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,17 @@ const schema = a.schema({
CommunityPollVote: a
.model({ id: a.id().required() })
.authorization([a.allow.public('apiKey'), a.allow.owner()]),
SecondaryIndexModel: a
.model({
title: a.string(),
description: a.string(),
viewCount: a.integer(),
status: a.enum(['draft', 'pending', 'published']),
})
.secondaryIndexes([
a.index('title'),
a.index('description').sortKeys(['viewCount']),
]),
});

export type Schema = ClientSchema<typeof schema>;
Loading

0 comments on commit 160f01c

Please sign in to comment.