From 7f7c595357a5f788a32f5ecab8cc49f303cc4431 Mon Sep 17 00:00:00 2001 From: Gagan Deep Date: Sun, 2 Oct 2022 20:05:08 +0530 Subject: [PATCH 1/3] initial commit --- app/api/graphql/__init__.py | 0 app/api/graphql/app.py | 16 ++++++++++++++++ app/api/graphql/mutations/__init__.py | 0 app/api/graphql/queries/__init__.py | 0 app/api/graphql/queries/query.py | 10 ++++++++++ app/api/graphql/types/__init__.py | 0 app/api/graphql/types/type.py | 7 +++++++ app/api/schema/__init__.py | 1 + pyproject.toml | 2 +- 9 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 app/api/graphql/__init__.py create mode 100644 app/api/graphql/app.py create mode 100644 app/api/graphql/mutations/__init__.py create mode 100644 app/api/graphql/queries/__init__.py create mode 100644 app/api/graphql/queries/query.py create mode 100644 app/api/graphql/types/__init__.py create mode 100644 app/api/graphql/types/type.py create mode 100644 app/api/schema/__init__.py diff --git a/app/api/graphql/__init__.py b/app/api/graphql/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/app/api/graphql/app.py b/app/api/graphql/app.py new file mode 100644 index 0000000..436b410 --- /dev/null +++ b/app/api/graphql/app.py @@ -0,0 +1,16 @@ +import strawberry + +from fastapi import FastAPI + +from strawberry.asgi import GraphQL + +from ..graphql.schema.queries import query + +schema = strawberry.Schema(query= query) + + +graphql_app = GraphQL(schema) + +app = FastAPI() + +app.include_router(graphql_app, prefix="/graphql") \ No newline at end of file diff --git a/app/api/graphql/mutations/__init__.py b/app/api/graphql/mutations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/app/api/graphql/queries/__init__.py b/app/api/graphql/queries/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/app/api/graphql/queries/query.py b/app/api/graphql/queries/query.py new file mode 100644 index 0000000..ecd5b4d --- /dev/null +++ b/app/api/graphql/queries/query.py @@ -0,0 +1,10 @@ + +import strawberry + +from ..types.type import User + +@strawberry.type +class Query: + @strawberry.field + def user(self) -> User: + return User(name="Patrick", age=100) \ No newline at end of file diff --git a/app/api/graphql/types/__init__.py b/app/api/graphql/types/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/app/api/graphql/types/type.py b/app/api/graphql/types/type.py new file mode 100644 index 0000000..1c8039e --- /dev/null +++ b/app/api/graphql/types/type.py @@ -0,0 +1,7 @@ +import strawberry + +@strawberry.type + +class User: + name: str + age: int \ No newline at end of file diff --git a/app/api/schema/__init__.py b/app/api/schema/__init__.py new file mode 100644 index 0000000..9e2221d --- /dev/null +++ b/app/api/schema/__init__.py @@ -0,0 +1 @@ +from .types import User \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index 08ff4db..ff824cf 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -20,7 +20,7 @@ python-jose = "^3.3.0" passlib = "^1.7.4" bcrypt = "^3.2.0" python-multipart = "^0.0.5" - +strawberry-graphql = "^0.92.2" [tool.poetry.dev-dependencies] black = "21.7b0" From c203ca20d9d39f04530d93b336bf398b884d0fdd Mon Sep 17 00:00:00 2001 From: Gagan Deep Date: Tue, 4 Oct 2022 12:50:07 +0530 Subject: [PATCH 2/3] graphql support added --- app/api/graphql-demo/README.md | 1 + app/api/graphql-demo/__init__.py | 0 app/api/graphql-demo/schema.py | 22 ++++++++++++++++++++++ pyproject.toml | 1 - 4 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 app/api/graphql-demo/README.md create mode 100644 app/api/graphql-demo/__init__.py create mode 100644 app/api/graphql-demo/schema.py diff --git a/app/api/graphql-demo/README.md b/app/api/graphql-demo/README.md new file mode 100644 index 0000000..a153e4d --- /dev/null +++ b/app/api/graphql-demo/README.md @@ -0,0 +1 @@ +https://strawberry.rocks/docs \ No newline at end of file diff --git a/app/api/graphql-demo/__init__.py b/app/api/graphql-demo/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/app/api/graphql-demo/schema.py b/app/api/graphql-demo/schema.py new file mode 100644 index 0000000..fc59c96 --- /dev/null +++ b/app/api/graphql-demo/schema.py @@ -0,0 +1,22 @@ +import typing +import strawberry + +def get_books(): + return [ + Book( + title='The Great Gatsby', + author='F. Scott Fitzgerald', + ), + ] + +@strawberry.type +class Book: + title: str + author: str + +@strawberry.type +class Query: + books: typing.List[Book] = strawberry.field(resolver=get_books) + + +schema = strawberry.Schema(query=Query) diff --git a/pyproject.toml b/pyproject.toml index ff824cf..36ce802 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -20,7 +20,6 @@ python-jose = "^3.3.0" passlib = "^1.7.4" bcrypt = "^3.2.0" python-multipart = "^0.0.5" -strawberry-graphql = "^0.92.2" [tool.poetry.dev-dependencies] black = "21.7b0" From 799964d03675121cf9f6c07a264920b628c19519 Mon Sep 17 00:00:00 2001 From: Gagan Deep Date: Tue, 4 Oct 2022 12:53:27 +0530 Subject: [PATCH 3/3] unnecessary files removed --- app/api/graphql/__init__.py | 0 app/api/graphql/app.py | 16 ---------------- app/api/graphql/mutations/__init__.py | 0 app/api/graphql/queries/__init__.py | 0 app/api/graphql/queries/query.py | 10 ---------- app/api/graphql/types/__init__.py | 0 app/api/graphql/types/type.py | 7 ------- app/api/schema/__init__.py | 1 - pyproject.toml | 1 + 9 files changed, 1 insertion(+), 34 deletions(-) delete mode 100644 app/api/graphql/__init__.py delete mode 100644 app/api/graphql/app.py delete mode 100644 app/api/graphql/mutations/__init__.py delete mode 100644 app/api/graphql/queries/__init__.py delete mode 100644 app/api/graphql/queries/query.py delete mode 100644 app/api/graphql/types/__init__.py delete mode 100644 app/api/graphql/types/type.py delete mode 100644 app/api/schema/__init__.py diff --git a/app/api/graphql/__init__.py b/app/api/graphql/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/app/api/graphql/app.py b/app/api/graphql/app.py deleted file mode 100644 index 436b410..0000000 --- a/app/api/graphql/app.py +++ /dev/null @@ -1,16 +0,0 @@ -import strawberry - -from fastapi import FastAPI - -from strawberry.asgi import GraphQL - -from ..graphql.schema.queries import query - -schema = strawberry.Schema(query= query) - - -graphql_app = GraphQL(schema) - -app = FastAPI() - -app.include_router(graphql_app, prefix="/graphql") \ No newline at end of file diff --git a/app/api/graphql/mutations/__init__.py b/app/api/graphql/mutations/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/app/api/graphql/queries/__init__.py b/app/api/graphql/queries/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/app/api/graphql/queries/query.py b/app/api/graphql/queries/query.py deleted file mode 100644 index ecd5b4d..0000000 --- a/app/api/graphql/queries/query.py +++ /dev/null @@ -1,10 +0,0 @@ - -import strawberry - -from ..types.type import User - -@strawberry.type -class Query: - @strawberry.field - def user(self) -> User: - return User(name="Patrick", age=100) \ No newline at end of file diff --git a/app/api/graphql/types/__init__.py b/app/api/graphql/types/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/app/api/graphql/types/type.py b/app/api/graphql/types/type.py deleted file mode 100644 index 1c8039e..0000000 --- a/app/api/graphql/types/type.py +++ /dev/null @@ -1,7 +0,0 @@ -import strawberry - -@strawberry.type - -class User: - name: str - age: int \ No newline at end of file diff --git a/app/api/schema/__init__.py b/app/api/schema/__init__.py deleted file mode 100644 index 9e2221d..0000000 --- a/app/api/schema/__init__.py +++ /dev/null @@ -1 +0,0 @@ -from .types import User \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index 36ce802..08ff4db 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -21,6 +21,7 @@ passlib = "^1.7.4" bcrypt = "^3.2.0" python-multipart = "^0.0.5" + [tool.poetry.dev-dependencies] black = "21.7b0" mkdocs = "^1"