github.com/graphql-go/graphql and github.com/graphql-go/relay provide a
great starting point for creating your own Relay-compliant GraphQL server with Go. Authorization, however, is left up completely to the developer. Here
is how we implemented a /login endpoint and passed the resulting context to the GraphQL Handler.
We’ll leave the handling of these context values within GraphQL to another post…
The loginFunc() function at /login receives the posted request and extracts a username and password from it. ConfirmLogin() is not outlined above,
but is easy enough to implement. In our scenario, we validate the login against our database and return the user or an error.
If the login is valid, we create and return the JWT with our encoded custom claim values (UserID & IsAdmin).
When a request is made to the graphql handler, the requireAuth() middleware parses the JWT, and if valid, passes the (UserID & IsAdmin) variables via context.
The passing of context to GraphQL is explained in this post.
Go’s “net/http” package provides great out of the box server capabilites with extensible middleware. In order to leverage http middleware in combination with the “github.com/graphql-go/graphql” package, we needed to pass the http.Request.Context() to the graphql handler. Here is how we did so:
The AddContext() function is taking the standard http.Request.Context() and supplementing it with our additonal “authContext” map. This Context is then passed to the graphqlHandlerFunc where we setup a new GraphQL instance with the Context initialized to http.Request.Context().
This way, we can access these values within our GraphQL objects.
In continuation of last year’s reading list, here is my second-annual reading list. I finally made the switch over to Goodreads, so I don’t have to do this from memory this time! As usual, there’s an eclectic mix of genres.
In alphabetical order by title…
1Q84 (1Q84, #1-3) by Haruki Murakami
American Lion: Andrew Jackson in the White House by Jon Meacham
American Sniper: The Autobiography of the Most Lethal Sniper in U.S. Military History by Chris Kyle
Brain Maker: The Power of Gut Microbes to Heal and Protect Your Brain–for Life by David Perlmutter
Broken Windows, Broken Business: How the Smallest Remedies Reap the Biggest Rewards by Michael Levine
Crossing to Safety by Wallace Stegner
Dad Is Fat by Jim Gaffigan
Dead Wake: The Last Crossing of the Lusitania by Erik Larson
Freedom by Jonathan Franzen
Go Set a Watchman by Harper Lee
Growth Hacker Marketing: A Primer on the Future of PR, Marketing, and Advertising by Ryan Holiday
Heaven is for Real: A Little Boy’s Astounding Story of His Trip to Heaven and Back by Todd Burpo
Hooked: How to Build Habit-Forming Products by Nir Eyal
Hyperbole and a Half by Allie Brosh
I Am Malala: The Girl Who Stood Up for Education and Was Shot by the Taliban by Malala Yousafzai
In the Garden of Beasts: Love, Terror, and an American Family in Hitler’s Berlin by Erik Larson
In the Plex: How Google Thinks, Works, and Shapes Our Lives by Steven Levy
John Adams by David McCullough
Les Misérables by Victor Hugo
Let’s Explore Diabetes with Owls by David Sedaris
Liar’s Poker by Michael Lewis
Maude by Donna Mabry
Missoula: Rape and the Justice System in a College Town by Jon Krakauer
Not My Father’s Son: A Memoir by Alan Cumming
Pearl Buck’s the Good Earth by Pearl S. Buck
Post Office by Charles Bukowski
Rob Delaney: Mother. Wife. Sister. Human. Warrior. Falcon. Yardstick. Turban. Cabbage. by Rob Delaney
Shakespeare Saved My Life: Ten Years in Solitary with the Bard by Laura Bates
Steve Jobs by Walter Isaacson
Tales of the Jazz Age (F. Scott Fitzgerald Classic) by F. Scott Fitzgerald
The Art of Living: The Classical Manual on Virtue, Happiness and Effectiveness by Epictetus
The Atlantis Gene (The Origin Mystery, #1) by A.G. Riddle
The Atlantis Plague (The Origin Mystery, #2) by A.G. Riddle
The Atlantis World (The Origin Mystery, #3) by A.G. Riddle
The Autobiography of Malcolm X by Malcolm X
The Bell Tolls for No One by Charles Bukowski
The Blessing of a Skinned Knee: Using Jewish Teachings to Raise Self-Reliant Children by Wendy Mogel
The Book Thief by Markus Zusak
The Boy Who Harnessed the Wind: Creating Currents of Electricity and Hope by William Kamkwamba
The Corrections by Jonathan Franzen
The Cryptographer’s Way by Dr. Bradford Hardie III
The Grand Design by Stephen Hawking
The Life and Times of the Thunderbolt Kid by Bill Bryson
The Life Changing Magic of Tidying Up by Marie Kondō
The Lost City of Z: A Tale of Deadly Obsession in the Amazon by David Grann
The Martian by Andy Weir
The Miracle Morning: The Not-So-Obvious Secret Guaranteed to Transform Your Life (Before 8AM) by Hal Elrod
The Pearl by John Steinbeck
The Signal and the Noise: Why So Many Predictions Fail - But Some Don’t by Nate Silver
Things Fall Apart (The African Trilogy, #1) by Chinua Achebe
Three Weeks With My Brother by Nicholas Sparks
Trust Me, I’m Lying: Confessions of a Media Manipulator by Ryan Holiday
Twenty Thousand Leagues Under the Sea by Jules Verne
We Are Not Ourselves by Matthew Thomas
When to Rob a Bank by Steven D. Levitt
Where the Red Fern Grows by Wilson Rawls
Wild: From Lost to Found on the Pacific Crest Trail by Cheryl Strayed
Wool by Hugh Howey Omnibus Edition (Books 1-5 of the Silo Series) l Summary & Study Guide by BookRags
Yes Please by Amy Poehler
Zealot: The Life and Times of Jesus of Nazareth by Reza Aslan
Zero to One: Notes on Startups, or How to Build the Future by Peter Thiel
When recently doing some last minute Christmas shopping on Amazon, I was presented with a suggestion to check out the Coin 2.0, with surprisingly positive average customer reviews (4 stars visually). I had been a supporter of the Coin Kickstarter campaign the first go-around, but canceled after numerous delays and poor reviews on the beta versions.
At quick glance, I found that all of the featured reviews in the main area and on the sidebar where largely negative. Then I looked at the Customer Reviews graph, and saw that the following breakdown:
5 star: 32%
4 star: 12%
3 star: 7%
2 star: 19%
1 star: 30%
This didn’t look like it averaged out to 4 stars, so I quickly ran the numbers. The actual average was under 3 stars (2.97)!
I did some quick research, and found that Amazon had recently changed their formula to provide more weight to “newer, more helpful and verified customer reviews” link.
Sorting the reviews by both “most helpful” and “most recent”, I found both to largely be weighted towards negative (3 stars or less) as well.
After a quick search, I couldn’t find any specifics on Amazon’s “Machine Learning Algorithm.” I’m not sure what’s going on here, and I’m generally a fan of Amazon, but this seems a little disingenuous. Thoughts?