Simple card search API for Magic the Gathering.
Tech used: Express, Apollo Server, MongoDB, Mongoose, GraphQL, React, Snowpack, TailwindCSS, Docker Compose.
Pre-reqs: Install Docker (and make sure docker compose is installed)
- Clone the repo
mv client/.env.sample client/.env
- Run
docker-compose up
(initial startup may take a while - wait for client to finish) - In another terminal tab run
npm run seed
to seed the card collection. (it should look something like this)
➜ npm run seed
> [email protected] seed
> docker exec mtg-card-search_mongo mongoimport --db=mtg-search --collection=cards --authenticationDatabase=admin --authenticationMechanism=SCRAM-SHA-256 -u=root -p=somepass --drop --type=csv --headerline --file=/data/seed/cards.csv
2021-04-13T22:56:55.551+0000 connected to: mongodb://localhost/
2021-04-13T22:56:55.555+0000 dropping: mtg-search.cards
2021-04-13T22:56:58.552+0000 [###########.............] mtg-search.cards 24.8MB/53.5MB (46.3%)
2021-04-13T22:57:01.516+0000 [#####################...] mtg-search.cards 48.1MB/53.5MB (89.8%)
2021-04-13T22:57:02.218+0000 [########################] mtg-search.cards 53.5MB/53.5MB (100.0%)
2021-04-13T22:57:02.218+0000 56946 document(s) imported successfully. 0 document(s) failed to import.
- React client frontend can be accessed at: http://localhost:8080
- Apollo GraphQL playground can be accessed at: http://localhost:4000
docker-compose up -d
Spin up express / mongo containers (app stack)
docker-compose down
Spin it down ;)
docker-compose logs -f server
Follow the logs in the server container
docker exec -it mtg-card-search_mongo mongo -u root -p somepass
Drop into the mongo shell in the mongo container
db.getCollection("cards").distinct('setCode')
Get a unique list of all MtG set codes.
Access the GraphQL playground at: http://localhost:4000
Here's some example queries you can run:
query CardSetSearchWithPagination {
pagination: cardPagination(
perPage: 50
page: 11
filter: { _operators: { originalReleaseDate: { exists: true } } }
sort: RARITY_DESC
) {
items {
_id
name
manaCost
rarity
set {
releaseDate
name
code
}
convertedManaCost
colorIdentity
text
scryfallId
}
pageInfo {
itemCount
pageCount
perPage
currentPage
}
}
}
// query
query SearchCards($name: RegExpAsString) {
cardMany(
limit: 10
filter: { _operators: { name: { regex: $name } } }
) {
_id
name
manaCost
rarity
setCode
convertedManaCost
colorIdentity
text
}
}
// Query Variables
{
"name": "/Garruk/i"
}
query {
cardMany(
filter:{
_operators:{
setCode:{
in:["8E"]
}
}
}
limit:10
sort: _ID_DESC
) {
_id
name
manaCost
rarity
setCode
convertedManaCost
colorIdentity
text
type
types
}
}
query Sets {
setMany(
sort: RELEASEDATE_DESC
filter:{
_operators:{
code:{
regex:"/^[0-9]+E.?$/"
}
}
}
) {
name
type
code
releaseDate
}
setCount
}