-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
59591ad
commit ff71e4b
Showing
14 changed files
with
278 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
graphql/%/appsync.js: graphql/node_modules $(wildcard graphql/%/*.ts) | ||
cd graphql && \ | ||
esbuild $*/*.ts \ | ||
--bundle \ | ||
--external:"@aws-appsync/utils" \ | ||
--format=esm \ | ||
--platform=node \ | ||
--target=esnext \ | ||
--sourcemap=inline \ | ||
--sources-content=false \ | ||
--outdir=$* | ||
|
||
graphql/node_modules: graphql/package.json | ||
cd graphql && npm install | ||
|
||
GRAPHQL := $(patsubst %.ts,%.js,$(wildcard graphql/*/*/appsync.ts)) | ||
|
||
.PHONY: graphql | ||
graphql: $(GRAPHQL) | ||
echo $(GRAPHQL) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { util, Context, DynamoDBPutItemRequest, AppSyncIdentityCognito } from '@aws-appsync/utils'; | ||
|
||
/** | ||
* A CreateGameInput creates a Game. | ||
* They are stored in DynamoDB with a PK of `GAME#<id>` and an SK of `GAME`. | ||
* The ID is a UUID | ||
* The fireflyUserId is the Cognito ID of the user | ||
input CreateGameInput { | ||
name: String! | ||
description: String | ||
} | ||
type Game { | ||
id: ID! | ||
name: String! | ||
description: String | ||
publicNotes: String | ||
privateNotes: String | ||
fireflyUserId: ID! | ||
createdAt: AWSDateTime! | ||
updatedAt: AWSDateTime! | ||
} | ||
*/ | ||
|
||
interface CreateGameInput { | ||
name: string; | ||
description?: string; | ||
} | ||
|
||
export function request(ctx: Context<{ input: CreateGameInput }>): DynamoDBPutItemRequest { | ||
if (!ctx.identity) { | ||
util.error('Unauthorized: Identity information is missing.'); | ||
} | ||
|
||
const identity = ctx.identity as AppSyncIdentityCognito; | ||
if (!identity.sub) { | ||
util.error('Unauthorized: User ID is missing.'); | ||
} | ||
|
||
const { input } = ctx.arguments; | ||
Check failure on line 41 in graphql/mutation/createGame/appsync.ts Codacy Production / Codacy Static Code Analysisgraphql/mutation/createGame/appsync.ts#L41
|
||
const id = util.autoId(); | ||
const timestamp = util.time.nowISO8601(); | ||
Check failure on line 43 in graphql/mutation/createGame/appsync.ts Codacy Production / Codacy Static Code Analysisgraphql/mutation/createGame/appsync.ts#L43
|
||
return { | ||
operation: 'PutItem', | ||
key: util.dynamodb.toMapValues({ PK: `GAME#${id}`, SK: 'GAME' }), | ||
attributeValues: util.dynamodb.toMapValues({ | ||
...input, | ||
id, | ||
fireflyUserId: identity.sub, | ||
createdAt: timestamp, | ||
updatedAt: timestamp, | ||
}), | ||
}; | ||
} | ||
|
||
export function response(ctx: Context): unknown { | ||
const { error, result } = ctx; | ||
if (error) { | ||
return util.appendError(error.message, error.type, result); | ||
} | ||
return result; | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"name": "graphql", | ||
"version": "1.0.0", | ||
"dependencies": { | ||
"@aws-appsync/utils": "^1.7.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters