Created
November 12, 2019 08:40
-
-
Save chiaki64/049fb402d2f1bb46139daf60a9d874bf to your computer and use it in GitHub Desktop.
pygraphy test code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import uvicorn | |
import pygraphy | |
from fastapi import FastAPI | |
from typing import Optional, List | |
app = FastAPI() | |
class Foo(pygraphy.Object): | |
a: str | |
class Bar(pygraphy.Object): | |
b: int | |
class FooBar(pygraphy.Union): | |
members = (Foo, Bar) | |
class GeoInput(pygraphy.Input): | |
lat: float | |
lng: float | |
string: str # new | |
@property | |
def latlng(self): | |
return "({},{})".format(self.lat, self.lng) | |
class Address(pygraphy.Object): | |
latlng: str | |
@pygraphy.field | |
def foobar(self) -> List[FooBar]: | |
return [Foo(a="test") for _ in range(5)] | |
class Query(pygraphy.Query): | |
@pygraphy.field | |
def address(self, geo: GeoInput) -> Address: | |
print(geo.string) | |
return Address(latlng=geo.latlng) | |
class Mutation(pygraphy.Object): | |
@pygraphy.field | |
def create_address(self, geo: GeoInput) -> Address: | |
return Address(latlng=geo.latlng) | |
@app.route("/") | |
class Schema(pygraphy.Schema): | |
query: Optional[Query] | |
mutation: Optional[Mutation] | |
if __name__ == "__main__": | |
uvicorn.run(app, host="0.0.0.0", port=8000) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment