Skip to content

Commit

Permalink
Reorganize GraphQL queries to under 'ctrl' namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
TaiSakuma committed May 14, 2024
1 parent 2798771 commit c6deddf
Show file tree
Hide file tree
Showing 24 changed files with 160 additions and 120 deletions.
4 changes: 3 additions & 1 deletion nextlinegraphql/plugins/ctrl/graphql/mutations/Exec.gql
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
mutation Exec {
exec
ctrl {
exec
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
mutation LoadExampleScript {
loadExampleScript
ctrl {
loadExampleScript
}
}
4 changes: 3 additions & 1 deletion nextlinegraphql/plugins/ctrl/graphql/mutations/Reset.gql
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
mutation Reset($statement: String) {
reset(statement: $statement)
ctrl {
reset(statement: $statement)
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
mutation RunAndContinue {
runAndContinue
ctrl {
runAndContinue
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
mutation SendPdbCommand($command: String!, $promptNo: Int!, $traceNo: Int!) {
sendPdbCommand(command: $command, promptNo: $promptNo, traceNo: $traceNo)
ctrl {
sendPdbCommand(command: $command, promptNo: $promptNo, traceNo: $traceNo)
}
}
4 changes: 3 additions & 1 deletion nextlinegraphql/plugins/ctrl/graphql/queries/Exception.gql
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
query Exception {
exception
ctrl {
exception
}
}
4 changes: 3 additions & 1 deletion nextlinegraphql/plugins/ctrl/graphql/queries/Source.gql
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
query Source($fileName: String) {
source(fileName: $fileName)
ctrl {
source(fileName: $fileName)
}
}
4 changes: 3 additions & 1 deletion nextlinegraphql/plugins/ctrl/graphql/queries/SourceLine.gql
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
query SourceLine($lineNo: Int!, $fileName: String) {
sourceLine(lineNo: $lineNo, fileName: $fileName)
ctrl {
sourceLine(lineNo: $lineNo, fileName: $fileName)
}
}
4 changes: 3 additions & 1 deletion nextlinegraphql/plugins/ctrl/graphql/queries/State.gql
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
query State {
state
ctrl {
state
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
subscription Counter {
counter
ctrlCounter
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
subscription Prompting($traceId: Int!) {
prompting(traceId: $traceId) {
ctrlPrompting(traceId: $traceId) {
prompting
fileName
lineNo
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
subscription State {
state
ctrlState
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
subscription Stdout {
stdout
ctrlStdout
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
subscription TraceIds {
traceIds
ctrlTraceIds
}
9 changes: 8 additions & 1 deletion nextlinegraphql/plugins/ctrl/schema/mutation.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ async def mutate_load_example_script(info: Info) -> bool:


@strawberry.type
class Mutation:
class MutationCtrl:
exec: bool = strawberry.field(resolver=mutate_exec)
run_and_continue: bool = strawberry.field(resolver=mutate_run_and_continue)
reset: bool = strawberry.field(resolver=mutate_reset)
Expand All @@ -80,3 +80,10 @@ class Mutation:
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)


@strawberry.type
class Mutation:
@strawberry.field
def ctrl(self) -> MutationCtrl:
return MutationCtrl()
9 changes: 8 additions & 1 deletion nextlinegraphql/plugins/ctrl/schema/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def query_continuous_enabled(info: Info) -> bool:


@strawberry.type
class Query:
class QueryCtrl:
hello: str = strawberry.field(resolver=query_hello)
state: str = strawberry.field(resolver=query_state)
run_no: int = strawberry.field(resolver=query_run_no)
Expand All @@ -58,3 +58,10 @@ class Query:
source_line: str = strawberry.field(resolver=query_source_line)
exception: Optional[str] = strawberry.field(resolver=query_exception)
continuous_enabled: bool = strawberry.field(resolver=query_continuous_enabled)


@strawberry.type
class Query:
@strawberry.field
def ctrl(self) -> QueryCtrl:
return QueryCtrl()
14 changes: 7 additions & 7 deletions nextlinegraphql/plugins/ctrl/schema/subscription.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,24 +73,24 @@ def subscribe_continuous_enabled(info: Info) -> AsyncIterator[bool]:

@strawberry.type
class Subscription:
counter: AsyncIterator[int] = strawberry.field(
ctrl_counter: AsyncIterator[int] = strawberry.field(
is_subscription=True, resolver=subscribe_counter
)
state: AsyncIterator[str] = strawberry.field(
ctrl_state: AsyncIterator[str] = strawberry.field(
is_subscription=True, resolver=subscribe_state
)
run_no: AsyncIterator[int] = strawberry.field(
ctrl_run_no: AsyncIterator[int] = strawberry.field(
is_subscription=True, resolver=subscribe_run_no
)
trace_ids: AsyncIterator[tuple[int, ...]] = strawberry.field(
ctrl_trace_ids: AsyncIterator[tuple[int, ...]] = strawberry.field(
is_subscription=True, resolver=subscribe_trace_ids
)
prompting: AsyncIterator[PromptingData] = strawberry.field(
ctrl_prompting: AsyncIterator[PromptingData] = strawberry.field(
is_subscription=True, resolver=subscribe_prompting
)
stdout: AsyncIterator[str] = strawberry.field(
ctrl_stdout: AsyncIterator[str] = strawberry.field(
is_subscription=True, resolver=subscribe_stdout
)
continuous_enabled: AsyncIterator[bool] = strawberry.field(
ctrl_continuous_enabled: AsyncIterator[bool] = strawberry.field(
is_subscription=True, resolver=subscribe_continuous_enabled
)
18 changes: 10 additions & 8 deletions tests/plugins/ctrl/schema/examples/test_async_asgi_testclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

async def test_query():
query = '''
{ hello }
{ ctrl
{ hello }
}
'''
data = {'query': query}

Expand All @@ -16,14 +18,14 @@ async def test_query():
async with TestClient(create_app()) as client:
resp = await client.post('/', json=data, headers=headers)
assert resp.status_code == 200
expect = {'data': {'hello': 'Hello, Mozilla/5.0!'}}
expect = {'data': {'ctrl': {'hello': 'Hello, Mozilla/5.0!'}}}
assert expect == resp.json()


async def test_subscription():
query = '''
subscription {
counter
ctrlCounter
}
'''

Expand All @@ -45,39 +47,39 @@ async def test_subscription():
expect = {
'type': 'data',
'id': '1',
'payload': {'data': {'counter': 1}},
'payload': {'data': {'ctrlCounter': 1}},
}
actual = await ws.receive_json()
assert expect == actual

expect = {
'type': 'data',
'id': '1',
'payload': {'data': {'counter': 2}},
'payload': {'data': {'ctrlCounter': 2}},
}
actual = await ws.receive_json()
assert expect == actual

expect = {
'type': 'data',
'id': '1',
'payload': {'data': {'counter': 3}},
'payload': {'data': {'ctrlCounter': 3}},
}
actual = await ws.receive_json()
assert expect == actual

expect = {
'type': 'data',
'id': '1',
'payload': {'data': {'counter': 4}},
'payload': {'data': {'ctrlCounter': 4}},
}
actual = await ws.receive_json()
assert expect == actual

expect = {
'type': 'data',
'id': '1',
'payload': {'data': {'counter': 5}},
'payload': {'data': {'ctrlCounter': 5}},
}
actual = await ws.receive_json()
assert expect == actual
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ async def test_query() -> None:
result = await schema.execute(MUTATE_LOAD_EXAMPLE_SCRIPT, context_value=context)
assert not result.errors
assert result.data
assert result.data['loadExampleScript'] is True
assert result.data['ctrl']['loadExampleScript'] is True
assert nextline.statement == example_script
4 changes: 2 additions & 2 deletions tests/plugins/ctrl/schema/mutations/test_reset.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ async def test_schema(statement: str | None) -> None:
MUTATE_RESET, context_value=context, variable_values=variables
)
assert (data := result.data)
assert data['reset'] is True
assert data['ctrl']['reset'] is True

result = await schema.execute(QUERY_SOURCE, context_value=context)
assert (data := result.data)

expected = statement or example_script
assert expected.split('\n') == data['source']
assert expected.split('\n') == data['ctrl']['source']
Loading

0 comments on commit c6deddf

Please sign in to comment.