Skip to content

Instantly share code, notes, and snippets.

@chiaki64
Created November 12, 2019 08:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chiaki64/049fb402d2f1bb46139daf60a9d874bf to your computer and use it in GitHub Desktop.
Save chiaki64/049fb402d2f1bb46139daf60a9d874bf to your computer and use it in GitHub Desktop.
pygraphy test code
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