Skip to content

Instantly share code, notes, and snippets.

View apostopher's full-sized avatar

Rahul Devaskar apostopher

View GitHub Profile
@apostopher
apostopher / machine.js
Created April 20, 2021 03:41
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
@apostopher
apostopher / machine.js
Created November 18, 2020 11:27
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
@apostopher
apostopher / machine.js
Last active November 17, 2020 09:57
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
@apostopher
apostopher / machine.js
Last active May 3, 2020 01:26
Generated by XState Viz: https://xstate.js.org/viz
const receiptMachine = Machine(
{
key: 'ReceiptMachine',
initial: 'initializing',
states: {
idle: {
on: {
purchase: 'purchasing',
},
},
@apostopher
apostopher / server.js
Created November 14, 2018 14:35
API server using graphql-yoga
import { GraphQLServer } from 'graphql-yoga'
// Import the resolvers
import resolvers from 'src/resolvers'
// Import our custom directive
import isAuthenticated from 'src/isAuthenticated'
const server = new GraphQLServer({
typeDefs: `${__dirname}/schema.graphql`,
@apostopher
apostopher / isAuthenticated.js
Created November 14, 2018 14:10
isAuthenticated Directive
import { SchemaDirectiveVisitor } from 'graphql-tools'
export function authenticate(resolver, { strict = true } = {}) {
return async (source, args, context, info) => {
const { req } = context
const token = getTokenFromReq(req)
try {
const currentUser = await context.loadUserFromToken(token)
context.currentUser = currentUser
context.authToken = token
@apostopher
apostopher / schema.graphql
Last active November 14, 2018 14:32
GraphQL schema
directive @isAuthenticated(strict: Boolean) on FIELD_DEFINITION
type Post {
title: String!
body: String!
}
type Query {
getPosts: [Post]
}

Keybase proof

I hereby claim:

  • I am apostopher on github.
  • I am apostopher (https://keybase.io/apostopher) on keybase.
  • I have a public key ASBLlA8h4HbMcfMCjTXL8iLttirhstwSS2-Dh2-KcDRSzQo

To claim this, I am signing this object:

@apostopher
apostopher / relayGlobalID.js
Created September 19, 2017 14:32
Relay global id input type
import { GraphQLNonNull } from 'graphql';
import { fromGlobalId } from 'graphql-relay';
export const RelayGlobalID = new GraphQLScalarType({
name: 'RelayGlobalID',
description: 'The RelayGlobalID scalar type represents a globalIdField in relay.',
serialize(value) {
return value;
},
parseValue(value) {
# These are my notes from the PragProg book on CoffeeScript of things that either
# aren't in the main CS language reference or I didn't pick them up there. I wrote
# them down before I forgot, and put it here for others but mainly as a reference for
# myself.
# assign arguments in constructor to properties of the same name:
class Thingie
constructor: (@name, @url) ->
# is the same as: