docker container run --rm -d --name gql -p 8000:80 ubuntu sleep inf
sleep 2
{ cat <<'eof2'
apt-get update &&
apt-get install -y python3-pip
pip install fastapi uvicorn ariadne
mkdir -p /tmp/gql
cd /tmp/gql
cut -c3- <<'eof' > main.py
from fastapi import FastAPI
from ariadne import gql, QueryType, make_executable_schema
from ariadne.asgi import GraphQL
app = FastAPI()
type_defs = gql("""
type Query {
hello: String!
}
""")
query = QueryType()
@query.field("hello")
def resolve_hello(*_):
return "Hello, world!"
schema = make_executable_schema(type_defs, query)
app.add_route("/graphql", GraphQL(schema, debug=True))
eof
eof2
} | docker container exec -i gql /bin/bash
docker container exec -w /tmp/gql gql \
uvicorn main:app --host 0.0.0.0 --port 80 --reload
... in another terminal
curl -s -X POST \
-H "Content-Type: application/json" \
-d '{"query":"query { hello }"}' \
http://localhost:8000/graphql |
jq .
... or in a browser