Skip to content

Instantly share code, notes, and snippets.

View nodkz's full-sized avatar

Paul Damnhorns nodkz

View GitHub Profile
// __IS_SERVER__ declared via Webpack globals
// const __IS_SERVER__ = typeof process === 'object' && process + '' === '[object process]';
if (__IS_SERVER__) {
const RRNL = require('react-relay-network-modern/node8'); // eslint-disable-line
const graphql = require('graphql').graphql; // eslint-disable-line
const schema = require('schema').default; // eslint-disable-line
return new RRNL.RelayNetworkLayer([
RRNL.cacheMiddleware({
size: 100,
ttl: 900000,
@nodkz
nodkz / package.json
Created November 20, 2017 10:15
Ram disk via scripts
{
"scripts": {
"ram": "yarn ram-check-disk && yarn ram-create-disk && yarn ram-link-node-modules && yarn ram-link-build && yarn install && yarn start",
"ram-check-disk": "[ -d /Volumes/npm_ram_disk ] && echo 'Disk already mounted!' && yarn build && exit 1 || exit 0",
"ram-create-disk": "diskutil erasevolume hfsx npm_ram_disk `hdiutil attach -nomount ram://1600000`",
"ram-link-node-modules": "mkdir /Volumes/npm_ram_disk/node_modules && rm -r -f ./node_modules && ln -s /Volumes/npm_ram_disk/node_modules ./node_modules",
"ram-link-build": "mkdir /Volumes/npm_ram_disk/build && rm -r -f ./build && ln -s /Volumes/npm_ram_disk/build ./build",
}
}
@nodkz
nodkz / user.js
Created November 8, 2017 13:28
Mongoose with flow example
/* @flow */
/* eslint-disable func-names */
import { Schema } from 'mongoose';
import DB from 'schema/db';
import composeWithMongoose from 'graphql-compose-mongoose';
import composeWithRelay from 'graphql-compose-relay';
import crypto from 'crypto';
import bcrypt from 'bcrypt';
import type { $Request } from 'express';
@nodkz
nodkz / react-relay_vx.x.x.js
Created October 18, 2017 14:31
react-relay flowtype declaration
import * as React from "react";
declare class RelayComponentClass<Props> extends React$Component<Props, any> {
static getFragment: Function;
};
declare type createFragmentContainer = <TBase>(
Component: Class<React$Component<TBase, any>> | (props: TBase) => React.Node,
fragmentSpec: any
) => Class<RelayComponentClass<TBase>>;
[ignore]
.*/build/.*
.*/tools/.*
.*/node_modules/.*/test/.*
.*/node_modules/.*/tests/.*
.*/node_modules/ajv.*
.*/node_modules/acorn.*
.*/node_modules/async.*
.*/node_modules/babel.*
.*/node_modules/bluebird.*
@nodkz
nodkz / mongoose.flowtype.js
Last active June 16, 2018 20:55
Covering mongoose models with flowtype
/* @flow */
/* eslint-disable */
import mongoose from 'mongoose';
export type MongoId = typeof mongoose.Types.ObjectId | {
toString(): string,
};
export type MongoOrScalarId = MongoId | string | number;
@nodkz
nodkz / .babelrc.js
Last active March 25, 2024 16:16
Babel 7.0 with .babelrc.js DEPRECATED! This config was created when babel 7 was in beta
/* eslint-disable prefer-template */
const path = require('path');
const aliases = require('./aliases');
// ///////////////////////////////////////////////////////////////
// ////////////////// PLUGINS ////////////////////////////////
// ///////////////////////////////////////////////////////////////
const commonPlugins = [
@nodkz
nodkz / server.js
Created February 7, 2017 08:09
Sentry/raven manual config
import path from 'path';
import express from 'express';
import { merge } from 'lodash';
import graphqlHTTP from 'express-graphql';
import PrettyError from 'pretty-error';
import expressHttpProxy from 'express-http-proxy';
import bodyParser from 'body-parser';
import raven from 'raven';
import morgan from 'morgan';
import { PORT, PUBLIC_URL } from 'config';
@nodkz
nodkz / apolloServer2019.ts
Last active August 3, 2022 11:17
GraphQL error tracking with sentry.io (ApolloServer 2019)
import express from 'express';
import { ApolloServer } from 'apollo-server-express';
import { ApolloServerPlugin } from 'apollo-server-plugin-base';
import * as Sentry from '@sentry/node';
Sentry.init({
environment: process.env.APP_ENV,
// see why we use APP_NAME here: https://github.com/getsentry/sentry-cli/issues/482
release: `${process.env.APP_NAME}-${process.env.APP_REVISION}` || '0.0.1',
dsn: process.env.SENTRY_DSN,
@nodkz
nodkz / relayStore.js
Last active June 29, 2017 01:30
relayStore with `reset` and simplified `mutate` methods
let relayStore;
function relayCreateStore() {
const env = new Relay.Environment();
env.injectNetworkLayer(new Relay.DefaultNetworkLayer('/graphql'));
if (__DEV__) {
RelayNetworkDebug.init(env);
}
env.reset = () => relayCreateStore();
env.mutate = ({
query,