-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
514 additions
and
1 deletion.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,3 +21,5 @@ dev-env/ | |
/data/ | ||
tmp/ | ||
.task/ | ||
node_modules/ | ||
package-lock.json |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
from pathlib import Path | ||
|
||
from ariadne import ObjectType, QueryType, gql, make_executable_schema | ||
from ariadne.asgi import GraphQL | ||
from starlette.applications import Starlette | ||
from starlette.routing import Mount | ||
|
||
from chii.const import CollectionType | ||
from gql.model import CollectTimeline | ||
|
||
# Define types using Schema Definition Language (https://graphql.org/learn/schema/) | ||
# Wrapping string in gql function provides validation and better error traceback | ||
type_defs = gql( | ||
Path(__file__, "..", "schema.graphql").resolve().read_text(encoding="utf8") | ||
) | ||
|
||
# Map resolver functions to Query fields using QueryType | ||
query = QueryType() | ||
|
||
|
||
# Resolvers are simple python functions | ||
@query.field("timeline_collection") | ||
async def timeline_collection(*_): | ||
return [ | ||
CollectTimeline( | ||
action=CollectionType.wish, subject_name="test", subject_name_cn="test2" | ||
), | ||
] | ||
|
||
|
||
# Map resolver functions to custom type fields using ObjectType | ||
person = ObjectType("CollectTimeline") | ||
|
||
# Create executable GraphQL schema | ||
schema = make_executable_schema(type_defs, query, person) | ||
|
||
app = Starlette( | ||
debug=True, | ||
routes=[ | ||
Mount("/graphql", GraphQL(schema, debug=True)), | ||
], | ||
) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from dataclasses import dataclass | ||
|
||
|
||
@dataclass(kw_only=True) | ||
class CollectTimeline: | ||
action: int | ||
subject_name: str | ||
subject_name_cn: str |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
type Query { | ||
timeline_collection:[CollectTimeline!]! | ||
} | ||
|
||
type CollectTimeline { | ||
action: Int! | ||
subject_name: String! | ||
subject_name_cn: String! | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
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