Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,15 @@ jobs:
- name: Install Dependencies
run: |
python -m pip install --upgrade pip
pip install yapf pylint pydicom
pip install yapf pylint pydicom ariadne

- name: Check format with yapf (Google Style)
run: yapf --diff --style google --recursive orthanc/python/

- name: Run pylint
run: pylint orthanc/python/
run: |
pylint orthanc/python/ \
--msg-template="::error file={path},line={line},col={column},title=Pylint ({msg_id})::{category}: {msg}"

build:
name: Build Docker Image
Expand All @@ -41,3 +43,23 @@ jobs:

- name: Build with docker compose
run: docker compose build

- name: Start docker compose
run: docker compose up -d

- name: Wait for Orthanc to be ready
run: |
echo "Waiting for Orthanc to start..."
timeout 30 bash -c 'while ! curl -s -f -u demo:demo http://localhost:8000/system; do sleep 2; done'
echo "Orthanc is ready!"

- name: Test GraphQL Endpoint
run: |
response=$(curl -s -X POST -u demo:demo -H "Content-Type: application/json" -d '{"query": "{ hello }"}' http://localhost:8000/graphql)
echo "Response: $response"
# Check if the output contains the expected "Hello from Orthanc GraphQL!" string
if [[ "$response" != *"Hello from Orthanc GraphQL!"* ]]; then
echo "GraphQL test failed. Unexpected response."
exit 1
fi
echo "GraphQL test passed!"
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ services:

VERBOSE_ENABLED: "true"
VERBOSE_STARTUP: "true"
ORTHANC__PYTHON_SCRIPT: "/python/graphql.py"
ORTHANC__PYTHON_SCRIPT: "/python/orthanc-graphql.py"
ORTHANC__PYTHON_VERBOSE: "true"

ORTHANC__REGISTERED_USERS: |
Expand Down
4 changes: 2 additions & 2 deletions orthanc/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ FROM orthancteam/orthanc
RUN apt-get update && apt install -y python3-venv
RUN python3 -m venv /.venv

RUN /.venv/bin/pip install pydicom
ENV PYTHONPATH=/.venv/lib64/python3.12/site-packages/
RUN /.venv/bin/pip install pydicom ariadne
ENV PYTHONPATH=/.venv/lib/python3.14/site-packages/

RUN mkdir /python
COPY * /python/
Empty file removed orthanc/python/graphql.py
Empty file.
55 changes: 55 additions & 0 deletions orthanc/python/orthanc-graphql.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# pylint: disable=invalid-name,import-error
"""
Orthanc GraphQL endpoint implementation using Ariadne.
"""
import json

from ariadne import QueryType, graphql_sync, make_executable_schema

import orthanc

# 1. Define a simple GraphQL schema
TYPE_DEFS = """
type Query {
hello: String!
}
"""

query = QueryType()


@query.field("hello")
def resolve_hello(_, _info):
"""Resolver for the 'hello' query."""
return "Hello from Orthanc GraphQL!"


schema = make_executable_schema(TYPE_DEFS, query)


def graphql_endpoint(output, _url, **request):
"""REST callback injected into Orthanc for GraphQL endpoints."""
if request['method'] != 'POST':
output.SendMethodNotAllowed('POST')
return

try:
# Parse the JSON body from the request
data = json.loads(request['body'])

# 2. Execute GraphQL query
_, response = graphql_sync(schema,
data,
context_value=request,
debug=True)

# 3. Use AnswerBuffer to return HTTP 200 JSON response
output.AnswerBuffer(json.dumps(response), 'application/json')

except Exception as e: # pylint: disable=broad-exception-caught
# Fallback for parsing errors or other exceptions
error_response = {"errors": [{"message": str(e)}]}
output.AnswerBuffer(json.dumps(error_response), 'application/json')


orthanc.RegisterRestCallback('/graphql', graphql_endpoint)
Loading