Skip to content

Instantly share code, notes, and snippets.

Jordan Last lastmjs

Block or report user

Report or block lastmjs

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
lastmjs /
Last active Aug 25, 2019
Full Stack Mentor - Candidate Assessment


Hey Student,

Oh dear, this is a tricky one. It's definitely messed me up in the past. What's happening here is an issue of scoping and closures. A few things to point you in the right direction:

  1. Study block scoping versus function scoping in JavaScript
  2. Study JavaScript's variable declarators, var, let, and const, and understand the differences between their uses
  3. Study up a bit on closures in JavaScript
  4. With your new knowledge, try to make btnNum block scoped instead of function scoped
View ultimate-schema.ts
const ultimateSchemaString = mergeTypes([
], {
all: true
const ultimateSchema = makeExecutableSchema({
typeDefs: ultimateSchemaString,
View directives.graphql
directive @userOwns(field: String) on FIELD | FIELD_DEFINITION
directive @authenticated on FIELD | FIELD_DEFINITION
directive @private on FIELD | FIELD_DEFINITION
View dataops.graphql
# This is where we define any custom resolvers, and where we add custom directives to any generated Prisma resolvers
type AuthPayload {
token: String!
user: User!
type Mutation {
# Custom resolvers
signup(email: String!, password: String!): AuthPayload!
View datamodel.graphql
# All types defined here will be fed through the Prisma generation process
# Essentially, all of these types become database tables
type User {
id: ID! @unique
createdAt: DateTime! @private
updatedAt: DateTime! @private
email: String! @unique @userOwns(field: "id")
password: String! @private
View private-directive-resolver.ts
export async function privateDirectiveResolver(next, source, args, context) {
throw new Error('Private');
View authenticated-directive-resolver.ts
export async function authenticatedDirectiveResolver(next, source, args, context) {
if (getUserId(context)) {
return await next();
else {
throw new Error('Not authenticated');
View user-owns-directive-resolver.ts
export async function userOwnsDirectiveResolver(next, source, args, context) {
if (source[args.field] === await getUserId(context)) {
return await next();
else {
throw new Error('Not authorized');
View directive-resolvers.ts
const directiveResolvers = {
userOwns: userOwnsDirectiveResolver,
authenticated: authenticatedDirectiveResolver,
private: privateDirectiveResolver
View resolvers.ts
const resolvers = {
Query: {
Mutation: {
signup: signupResolver,
login: loginResolver
You can’t perform that action at this time.