Skip to content

Instantly share code, notes, and snippets.

Avatar
🎯
Focusing

Ryan Collins RyanCCollins

🎯
Focusing
View GitHub Profile
View post-query.ts
// 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),
View comment-input-type.ts
import {
GraphQLInputObjectType,
GraphQLString,
GraphQLID,
GraphQLNonNull,
} from 'graphql';
export default new GraphQLInputObjectType({
name: 'CommentInput',
fields: () => ({
View comment-schema.ts
// 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',
View express-app.ts
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';
View graphQLEntry.ts
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';
View gist:bf6d44a7aa22661a729b7dc9e82431f3
/* @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({
View typescript-union-types.ts
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 Jan 5, 2017
Elm reducer / union type example
View model.elm
type alias Model =
{ error: Maybe String
, message: Maybe String
, isSubmitting: Bool
}
type alias Error =
{ message: String }
type Msg
View reducer-example.js
export const initialState = {
error: null,
message: null,
isSubmitting: false,
modal: {
isVisible: false,
},
};
const feedbackReducer =
View functional-js-notes.md

Functional Programming in JS

Identity functor

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