├── .eslintrc.json ├── .gitignore ├── .npmignore ├── .prettierignore ├── .prettierrc ├── README.md ├── bin └── cdk.ts ├── cdk.json ├── codegen.ts ├── lib ├── cdk-stack.ts └── helpers.ts ├── package-lock.json ├── package.json ├── schema.graphql ├── src ├── lib │ └── helpers.ts ├── resolvers │ ├── createPost.ts │ ├── deletePost.ts │ ├── getPost.ts │ ├── getPosts.ts │ └── updatePost.ts └── types │ └── appsync.ts └── tsconfig.json /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": [ 3 | "prettier", 4 | "plugin:prettier/recommended", 5 | "plugin:@typescript-eslint/recommended", 6 | "eslint:recommended" 7 | ], 8 | "parserOptions": { 9 | "ecmaVersion": 2018 10 | }, 11 | "env": { 12 | "node": true, 13 | "es6": true 14 | }, 15 | "overrides": [ 16 | { 17 | "files": ["src/**/*.ts"], 18 | "extends": ["plugin:@aws-appsync/base"] 19 | } 20 | ] 21 | } 22 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | *.js 3 | !jest.config.js 4 | *.d.ts 5 | node_modules 6 | 7 | # CDK asset staging directory 8 | .cdk.staging 9 | cdk.out 10 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | *.ts 2 | !*.d.ts 3 | 4 | # CDK asset staging directory 5 | .cdk.staging 6 | cdk.out 7 | -------------------------------------------------------------------------------- /.prettierignore: -------------------------------------------------------------------------------- 1 | build 2 | src/types/appsync.ts 3 | -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "tabWidth": 2, 3 | "useTabs": false, 4 | "singleQuote": true, 5 | "trailingComma": "all", 6 | "endOfLine": "auto" 7 | } 8 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | AppSync TypeScript Resolvers demo 2 | 3 | **Build and Deploy** 4 | 5 | ```bash 6 | npm run build 7 | npx cdk deploy --all 8 | ``` 9 | 10 | or 11 | 12 | ```bash 13 | npm run deploy 14 | ``` 15 | -------------------------------------------------------------------------------- /bin/cdk.ts: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | import 'source-map-support/register'; 3 | import * as cdk from 'aws-cdk-lib'; 4 | import { CdkStack } from '../lib/cdk-stack'; 5 | 6 | const app = new cdk.App(); 7 | new CdkStack(app, 'CdkStack', { 8 | /* If you don't specify 'env', this stack will be environment-agnostic. 9 | * Account/Region-dependent features and context lookups will not work, 10 | * but a single synthesized template can be deployed anywhere. */ 11 | 12 | /* Uncomment the next line to specialize this stack for the AWS Account 13 | * and Region that are implied by the current CLI configuration. */ 14 | // env: { account: process.env.CDK_DEFAULT_ACCOUNT, region: process.env.CDK_DEFAULT_REGION }, 15 | 16 | /* Uncomment the next line if you know exactly what Account and Region you 17 | * want to deploy the stack to. */ 18 | // env: { account: '123456789012', region: 'us-east-1' }, 19 | 20 | /* For more information, see https://docs.aws.amazon.com/cdk/latest/guide/environments.html */ 21 | }); -------------------------------------------------------------------------------- /cdk.json: -------------------------------------------------------------------------------- 1 | { 2 | "app": "npx ts-node --prefer-ts-exts bin/cdk.ts", 3 | "watch": { 4 | "include": [ 5 | "**" 6 | ], 7 | "exclude": [ 8 | "README.md", 9 | "cdk*.json", 10 | "**/*.d.ts", 11 | "**/*.js", 12 | "tsconfig.json", 13 | "package*.json", 14 | "yarn.lock", 15 | "node_modules", 16 | "test" 17 | ] 18 | }, 19 | "context": { 20 | "@aws-cdk/aws-lambda:recognizeLayerVersion": true, 21 | "@aws-cdk/core:checkSecretUsage": true, 22 | "@aws-cdk/core:target-partitions": [ 23 | "aws", 24 | "aws-cn" 25 | ], 26 | "@aws-cdk-containers/ecs-service-extensions:enableDefaultLogDriver": true, 27 | "@aws-cdk/aws-ec2:uniqueImdsv2TemplateName": true, 28 | "@aws-cdk/aws-ecs:arnFormatIncludesClusterName": true, 29 | "@aws-cdk/aws-iam:minimizePolicies": true, 30 | "@aws-cdk/core:validateSnapshotRemovalPolicy": true, 31 | "@aws-cdk/aws-codepipeline:crossAccountKeyAliasStackSafeResourceName": true, 32 | "@aws-cdk/aws-s3:createDefaultLoggingPolicy": true, 33 | "@aws-cdk/aws-sns-subscriptions:restrictSqsDescryption": true, 34 | "@aws-cdk/aws-apigateway:disableCloudWatchRole": true, 35 | "@aws-cdk/core:enablePartitionLiterals": true, 36 | "@aws-cdk/aws-events:eventsTargetQueueSameAccount": true, 37 | "@aws-cdk/aws-iam:standardizedServicePrincipals": true, 38 | "@aws-cdk/aws-ecs:disableExplicitDeploymentControllerForCircuitBreaker": true, 39 | "@aws-cdk/aws-iam:importedRoleStackSafeDefaultPolicyName": true, 40 | "@aws-cdk/aws-s3:serverAccessLogsUseBucketPolicy": true, 41 | "@aws-cdk/aws-route53-patters:useCertificate": true, 42 | "@aws-cdk/customresources:installLatestAwsSdkDefault": false, 43 | "@aws-cdk/aws-rds:databaseProxyUniqueResourceName": true, 44 | "@aws-cdk/aws-codedeploy:removeAlarmsFromDeploymentGroup": true, 45 | "@aws-cdk/aws-apigateway:authorizerChangeDeploymentLogicalId": true, 46 | "@aws-cdk/aws-ec2:launchTemplateDefaultUserData": true, 47 | "@aws-cdk/aws-secretsmanager:useAttachedSecretResourcePolicyForSecretTargetAttachments": true 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /codegen.ts: -------------------------------------------------------------------------------- 1 | import { CodegenConfig } from '@graphql-codegen/cli'; 2 | 3 | const config: CodegenConfig = { 4 | overwrite: true, 5 | schema: [ 6 | 'schema.graphql', 7 | ` 8 | scalar AWSDate 9 | scalar AWSTime 10 | scalar AWSDateTime 11 | scalar AWSTimestamp 12 | scalar AWSEmail 13 | scalar AWSJSON 14 | scalar AWSURL 15 | scalar AWSPhone 16 | scalar AWSIPAddress 17 | `, 18 | ], 19 | config: { 20 | scalars: { 21 | AWSJSON: 'string', 22 | AWSDate: 'string', 23 | AWSTime: 'string', 24 | AWSDateTime: 'string', 25 | AWSTimestamp: 'number', 26 | AWSEmail: 'string', 27 | AWSURL: 'string', 28 | AWSPhone: 'string', 29 | AWSIPAddress: 'string', 30 | }, 31 | }, 32 | generates: { 33 | 'src/types/appsync.ts': { 34 | plugins: ['typescript'], 35 | }, 36 | }, 37 | }; 38 | 39 | export default config; 40 | -------------------------------------------------------------------------------- /lib/cdk-stack.ts: -------------------------------------------------------------------------------- 1 | import * as cdk from 'aws-cdk-lib'; 2 | import { Construct } from 'constructs'; 3 | import * as appsync from 'aws-cdk-lib/aws-appsync'; 4 | import * as dynamodb from 'aws-cdk-lib/aws-dynamodb'; 5 | import { bundleAppSyncResolver } from './helpers'; 6 | import { CfnApiKey } from 'aws-cdk-lib/aws-appsync'; 7 | 8 | export class CdkStack extends cdk.Stack { 9 | constructor(scope: Construct, id: string, props?: cdk.StackProps) { 10 | super(scope, id, props); 11 | 12 | const api = new appsync.GraphqlApi(this, 'Api', { 13 | name: 'typescript-resolvers-demo', 14 | schema: appsync.SchemaFile.fromAsset('schema.graphql'), 15 | authorizationConfig: { 16 | defaultAuthorization: { 17 | authorizationType: appsync.AuthorizationType.API_KEY, 18 | }, 19 | }, 20 | xrayEnabled: true, 21 | logConfig: { 22 | fieldLogLevel: appsync.FieldLogLevel.ALL, 23 | }, 24 | }); 25 | 26 | const postsTable = new dynamodb.Table(this, 'PostTable', { 27 | partitionKey: { 28 | name: 'id', 29 | type: dynamodb.AttributeType.STRING, 30 | }, 31 | }); 32 | postsTable.addGlobalSecondaryIndex({ 33 | indexName: 'byAuthor', 34 | partitionKey: { 35 | name: 'authorName', 36 | type: dynamodb.AttributeType.STRING, 37 | }, 38 | }); 39 | 40 | new CfnApiKey(this, 'public-api-key', { 41 | apiId: api.apiId, 42 | expires: Math.floor((Date.now() + 1000 * 60 * 60 * 24 * 365) / 1000), 43 | }); 44 | 45 | const postsDS = api.addDynamoDbDataSource('postDataSource', postsTable); 46 | 47 | const defaultPipelineCode = appsync.Code.fromInline(` 48 | // The before step 49 | export function request(...args) { 50 | return {} 51 | } 52 | 53 | // The after step 54 | export function response(ctx) { 55 | return ctx.prev.result 56 | } 57 | `); 58 | 59 | // get posts 60 | const getPosts = new appsync.AppsyncFunction(this, 'GetPosts', { 61 | name: 'getPosts', 62 | api, 63 | dataSource: postsDS, 64 | code: bundleAppSyncResolver('src/resolvers/getPosts.ts'), 65 | runtime: appsync.FunctionRuntime.JS_1_0_0, 66 | }); 67 | 68 | new appsync.Resolver(this, 'GetPostsResolver', { 69 | api, 70 | typeName: 'Query', 71 | fieldName: 'getPosts', 72 | code: defaultPipelineCode, 73 | runtime: appsync.FunctionRuntime.JS_1_0_0, 74 | pipelineConfig: [getPosts], 75 | }); 76 | 77 | // get post 78 | const getPost = new appsync.AppsyncFunction(this, 'GetPost', { 79 | name: 'getPost', 80 | api, 81 | dataSource: postsDS, 82 | code: bundleAppSyncResolver('src/resolvers/getPost.ts'), 83 | runtime: appsync.FunctionRuntime.JS_1_0_0, 84 | }); 85 | 86 | new appsync.Resolver(this, 'GetPostResolver', { 87 | api, 88 | typeName: 'Query', 89 | fieldName: 'getPost', 90 | code: defaultPipelineCode, 91 | runtime: appsync.FunctionRuntime.JS_1_0_0, 92 | pipelineConfig: [getPost], 93 | }); 94 | 95 | // create post 96 | const createPost = new appsync.AppsyncFunction(this, 'CreatePost', { 97 | name: 'createPost', 98 | api, 99 | dataSource: postsDS, 100 | code: bundleAppSyncResolver('src/resolvers/createPost.ts'), 101 | runtime: appsync.FunctionRuntime.JS_1_0_0, 102 | }); 103 | 104 | new appsync.Resolver(this, 'CreatePostResolver', { 105 | api, 106 | typeName: 'Mutation', 107 | fieldName: 'createPost', 108 | code: defaultPipelineCode, 109 | runtime: appsync.FunctionRuntime.JS_1_0_0, 110 | pipelineConfig: [createPost], 111 | }); 112 | 113 | // update post 114 | const updatePost = new appsync.AppsyncFunction(this, 'UpdatePost', { 115 | name: 'updatePost', 116 | api, 117 | dataSource: postsDS, 118 | code: bundleAppSyncResolver('src/resolvers/updatePost.ts'), 119 | runtime: appsync.FunctionRuntime.JS_1_0_0, 120 | }); 121 | 122 | new appsync.Resolver(this, 'PipelineResolver', { 123 | api, 124 | typeName: 'Mutation', 125 | fieldName: 'updatePost', 126 | code: defaultPipelineCode, 127 | runtime: appsync.FunctionRuntime.JS_1_0_0, 128 | pipelineConfig: [updatePost], 129 | }); 130 | } 131 | } 132 | -------------------------------------------------------------------------------- /lib/helpers.ts: -------------------------------------------------------------------------------- 1 | import { Code } from 'aws-cdk-lib/aws-appsync'; 2 | import * as esbuild from 'esbuild'; 3 | 4 | export const bundleAppSyncResolver = (entryPoint: string): Code => { 5 | const result = esbuild.buildSync({ 6 | entryPoints: [entryPoint], 7 | external: ['@aws-appsync/utils'], 8 | bundle: true, 9 | write: false, 10 | platform: 'node', 11 | target: 'esnext', 12 | format: 'esm', 13 | sourcemap: 'inline', 14 | sourcesContent: false, 15 | }); 16 | 17 | return Code.fromInline(result.outputFiles[0].text); 18 | }; 19 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "appsync-js-reslvers-typescript", 3 | "version": "1.0.0", 4 | "bin": { 5 | "cdk": "bin/cdk.js" 6 | }, 7 | "scripts": { 8 | "cdk": "cdk", 9 | "codegen": "graphql-codegen" 10 | }, 11 | "author": "", 12 | "license": "ISC", 13 | "devDependencies": { 14 | "@aws-appsync/eslint-plugin": "^1.1.0", 15 | "@aws-appsync/utils": "^1.2.4", 16 | "@graphql-codegen/cli": "^3.2.2", 17 | "@graphql-codegen/typescript": "^3.0.2", 18 | "@types/node": "^18.14.6", 19 | "@typescript-eslint/eslint-plugin": "^5.54.1", 20 | "@typescript-eslint/parser": "^5.54.1", 21 | "aws-cdk": "^2.67.0", 22 | "aws-cdk-lib": "^2.67.0", 23 | "esbuild": "^0.17.11", 24 | "eslint": "^8.35.0", 25 | "eslint-config-prettier": "^8.7.0", 26 | "eslint-plugin-prettier": "^4.2.1", 27 | "rimraf": "^4.3.1", 28 | "ts-node": "^10.9.1", 29 | "typescript": "^4.9.5" 30 | }, 31 | "dependencies": { 32 | "constructs": "^10.1.270", 33 | "source-map-support": "^0.5.21" 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /schema.graphql: -------------------------------------------------------------------------------- 1 | type Query { 2 | getAuthor(name: ID!): Author 3 | getAuthors: AuthorsResult! 4 | getPosts(author: ID!): PostsResult! 5 | getAllPosts: PostsResult! 6 | getPost(id: ID!): Post! 7 | } 8 | 9 | type Mutation { 10 | createAuthor(author: CreateAuthorInput!): Author! 11 | createPost(post: CreatePostInput!): Post! 12 | createComment(comment: CreateCommentInput!): Comment! 13 | updatePost(post: UpdatePostInput!): Post! 14 | deletePost(id: ID!): Boolean! 15 | } 16 | 17 | type Post { 18 | id: ID! 19 | title: String! 20 | content: String! 21 | authorName: String! 22 | author: Author! 23 | comments: [Comment!] 24 | publishDate: AWSDate! 25 | createdAt: AWSDateTime! 26 | updatedAt: AWSDateTime! 27 | } 28 | 29 | input CreatePostInput { 30 | title: String! 31 | content: String! 32 | authorName: String! 33 | publishDate: AWSDate 34 | } 35 | 36 | input UpdatePostInput { 37 | id: ID! 38 | title: String 39 | content: String 40 | publishDate: AWSDate 41 | } 42 | 43 | type Author { 44 | name: ID! 45 | email: AWSEmail! 46 | posts: [Post!] 47 | createdAt: AWSDateTime! 48 | updatedAt: AWSDateTime! 49 | } 50 | 51 | type PostsResult { 52 | items: [Post!]! 53 | nextToken: String 54 | } 55 | 56 | type AuthorsResult { 57 | items: [Author!]! 58 | nextToken: String 59 | } 60 | 61 | input CreateAuthorInput { 62 | name: ID! 63 | email: AWSEmail! 64 | } 65 | 66 | type Comment { 67 | id: ID! 68 | message: String! 69 | createdAt: AWSDateTime! 70 | updatedAt: AWSDateTime! 71 | } 72 | 73 | input CreateCommentInput { 74 | message: String! 75 | postId: String! 76 | } 77 | -------------------------------------------------------------------------------- /src/lib/helpers.ts: -------------------------------------------------------------------------------- 1 | import { 2 | DynamoDBExpression, 3 | ExpressionAttributeNameMap, 4 | ExpressionAttributeValueMap, 5 | util, 6 | } from '@aws-appsync/utils'; 7 | 8 | export type CreateItem = T & { 9 | updatedAt: string; 10 | createdAt: string; 11 | }; 12 | 13 | export function createItem(item: T): CreateItem { 14 | return { 15 | ...item, 16 | createdAt: util.time.nowISO8601(), 17 | updatedAt: util.time.nowISO8601(), 18 | }; 19 | } 20 | 21 | export type UpdateItem = T & { 22 | updatedAt: string; 23 | }; 24 | 25 | export function updateItem(item: T): UpdateItem { 26 | return { 27 | ...item, 28 | updatedAt: util.time.nowISO8601(), 29 | }; 30 | } 31 | 32 | export function generateUpdateExpressions( 33 | item: Record, 34 | ): DynamoDBExpression { 35 | const updateItem = { 36 | ...item, 37 | updatedAt: util.time.nowISO8601(), 38 | }; 39 | 40 | const updateExpression: string[] = []; 41 | const expressionNames: ExpressionAttributeNameMap = {}; 42 | const expressionValues: ExpressionAttributeValueMap = {}; 43 | 44 | for (const [key, value] of Object.entries(updateItem)) { 45 | updateExpression.push(`#${key} = :${key}`); 46 | expressionNames[`#${key}`] = key; 47 | expressionValues[`:${key}`] = util.dynamodb.toDynamoDB(value); 48 | } 49 | 50 | return { 51 | expression: `set ${updateExpression.join(', ')}`, 52 | expressionNames, 53 | expressionValues, 54 | }; 55 | } 56 | -------------------------------------------------------------------------------- /src/resolvers/createPost.ts: -------------------------------------------------------------------------------- 1 | import { Context, DynamoDBPutItemRequest, util } from '@aws-appsync/utils'; 2 | import { createItem } from '../lib/helpers'; 3 | import { MutationCreatePostArgs, Post } from '../types/appsync'; 4 | 5 | export function request( 6 | ctx: Context, 7 | ): DynamoDBPutItemRequest { 8 | // add timestamps 9 | const item = createItem(ctx.args.post); 10 | 11 | return { 12 | operation: 'PutItem', 13 | key: { 14 | id: util.dynamodb.toDynamoDB(util.autoId()), 15 | }, 16 | attributeValues: util.dynamodb.toMapValues({ 17 | publishDate: util.time.nowISO8601(), 18 | ...item, 19 | }), 20 | }; 21 | } 22 | 23 | export function response( 24 | ctx: Context, 25 | ) { 26 | return ctx.result; 27 | } 28 | -------------------------------------------------------------------------------- /src/resolvers/deletePost.ts: -------------------------------------------------------------------------------- 1 | import { Context, DynamoDBDeleteItemRequest, util } from '@aws-appsync/utils'; 2 | import { MutationDeletePostArgs } from '../types/appsync'; 3 | 4 | export function request( 5 | ctx: Context, 6 | ): DynamoDBDeleteItemRequest { 7 | return { 8 | operation: 'DeleteItem', 9 | key: { 10 | id: util.dynamodb.toDynamoDB(ctx.args.id), 11 | }, 12 | }; 13 | } 14 | 15 | export function response(ctx: Context) { 16 | return ctx.result; 17 | } 18 | -------------------------------------------------------------------------------- /src/resolvers/getPost.ts: -------------------------------------------------------------------------------- 1 | import { Context, DynamoDBGetItemRequest, util } from '@aws-appsync/utils'; 2 | import { Post, QueryGetPostArgs } from '../types/appsync'; 3 | 4 | export function request( 5 | ctx: Context, 6 | ): DynamoDBGetItemRequest { 7 | console.log('ctx.args.id', ctx.args.id); 8 | 9 | return { 10 | operation: 'GetItem', 11 | key: { 12 | id: util.dynamodb.toDynamoDB(ctx.args.id), 13 | }, 14 | }; 15 | } 16 | 17 | export function response( 18 | ctx: Context, 19 | ) { 20 | return ctx.result; 21 | } 22 | -------------------------------------------------------------------------------- /src/resolvers/getPosts.ts: -------------------------------------------------------------------------------- 1 | import { Context, DynamoDBQueryRequest, util } from '@aws-appsync/utils'; 2 | import { 3 | QueryGetPostArgs, 4 | QueryGetPostsArgs, 5 | PostsResult, 6 | } from '../types/appsync'; 7 | 8 | export function request(ctx: Context): DynamoDBQueryRequest { 9 | return { 10 | operation: 'Query', 11 | index: 'byAuthor', 12 | query: { 13 | expression: '#authorName = :authorName', 14 | expressionNames: { 15 | '#authorName': 'authorName', 16 | }, 17 | expressionValues: { 18 | ':authorName': util.dynamodb.toDynamoDB(ctx.args.author), 19 | }, 20 | }, 21 | scanIndexForward: false, 22 | }; 23 | } 24 | 25 | export function response( 26 | ctx: Context, 27 | ) { 28 | return ctx.result; 29 | } 30 | -------------------------------------------------------------------------------- /src/resolvers/updatePost.ts: -------------------------------------------------------------------------------- 1 | import { Context, DynamoDBUpdateItemRequest, util } from '@aws-appsync/utils'; 2 | import { generateUpdateExpressions, updateItem } from '../lib/helpers'; 3 | import { MutationUpdatePostArgs, Post } from '../types/appsync'; 4 | 5 | export function request( 6 | ctx: Context, 7 | ): DynamoDBUpdateItemRequest { 8 | const { id, ...post } = ctx.args.post; 9 | const updatedPost = updateItem(post); 10 | 11 | return { 12 | operation: 'UpdateItem', 13 | key: { 14 | id: util.dynamodb.toDynamoDB(id), 15 | }, 16 | update: generateUpdateExpressions(updatedPost), 17 | condition: { 18 | expression: 'attribute_exists(#id)', 19 | expressionNames: { 20 | '#id': 'id', 21 | }, 22 | }, 23 | }; 24 | } 25 | 26 | export function response( 27 | ctx: Context, 28 | ) { 29 | return ctx.result; 30 | } 31 | -------------------------------------------------------------------------------- /src/types/appsync.ts: -------------------------------------------------------------------------------- 1 | export type Maybe = T | null; 2 | export type InputMaybe = Maybe; 3 | export type Exact = { [K in keyof T]: T[K] }; 4 | export type MakeOptional = Omit & { [SubKey in K]?: Maybe }; 5 | export type MakeMaybe = Omit & { [SubKey in K]: Maybe }; 6 | /** All built-in and custom scalars, mapped to their actual values */ 7 | export type Scalars = { 8 | ID: string; 9 | String: string; 10 | Boolean: boolean; 11 | Int: number; 12 | Float: number; 13 | AWSDate: string; 14 | AWSDateTime: string; 15 | AWSEmail: string; 16 | AWSIPAddress: string; 17 | AWSJSON: string; 18 | AWSPhone: string; 19 | AWSTime: string; 20 | AWSTimestamp: number; 21 | AWSURL: string; 22 | }; 23 | 24 | export type Author = { 25 | __typename?: 'Author'; 26 | createdAt: Scalars['AWSDateTime']; 27 | email: Scalars['AWSEmail']; 28 | name: Scalars['ID']; 29 | posts?: Maybe>; 30 | updatedAt: Scalars['AWSDateTime']; 31 | }; 32 | 33 | export type AuthorsResult = { 34 | __typename?: 'AuthorsResult'; 35 | items: Array; 36 | nextToken?: Maybe; 37 | }; 38 | 39 | export type Comment = { 40 | __typename?: 'Comment'; 41 | createdAt: Scalars['AWSDateTime']; 42 | id: Scalars['ID']; 43 | message: Scalars['String']; 44 | updatedAt: Scalars['AWSDateTime']; 45 | }; 46 | 47 | export type CreateAuthorInput = { 48 | email: Scalars['AWSEmail']; 49 | name: Scalars['ID']; 50 | }; 51 | 52 | export type CreateCommentInput = { 53 | message: Scalars['String']; 54 | postId: Scalars['String']; 55 | }; 56 | 57 | export type CreatePostInput = { 58 | authorName: Scalars['String']; 59 | content: Scalars['String']; 60 | publishDate?: InputMaybe; 61 | title: Scalars['String']; 62 | }; 63 | 64 | export type Mutation = { 65 | __typename?: 'Mutation'; 66 | createAuthor: Author; 67 | createComment: Comment; 68 | createPost: Post; 69 | deletePost: Scalars['Boolean']; 70 | updatePost: Post; 71 | }; 72 | 73 | 74 | export type MutationCreateAuthorArgs = { 75 | author: CreateAuthorInput; 76 | }; 77 | 78 | 79 | export type MutationCreateCommentArgs = { 80 | comment: CreateCommentInput; 81 | }; 82 | 83 | 84 | export type MutationCreatePostArgs = { 85 | post: CreatePostInput; 86 | }; 87 | 88 | 89 | export type MutationDeletePostArgs = { 90 | id: Scalars['ID']; 91 | }; 92 | 93 | 94 | export type MutationUpdatePostArgs = { 95 | post: UpdatePostInput; 96 | }; 97 | 98 | export type Post = { 99 | __typename?: 'Post'; 100 | author: Author; 101 | authorName: Scalars['String']; 102 | comments?: Maybe>; 103 | content: Scalars['String']; 104 | createdAt: Scalars['AWSDateTime']; 105 | id: Scalars['ID']; 106 | publishDate: Scalars['AWSDate']; 107 | title: Scalars['String']; 108 | updatedAt: Scalars['AWSDateTime']; 109 | }; 110 | 111 | export type PostsResult = { 112 | __typename?: 'PostsResult'; 113 | items: Array; 114 | nextToken?: Maybe; 115 | }; 116 | 117 | export type Query = { 118 | __typename?: 'Query'; 119 | getAllPosts: PostsResult; 120 | getAuthor?: Maybe; 121 | getAuthors: AuthorsResult; 122 | getPost: Post; 123 | getPosts: PostsResult; 124 | }; 125 | 126 | 127 | export type QueryGetAuthorArgs = { 128 | name: Scalars['ID']; 129 | }; 130 | 131 | 132 | export type QueryGetPostArgs = { 133 | id: Scalars['ID']; 134 | }; 135 | 136 | 137 | export type QueryGetPostsArgs = { 138 | author: Scalars['ID']; 139 | }; 140 | 141 | export type UpdatePostInput = { 142 | content?: InputMaybe; 143 | id: Scalars['ID']; 144 | publishDate?: InputMaybe; 145 | title?: InputMaybe; 146 | }; 147 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "ES2020", 4 | "module": "commonjs", 5 | "lib": [ 6 | "es2020" 7 | ], 8 | "declaration": true, 9 | "strict": true, 10 | "noImplicitAny": true, 11 | "strictNullChecks": true, 12 | "noImplicitThis": true, 13 | "alwaysStrict": true, 14 | "noUnusedLocals": false, 15 | "noUnusedParameters": false, 16 | "noImplicitReturns": true, 17 | "noFallthroughCasesInSwitch": false, 18 | "inlineSourceMap": true, 19 | "inlineSources": true, 20 | "experimentalDecorators": true, 21 | "strictPropertyInitialization": false, 22 | "typeRoots": [ 23 | "./node_modules/@types" 24 | ] 25 | }, 26 | "exclude": [ 27 | "node_modules", 28 | "cdk.out" 29 | ] 30 | } 31 | --------------------------------------------------------------------------------