This repo consists of the source code for a recruitment task for Shopify's Backend Engineer Intern position.
Summer 2019 Developer Intern Challenge Question
My plan was to create a GraphQL API with cart functionality with well-written code.
- At first, I wrote on a sheet of paper queries, mutations and types I’d need for such API.
- Initially, I wanted to give Prisma with TypeScript a try (never used that), but after few hours of fighting with Docker I gave up, I had some hardware problem.
- I chose Go for this, I have some experience with Go.
- I started with writing domain structures (that is models/entities - purchase, product, etc.).
- Then I proceeded to writing first working resolver, for all products.
- After writing the rest of queries and mutation for purchasing single product I refactored some of the code to be more abstract and because of that more testable and universal.
- I began doing extra credit, I solved cart authorization using JWT. When creating a cart, you got a JWT with cart id in claims in response which you have to submit in
Authorization
header when you are dealing with cart endpoints.
You can use one of the prebuilt binaries in the Releases section or build it yourself using instruction below.
After first run, you can edit config.ini
file and then re-run program with new settings. You probably also want to populate the products
SQL table with some content.
- Go 1.10.3+
- dep dependency manager
- GCC for compiling SQLite driver (not sure if it's needed)
- Clone GitHub repository
- Download all dependencies by
dep ensure
- You are ready to build!
go build main.go
List of queries and mutations can be found in schema.graphql file which describes it best (it's the actual schema).
showCart
, addToCart
and checkoutCart
resolvers need a JWT token submitted in Authorization
header in order to work. You can acquire this token from createCart
query.