-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
--- | ||
exclude_paths: | ||
- "graphql/mutation/*/appsync.js" | ||
- "graphql/query/*/appsync.js" |
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.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { util, Context, DynamoDBPutItemRequest, AppSyncIdentityCognito, PutItemInputAttributeMap } from '@aws-appsync/utils'; | ||
Check failure on line 1 in graphql/mutation/createGame/appsync.ts Codacy Production / Codacy Static Code Analysisgraphql/mutation/createGame/appsync.ts#L1
|
||
|
||
/** | ||
* 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 | ||
} | ||
Check failure on line 12 in graphql/mutation/createGame/appsync.ts Codacy Production / Codacy Static Code Analysisgraphql/mutation/createGame/appsync.ts#L12
|
||
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.'); | ||
} | ||
|
||
var identity = ctx.identity as AppSyncIdentityCognito; | ||
if (!identity.sub) { | ||
util.error('Unauthorized: User ID is missing.'); | ||
} | ||
|
||
var input = ctx.arguments.input; | ||
Check failure on line 41 in graphql/mutation/createGame/appsync.ts Codacy Production / Codacy Static Code Analysisgraphql/mutation/createGame/appsync.ts#L41
Check failure on line 41 in graphql/mutation/createGame/appsync.ts Codacy Production / Codacy Static Code Analysisgraphql/mutation/createGame/appsync.ts#L41
|
||
var id = util.autoId(); | ||
Check failure on line 42 in graphql/mutation/createGame/appsync.ts Codacy Production / Codacy Static Code Analysisgraphql/mutation/createGame/appsync.ts#L42
Check failure on line 42 in graphql/mutation/createGame/appsync.ts Codacy Production / Codacy Static Code Analysisgraphql/mutation/createGame/appsync.ts#L42
|
||
var timestamp = util.time.nowISO8601(); | ||
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, | ||
}) as PutItemInputAttributeMap, | ||
}; | ||
} | ||
|
||
export function response(ctx: Context): unknown { | ||
if (ctx.error) { | ||
return util.appendError(ctx.error.message, ctx.error.type, ctx.result); | ||
} | ||
return ctx.result; | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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" | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.