Skip to content

Commit

Permalink
In Ark GraphQL API, expose field returning all the cards (#447)
Browse files Browse the repository at this point in the history
  • Loading branch information
shaldengeki authored Aug 29, 2024
1 parent f2128f2 commit 7da57ec
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 2 additions & 0 deletions ark_nova_stats/api/gql/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from ark_nova_stats.api.gql.types.game_log import (
fetch_card_field,
fetch_cards_field,
fetch_user_field,
game_log_field,
game_logs_field,
Expand All @@ -27,6 +28,7 @@ def Schema(app: flask.Flask):
"stats": stats_field(GameLog, User),
"user": fetch_user_field(User),
"card": fetch_card_field(Card),
"cards": fetch_cards_field(Card),
},
),
mutation=GraphQLObjectType(
Expand Down
17 changes: 16 additions & 1 deletion ark_nova_stats/api/gql/types/game_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
GraphQLObjectType,
GraphQLString,
)
from sqlalchemy import desc
from sqlalchemy import asc, desc

from ark_nova_stats.bga_log_parser.game_log import GameLog as ParsedGameLog
from ark_nova_stats.config import app, db
Expand Down Expand Up @@ -532,3 +532,18 @@ def fetch_card_field(
args=fetch_card_filters,
resolve=lambda root, info, **args: fetch_card(card_model, args),
)


def fetch_cards(card_model: Type[CardModel]) -> list[CardModel]:
return card_model.query.order_by(asc(card_model.name)).all()


def fetch_cards_field(
card_model: Type[CardModel],
) -> GraphQLField:
return GraphQLField(
GraphQLNonNull(GraphQLList(card_type)),
description="List cards.",
args={},
resolve=lambda root, info, **args: fetch_cards(card_model),
)

0 comments on commit 7da57ec

Please sign in to comment.