Skip to content

Commit

Permalink
Adding first Strawberry test
Browse files Browse the repository at this point in the history
  • Loading branch information
paula-mg committed Sep 5, 2024
1 parent 0f7329f commit 18d4d6b
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
5 changes: 3 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ requires-python = ">=3.10"
plotting = ["scipy", "matplotlib"]
# REST service support
service = ["fastapi>=0.100.0", "uvicorn"]
# For development tests/docs
dev = [
# This syntax is supported since pip 21.2
# https://github.com/pypa/pip/issues/10393
Expand All @@ -41,11 +40,13 @@ dev = [
"sphinx-copybutton",
"sphinx-design",
"sphinxcontrib-openapi",
"strawberry-graphql[debug-server]",
"strawberry-graphql[fastapi]",
"tox-direct",
"types-mock",
"httpx",
"myst-parser",
]
] # For development tests/docs

[project.scripts]
scanspec = "scanspec.cli:cli"
Expand Down
34 changes: 34 additions & 0 deletions src/scanspec/schema.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import strawberry
from fastapi import FastAPI
from strawberry.fastapi import GraphQLRouter


def get_lines():
# example line
return [Line(name="line", axis="x", start=0.2, stop=0.3, num=4)]


@strawberry.input
class Line:
name: str
axis: str = strawberry.field(description="An identifier for what to move")
start: float = strawberry.field(
description="Midpoint of the first point of the line"
)
stop: float = strawberry.field(description="Midpoint of the last point of the line")
num: int = strawberry.field(description="Number of frames to produce")


@strawberry.type
class Query:
@strawberry.field
def validate(self, spec: Line) -> str:
return "accepted"


schema = strawberry.Schema(Query)

graphql_app = GraphQLRouter(schema, path="/", graphql_ide="apollo-sandbox")

app = FastAPI()
app.include_router(graphql_app, prefix="/graphql")

0 comments on commit 18d4d6b

Please sign in to comment.