This is my solution for the 2019 Shopify Dev Challenge. The solution is written in GO using graphQL, and mySQL for the database
Requirements:
- Go
- MySQL
- Download the project into your $GOPATH/src directory and run setup.sh to install all of the go dependencies
- Configure the MySQL connection information for your testing environment
- Run the attached SQL scripts in your database terminal to set up the required tables
- Generate self signed keys for TLS in the project folder:
$ openssl genrsa -out server.key 2048
$ openssl ecparam -genkey -name secp384r1 -out server.key
$ openssl req -new -x509 -sha256 -key server.key -out server.crt -days 3650
openssl genrsa -out server.key 2048
- Run main.go and the server will be listening at https://localhost:4000/
$ sh setup.sh
$ go build main.go
To test use Postman or your API testing app of choice.
- Certs used for TLS are self-signed so settings may need to be adjusted
- Use a GET request directed at https://localhost:4000/generate-jwt to retrieve a JWT for authenticating API requests
- POST query with the JWT set as the bearer token to https://localhost:4000/go-graphql
POST Formatting:
{
"request": "type{Field(parameters){return values}}"
}
Example post requests:
# Return products that are in stock
{
"request": "query{GetProducts(InStock:true){id, title, price, inventorycount}}"
}
# Return products with CPU int title
{
"request": "query{GetProducts(Title:\"CPU\"){id, title, price, inventorycount}}"
}
# Return products with title CPU that are in stock
{
"request": "query{GetProducts(Title:\"CPU\",InStock:true){id, title, price, inventorycount}}"
}
# Return contents of Cart 1
{
"request": "query{GetCartContents(CartID:1){productid, title, price}}"
}
# Add Item with ID 2 to Cart 1
{
"request": "mutation{AddToCart: AddToCart(CartID:1,ItemID:2)}"
}
# Check out cart with ID 1
{
"request": "mutation{CheckOut(CartID:1)}"
}