Skip to content

Instantly share code, notes, and snippets.

View RyanCCollins's full-sized avatar

Ryan Collins RyanCCollins

View GitHub Profile
// From server/graph/queries/post/posts.ts
import {
GraphQLList,
} from 'graphql';
import types from '../../types';
import PostModel from '../../../db/models/post';
export default {
type: new GraphQLList(types.postType),
import {
GraphQLInputObjectType,
GraphQLString,
GraphQLID,
GraphQLNonNull,
} from 'graphql';
export default new GraphQLInputObjectType({
name: 'CommentInput',
fields: () => ({
// Comment Model Schema and related GraphQL Schema
// From /server/db/models/comment.ts
import mongoose from 'mongoose';
const CommentSchema = new mongoose.Schema({
author: String,
body: String,
post: {
type: String,
ref: 'Post',
import * as React from 'react';
import { ApolloClient, createNetworkInterface } from 'apollo-client';
import { renderToString, renderToStaticMarkup } from 'react-dom/server';
import { match, RouterContext } from 'react-router';
import morgan from 'morgan';
import express from 'express';
import compression from 'compression';
import path from 'path';
import { ApolloProvider } from 'react-apollo';
import store from '../client/store';
import 'babel-polyfill';
import path from 'path';
import fs from 'fs';
import * as express from 'express';
import { graphql } from 'graphql';
import { introspectionQuery } from 'graphql/utilities';
import bodyParser from 'body-parser';
import cors from 'cors';
import { graphiqlExpress, graphqlExpress } from 'graphql-server-express';
import schema from './graph';
/* @flow */
type Maybe<T,U> = (pattern: {
some(x: T): U;
none(): U;
}) => U;
function map<A,B,C>(maybe: Maybe<A,C>, f: (a: A) => B): Maybe<B,C> {
return function(pattern) {
return maybe({
@RyanCCollins
RyanCCollins / typescript-union-types.ts
Last active January 5, 2017 05:36
TypeScript Union Types
type FeedbackAction = 'FEEDBACK_SUBMISSION_INITIATION' | 'FEEDBACK_SUBMISSION_MESSAGE' | 'FEEDBACK_SUBMISSION_ERROR'; // etc. etc.
interface IAction<P> {
type: FeedbackAction;
payload: P;
};
interface IFeedbackState {
error: Error;
message: string;
@RyanCCollins
RyanCCollins / model.elm
Created January 5, 2017 03:59
Elm reducer / union type example
type alias Model =
{ error: Maybe String
, message: Maybe String
, isSubmitting: Bool
}
type alias Error =
{ message: String }
type Msg
@RyanCCollins
RyanCCollins / reducer-example.js
Created January 5, 2017 03:47
Reducer example
export const initialState = {
error: null,
message: null,
isSubmitting: false,
modal: {
isVisible: false,
},
};
const feedbackReducer =

Functional Programming in JS

Identity functor

const Identity = x => ({
  map: f => Identity(f(x)),
  fold: f => f(x),
  inspect: () => `Identity(${x})`
});