Skip to content

Commit

Permalink
Add GraphQL mutation to load example script
Browse files Browse the repository at this point in the history
  • Loading branch information
TaiSakuma committed May 9, 2024
1 parent 47c61f5 commit d4da8d3
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions nextlinegraphql/plugins/ctrl/schema/mutation.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
from pathlib import Path
from typing import Optional

import strawberry
from nextline import Nextline
from strawberry.types import Info

from nextlinegraphql.plugins.ctrl import example_script as example_script_module

EXAMPLE_SCRIPT_PATH = Path(example_script_module.__file__).parent / 'script.py'
assert EXAMPLE_SCRIPT_PATH.is_file()
example_script = EXAMPLE_SCRIPT_PATH.read_text()


async def mutate_exec(info: Info) -> bool:
nextline = info.context['nextline']
Expand Down Expand Up @@ -56,6 +63,13 @@ async def mutate_kill(info: Info) -> bool:
return True


async def mutate_load_example_script(info: Info) -> bool:
nextline = info.context['nextline']
assert isinstance(nextline, Nextline)
await nextline.reset(statement=example_script)
return True


@strawberry.type
class Mutation:
exec: bool = strawberry.field(resolver=mutate_exec)
Expand All @@ -65,3 +79,4 @@ class Mutation:
interrupt: bool = strawberry.field(resolver=mutate_interrupt)
terminate: bool = strawberry.field(resolver=mutate_terminate)
kill: bool = strawberry.field(resolver=mutate_kill)
load_example_script: bool = strawberry.field(resolver=mutate_load_example_script)

0 comments on commit d4da8d3

Please sign in to comment.