Skip to content

Commit

Permalink
Implemented getPosts query
Browse files Browse the repository at this point in the history
  • Loading branch information
willa75 committed May 18, 2022
1 parent 40bd85a commit dd187d3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
8 changes: 8 additions & 0 deletions lib/cdk-typescript-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@ export class CdkTypescriptStack extends Stack {

const postsDS = api.addDynamoDbDataSource('postsTable', postsTable);

// get list of posts
postsDS.createResolver({
typeName: 'Query',
fieldName: 'getPosts',
requestMappingTemplate: appsync.MappingTemplate.dynamoDbScanTable(),
responseMappingTemplate: appsync.MappingTemplate.dynamoDbResultList()
});

// create post
postsDS.createResolver({
typeName: 'Mutation',
Expand Down
7 changes: 1 addition & 6 deletions schema.api.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ schema {
}

type Query {
getPosts: PostsPage!
getPosts: [Post!]!
}

type Mutation {
Expand All @@ -16,9 +16,4 @@ type Post {
title: String!
text: String!
createdAt: AWSDateTime!
}

type PostsPage {
posts: [Post!]!
nextToken: String
}

0 comments on commit dd187d3

Please sign in to comment.