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
import { PubSub } from 'apollo-server-express';
const pubsub = new PubSub();
const TOPIC = 'infoTopic';
const infos = ['info1', 'info2', 'info3', 'done']
const publish = () => {
setTimeout( () =>
infos.forEach(info => pubsub.publish(TOPIC, {info})), 1000)
import { makeExecutableSchema } from 'graphql-tools';
import resolvers from './resolvers';
const typeDefs = [
`
type Query {
go: String!
}
type Subscription {
import express from 'express';
import { ApolloServer } from 'apollo-server-express';
import http from 'http';
import { typeDefs } from './schema';
import resolvers from './resolvers';
const PORT = 3031;
const app = express();
const stuff = {
isWombat: true,
sugar: ["in the morning", "in the evening", "at suppertime"]
}
instance.newStuff = stuff;
instance.getStuff();
instance.newStuff.sugar = ["You are my candy, girl", "and you keep me wanting you"];
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;}, [] )
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;
}
class MyClass {
@log
sum(a, b) {
return a + b;
}
}
const instance = new MyClass()
instance.sum(2, 3); // execute the decorated method
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
import React from "react"
import { Query } from "react-apollo";
import gql from "graphql-tag";
const ExchangeRates = () => (
<Query
query={gql`
{
rates(currency: "USD") {
currency
rate
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}>