Created
November 11, 2019 03:54
-
-
Save chiaki64/e5168279926f0cadeacba59f78c5eb2c to your computer and use it in GitHub Desktop.
Introspection
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
""" | |
@Author: Kuonji Chiaki | |
@Data: 2019/11/11 11:49 | |
""" | |
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 | |
@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: | |
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