Skip to content

Commit

Permalink
Add connector query
Browse files Browse the repository at this point in the history
  • Loading branch information
edlouth committed Nov 30, 2023
1 parent 4dab9fa commit 0b439f6
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 0 deletions.
31 changes: 31 additions & 0 deletions grai-frontend/src/testing/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,37 @@
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "connector",
"description": null,
"args": [
{
"name": "id",
"description": null,
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "ID",
"ofType": null
}
},
"defaultValue": null
}
],
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "OBJECT",
"name": "Connector",
"ofType": null
}
},
"isDeprecated": false,
"deprecationReason": null
}
],
"inputFields": null,
Expand Down
5 changes: 5 additions & 0 deletions grai-server/app/api/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ class Query:
connectors: List[Connector] = strawberry.django.field(
permission_classes=[IsAuthenticated], order=ConnectorOrder, pagination=True
)

@strawberry.django.field(permission_classes=[IsAuthenticated])
def connector(self, id: strawberry.ID) -> Connector:
return ConnectorModel.objects.get(id=id)

profile: Profile = strawberry.django.field(resolver=get_profile, permission_classes=[IsAuthenticated])
# devices: DataWrapper[Device] = strawberry.field(
# resolver=get_devices, permission_classes=[IsAuthenticated]
Expand Down
27 changes: 27 additions & 0 deletions grai-server/app/api/tests/test_queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,3 +254,30 @@ async def test_profile_devices(test_context):
]
},
}


@pytest.mark.django_db
@pytest.mark.asyncio
async def test_connector(test_context, test_connector):
context, organisation, workspace, user, membership = test_context

query = """
query Connector($connectorId: ID!) {
connector(id: $connectorId) {
id
}
}
"""

result = await schema.execute(
query,
variable_values={
"connectorId": str(test_connector.id),
},
context_value=context,
)

assert result.errors is None
assert result.data["connector"] == {
"id": str(test_connector.id),
}

0 comments on commit 0b439f6

Please sign in to comment.