The ts-graphql-yoga
sample application demonstrates how to use the @klotho::expose
annotation with a graphql-yoga server. The sample application defines a graphql endpoint to run queries and mutations against.
This guide assumes:
run the terminal commands:
npm install
npx ts-node index.ts
# [email protected] start
# ts-node src/index.ts
# Server is running on http://localhost:3000/graphql
Running queries through the browser
# hello
query {
hello
}
# > {
# > "data": {
# > "hello": "Hello from Klotho!"
# > }
# > }
run the terminal commands:
# Compile the app
npx tsc && klotho . --app ts-graphql-yoga -p aws
# Go into the compiled directory
cd compiled
# If you didn't set the aws region as indicated in the compiler output, do that now
pulumi config set aws:region YOUR_REGION -s ts-graphql-yoga
# npm install
npm install
# Deploy
pulumi up -s ts-graphql-yoga
# Outputs: {
# apiUrl: 'https://<...>.execute-api.<YOUR_REGION>.amazonaws.com/stage/'
# }
# Add a user
curl 'https://<...>.execute-api.<YOUR_REGION>.amazonaws.com/stage/graphql' -X POST -H 'content-type: application/json' --data '{"query": "query {hello}"}'
# > {"data":{"hello":"Hello from Klotho!"}}%
From the compiled directory still,
# Tear down when done
pulumi destroy -s ts-graphql-yoga