This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { makeExecutableSchema } from 'graphql-tools'; | |
import resolvers from './resolvers'; | |
const typeDefs = [ | |
` | |
type Query { | |
go: String! | |
} | |
type Subscription { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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;}, [] ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyClass { | |
@log | |
sum(a, b) { | |
return a + b; | |
} | |
} | |
const instance = new MyClass() | |
instance.sum(2, 3); // execute the decorated method |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from "react" | |
import { Query } from "react-apollo"; | |
import gql from "graphql-tag"; | |
const ExchangeRates = () => ( | |
<Query | |
query={gql` | |
{ | |
rates(currency: "USD") { | |
currency | |
rate |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}> |