(Work-in-progress) GraphQL server written in Rust.
This project aims to provide a Relay-compliant GraphQL server that models all cards in the Transformers Trading Card Game as well-defined entities.
The Transformers TCG is an interesting thing to model because the game is still fairly new, yet is very dynamic due to the different types of cards and the variations of data they provide.
This list is likely to change as I explore and improve on this project:
Server:
- rust!
- async-graphql
- sqlx - custom fork for my user-defined types right now
- tide
- postgres
Client:
This project uses Auth0 for OAuth2 authentication and JWT creation/validation.
Please follow our Setting up Auth0 guide before trying to set up the server.
You'll need the Rust toolchain and Postgres installed on your computer.
- Make sure you have Postgres running and copy the
.env.example
to.env
with theDATABASE_URL
pointing to your local database. - Install the
cargo sqlx
command usingcargo install --git git://github.com/phated/sqlx --branch custom-types-040 sqlx-cli
- Create the database using
cargo sqlx database create
- Migrate the new database using
cargo sqlx migrate run
- Build and start the server with
cargo run
You'll need Node.js and Yarn installed on your computer.
- Get the JWT from a logged in GraphiQL session, by navigating to
localhost:3000/login
and then grabbing the token after "Bearer" under "HTTP Headers" once redirected to the GraphiQL interface. - Add the token to your
.env
file asAUTH_TOKEN
- Fetch the Node dependencies using
yarn
command - Then seed the database with
yarn seed
You can test the newly seeded data with the built-in playground.
Open your browser to localhost:3000
and start exploring the schema and issuing requests!
Here is an example of a valid query (with full Relay
support) that you can send to this server.
query {
allCards {
pageInfo {
hasPreviousPage
hasNextPage
startCursor
endCursor
}
edges {
node {
... on Node {
id
}
... on Card {
tcgId
rarity
number
category
wave {
... on Node {
id
}
tcgId
name
released
}
}
... on CharacterCard {
modes {
title
faction
stars
type
... on AltMode {
subtitle
traits
health
attack
defense
}
... on BotMode {
subtitle
traits
health
attack
defense
}
}
}
... on BattleCard {
title
stars
faction
icons
attackModifier
defenseModifier
}
}
}
}
}