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 / client.js
Last active March 15, 2018 18:58
Proposal for react-relay-network-modern-ssr package
// client
import { RelayNetworkLayer } from 'react-relay-network-modern';
import RelaySSR from 'react-relay-network-modern-ssr/client';
const relaySSR = new RelaySSR(window.relayData);
const network = new RelayNetworkLayer([
relaySSR.getMiddleware(),
]);
@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 / fixPackageRelayCompiler.1.4.js
Created July 5, 2018 09:34
Add optionalChaining to relay-compiler@1.4.1
/* @flow */
const fs = require('fs');
// Add support for optionalChaining in relay-compiler 1.4
const filename = './node_modules/relay-compiler/bin/relay-compiler';
fs.readFile(filename, 'utf8', (err, data) => {
if (err) {
return console.log(err);
@nodkz
nodkz / component.js
Created August 25, 2018 05:24
Relay: unmask fragment by reading data from store
function itemTrackingHelper(relayContext, item) {
const {title, description} = unmaskFragmentData({
relayContext,
relayData: item,
fragmentPropName: 'item',
fragment: itemTrackingHelperFragment
});
}
const itemTrackingHelperFragment = graphql`
@nodkz
nodkz / LookupQueryRenderer.js
Created December 27, 2017 08:21
Relay.Modern query renderers
/* @flow */
/* eslint-disable no-use-before-define, react/no-unused-prop-types */
import * as React from 'react';
import areEqual from 'fbjs/lib/areEqual';
// forked from https://github.com/robrichard/relay-query-lookup-renderer
// import type { CacheConfig, Disposable } from 'RelayCombinedEnvironmentTypes';
// import type { RelayEnvironmentInterface as ClassicEnvironment } from 'RelayEnvironment';
@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>>;
@nodkz
nodkz / buildNodeImage.js
Created December 8, 2016 14:45
Building `node:slim` docker container with your node_modules via `node:build` container on Mac.
/* eslint-disable no-use-before-define, camelcase */
import cp from 'child_process';
import fsExtra from 'fs-extra';
import hashFiles from 'hash-files';
import chalk from 'chalk';
import {
repositoryName,
rootDir,
buildEnv,
@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 / 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",
}
}