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 17, 2024
1 parent 59591ad commit 200f8e8
Show file tree
Hide file tree
Showing 3,359 changed files with 784,180 additions and 13 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
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 .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"root": true}
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
18 changes: 15 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,10 @@ 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

.PHONY: graphql-eslint
graphql-eslint:
docker run --rm -it --user $$(id -u):$$(id -g) -v $(PWD)/graphql:/code pipelinecomponents/eslint eslint
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
11 changes: 11 additions & 0 deletions graphql/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import globals from "globals";
import pluginJs from "@eslint/js";
import tseslint from "typescript-eslint";


export default [
{files: ["**/*.{js,mjs,cjs,ts}"]},
{languageOptions: { globals: {...globals.browser, ...globals.node} }},
pluginJs.configs.recommended,
...tseslint.configs.recommended,
];
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';

/**
* 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 {
if (!context.identity) {
util.error('Unauthorized: Identity information is missing.' as string);
}

const identity = context.identity as AppSyncIdentityCognito;
if (!identity.sub) {
util.error('Unauthorized: User ID is missing.' as string);
}

const input = context.arguments.input;
const id = util.autoId();
const timestamp = util.time.nowISO8601();
return {
operation: 'PutItem',
key: util.dynamodb.toMapValues({ PK: "GAME#"+id, SK: 'GAME' }),
attributeValues: util.dynamodb.toMapValues({
name: input.name,
description: input.description,
id: id,
fireflyUserId: identity.sub,
createdAt: timestamp,
updatedAt: timestamp
}) as PutItemInputAttributeMap
};
}

export function response(context: Context): unknown {
if (context.error) {
util.appendError(context.error.message, context.error.type, context.result);
return;
}
return context.result;
}
1 change: 1 addition & 0 deletions graphql/node_modules/.bin/acorn

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

1 change: 1 addition & 0 deletions graphql/node_modules/.bin/eslint

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

1 change: 1 addition & 0 deletions graphql/node_modules/.bin/js-yaml

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

1 change: 1 addition & 0 deletions graphql/node_modules/.bin/node-which

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

1 change: 1 addition & 0 deletions graphql/node_modules/.bin/semver

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

1 change: 1 addition & 0 deletions graphql/node_modules/.bin/tsc

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

1 change: 1 addition & 0 deletions graphql/node_modules/.bin/tsserver

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

Loading

0 comments on commit 200f8e8

Please sign in to comment.