Skip to content

Instantly share code, notes, and snippets.

View JeffML's full-sized avatar
🏠
Barely working

Jeff Lowery JeffML

🏠
Barely working
View GitHub Profile
@JeffML
JeffML / authorOps.js
Created November 26, 2017 17:24
Resolver code for AuthorOps
const addBook = (book, authorId) => {
console.log("addBook", book, authorId)
return new Promise((resolve, reject) => {
book.authorId = authorId
books.push(book)
resolve(books.length)
})
}
const removeBook = (book, authorId) => {
@JeffML
JeffML / UCI_state
Created April 8, 2018 04:51
UCI state example
GUI engine
// tell the engine to switch to UCI mode
uci
// engine identify
id name Shredder
id author Stefan MK
// engine sends the options it can change
@JeffML
JeffML / query_async_schema.js
Created April 8, 2018 17:15
A simple schema and resolver for demonstrating parallel vs sequential execution
import {makeExecutableSchema} from 'graphql-tools';
const typeDefs = `
type Query {
message(id: ID!): String!
}
type Mutation {
message(id: ID!): String!
}
import React from "react";
import { Query } from 'react-apollo';
import gql from "graphql-tag";
const query = gql`{
currencyOfInterest @client
}`
const ExchangeSelector = ({data: {rates}}) => (
<Query query={query}>
import React from 'react';
import logo from './logo.svg';
import './App.css';
import { ApolloProvider } from "react-apollo";
import ApolloClient from "apollo-boost";
const client = new ApolloClient({
uri: "https://w5xlvm3vzz.lp.gql.zone/graphql"
});
const App = () => (
<ApolloProvider client={client}>
import React from "react"
import { Query } from "react-apollo";
import gql from "graphql-tag";
const ExchangeRates = () => (
<Query
query={gql`
{
rates(currency: "USD") {
currency
rate
const log = (target, name, descriptor) => {
/*
target: the class instance of the method
name: the name of the method
descriptor:
value: the method itself
*/
const original = descriptor.value; // hold onto the original function
class MyClass {
@log
sum(a, b) {
return a + b;
}
}
const instance = new MyClass()
instance.sum(2, 3); // execute the decorated method
var STRIP_COMMENTS = /((\/\/.*$)|(\/\*[\s\S]*?\*\/))/mg;
var ARGUMENT_NAMES = /([^\s,]+)/g;
function getParamNames(func) {
var fnStr = func.toString().replace(STRIP_COMMENTS, '');
var result = fnStr.slice(fnStr.indexOf('(') + 1, fnStr.indexOf(')')).match(ARGUMENT_NAMES);
if (result === null)
result = [];
return result;
}
const insertStuff = (target, name, descriptor) => {
const original = descriptor.value;
if (typeof original === 'function') {
const paramNames = getParamNames(original)
descriptor.value = function () {
const args = paramNames.reduce((arr, pn, i) => {
arr[i] = this.newStuff[pn];
return arr;}, [] )