Skip to content

Commit

Permalink
Add a mutation to graphql
Browse files Browse the repository at this point in the history
  • Loading branch information
jarrod-lowe committed Aug 15, 2024
1 parent 59591ad commit c3fc897
Show file tree
Hide file tree
Showing 69 changed files with 3,691 additions and 17 deletions.
4 changes: 4 additions & 0 deletions .codacy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
exclude_paths:
- "graphql/mutation/*/appsync.js"
- "graphql/query/*/appsync.js"
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ override.tf.json
# Ignore CLI configuration files
.terraformrc
terraform.rc

.validate
.apply
plan.tfplan
14 changes: 11 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ RW_ROLE = arn:aws:iam::$(ACCOUNT_ID):role/GitHubAction-Wildsea-rw-dev

all: $(TERRAFOM_VALIDATE)

include graphql/graphql.mk

.PHONY: terraform-format
terraform-format: $(addprefix terraform-format-environment-,$(TERRAFORM_ENVIRONMENTS)) $(addprefix terraform-format-module-,$(TERRAFORM_MODULES))
@true
Expand All @@ -35,13 +37,16 @@ terraform/environment/aws-dev/.apply: terraform/environment/aws-dev/*.tf terrafo
./terraform/environment/aws-dev/deploy.sh $(ACCOUNT_ID) dev
touch $@

terraform/environment/wildsea-dev/plan.tfplan: terraform/environment/wildsea-dev/*.tf terraform/module/wildsea/*.tf terraform/environment/wildsea-dev/.terraform
terraform/environment/wildsea-dev/plan.tfplan: terraform/environment/wildsea-dev/*.tf terraform/module/wildsea/*.tf terraform/environment/wildsea-dev/.terraform $(GRAPHQL)
cd terraform/environment/wildsea-dev ; ../../../scripts/run-as.sh $(RO_ROLE) \
terraform plan -out=./plan.tfplan

terraform/environment/wildsea-dev/.apply: terraform/environment/wildsea-dev/plan.tfplan
terraform/environment/wildsea-dev/.apply: terraform/environment/wildsea-dev/plan.tfplan $(GRAPHQL)
cd terraform/environment/wildsea-dev ; ../../../scripts/run-as.sh $(RW_ROLE) \
terraform apply ./plan.tfplan
terraform apply ./plan.tfplan ; \
status=$$? ; \
rm -f $< ; \
[ "$$status" -eq 0 ]
touch $@

terraform/environment/wildsea-dev/.terraform: terraform/environment/wildsea-dev/*.tf terraform/module/wildsea/*.tf
Expand All @@ -54,3 +59,6 @@ terraform/environment/wildsea-dev/.terraform: terraform/environment/wildsea-dev/
clean:
rm -f terraform/environment/*/.validate
rm -f terraform/environment/*/plan.tfplan
rm -f graphql/mutation/*/appsync.js
rm -f graphql/query/*/appsync.js
rm -rf graphql/node_modules
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Wildsea companion app
* Log into Codacy, and connect the repo
* Configure the rule to maximum
* In Codacy, in the repo, go to code patterns, and edit the coding standard:
* Set the languages to: CSS, Go, JSON, Javascript, Markdown, Python, Shell, Terraform, Typescript, XML, YAML
* Set the languages to: CSS, Go, JSON, Markdown, Python, Shell, Terraform, Typescript, XML, YAML
* Select every tool that is:
* NOT client-side
* NOT deprecated
Expand Down Expand Up @@ -86,6 +86,8 @@ If you do not set the secret, then Cognito will be used as the identity source.

## Development Environment

Install esbuild with `sudo npm install -g --save-exact --save-dev esbuild`

After having set up the AWS Account, use `AWS_PROFILE=<profile> make dev` to
deploy a development version. If this is a different AWS Account from the real
deployment, you will need to create an S3 bucket for the state, in the same way
Expand Down
20 changes: 20 additions & 0 deletions graphql/graphql.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
graphql/%/appsync.js: graphql/node_modules graphql/%/appsync.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)
38 changes: 38 additions & 0 deletions graphql/mutation/createGame/appsync.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 48 additions & 0 deletions graphql/mutation/createGame/appsync.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { util, Context, DynamoDBPutItemRequest, AppSyncIdentityCognito, PutItemInputAttributeMap } from '@aws-appsync/utils';

Check failure on line 1 in graphql/mutation/createGame/appsync.ts

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

graphql/mutation/createGame/appsync.ts#L1

ES2015 modules are forbidden.

Check failure on line 1 in graphql/mutation/createGame/appsync.ts

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

graphql/mutation/createGame/appsync.ts#L1

You have a misspelled word: Cognito on Identifier

/**
* 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
*/

interface CreateGameInput {
name: string;
description?: string;
}

export function request(context: Context<{ input: CreateGameInput }>): DynamoDBPutItemRequest {

Check failure on line 15 in graphql/mutation/createGame/appsync.ts

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

graphql/mutation/createGame/appsync.ts#L15

ES2015 modules are forbidden.
if (!context.identity) {
util.error('Unauthorized: Identity information is missing.' as string);
}

const identity = context.identity as AppSyncIdentityCognito;

Check failure on line 20 in graphql/mutation/createGame/appsync.ts

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

graphql/mutation/createGame/appsync.ts#L20

ES2015 block-scoped variables are forbidden.

Check failure on line 20 in graphql/mutation/createGame/appsync.ts

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

graphql/mutation/createGame/appsync.ts#L20

You have a misspelled word: Cognito on Identifier
if (!identity.sub) {
util.error('Unauthorized: User ID is missing.' as string);
}

const input = context.arguments.input;

Check failure on line 25 in graphql/mutation/createGame/appsync.ts

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

graphql/mutation/createGame/appsync.ts#L25

ES2015 block-scoped variables are forbidden.
const id = util.autoId();

Check failure on line 26 in graphql/mutation/createGame/appsync.ts

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

graphql/mutation/createGame/appsync.ts#L26

ES2015 block-scoped variables are forbidden.
const timestamp = util.time.nowISO8601();

Check failure on line 27 in graphql/mutation/createGame/appsync.ts

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

graphql/mutation/createGame/appsync.ts#L27

ES2015 block-scoped variables are forbidden.
return {
operation: 'PutItem',
key: util.dynamodb.toMapValues({ PK: "GAME#"+id, SK: 'GAME' }),

Check failure on line 30 in graphql/mutation/createGame/appsync.ts

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

graphql/mutation/createGame/appsync.ts#L30

You have a misspelled word: dynamodb on Identifier
attributeValues: util.dynamodb.toMapValues({

Check failure on line 31 in graphql/mutation/createGame/appsync.ts

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

graphql/mutation/createGame/appsync.ts#L31

You have a misspelled word: dynamodb on Identifier
name: input.name,
description: input.description,
id: id,
fireflyUserId: identity.sub,
createdAt: timestamp,
updatedAt: timestamp
}) as PutItemInputAttributeMap
};
}

export function response(context: Context): unknown {

Check failure on line 42 in graphql/mutation/createGame/appsync.ts

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

graphql/mutation/createGame/appsync.ts#L42

ES2015 modules are forbidden.
if (context.error) {
util.appendError(context.error.message, context.error.type, context.result);
return;
}
return context.result;
}
13 changes: 13 additions & 0 deletions graphql/node_modules/.package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

137 changes: 137 additions & 0 deletions graphql/node_modules/@aws-appsync/utils/CHANGELOG.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit c3fc897

Please sign in to comment.