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
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
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 { 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
/* eslint-env mocha */ | |
/* eslint-disable import/no-extraneous-dependencies */ | |
// see https://www.apollographql.com/docs/link/index.html#standalone | |
import fetch from 'node-fetch'; | |
import { execute, makePromise } from 'apollo-link'; | |
import { WebSocketLink } from 'apollo-link-ws'; | |
import { SubscriptionClient } from 'subscriptions-transport-ws'; | |
import ws from 'ws'; | |
import { HttpLink } from 'apollo-link-http'; |
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
/* eslint-env mocha */ | |
import chai from 'chai'; | |
import fetch, { subscribe } from './fetch'; | |
chai.should(); | |
describe('subscribe, then go', function () { | |
this.timeout(5000); | |
const handlers = { |
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 { workerData, parentPort, isMainThread } = require("worker_threads"); | |
// You can do any heavy stuff here, in a synchronous way | |
// without blocking the "main thread" | |
parentPort.on("message", message => { | |
if (message === "exit") { | |
parentPort.postMessage("sold!"); | |
parentPort.close(); | |
} else { | |
parentPort.postMessage({ going: message }); |
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 { Worker, isMainThread } = require("worker_threads"); | |
function runService(workerData) { | |
const worker = new Worker("./service.js", { workerData }); | |
worker.postMessage("once"); | |
worker.on("message", incoming => console.log({ incoming })); | |
worker.on("error", code => new Error(`Worker error with exit code ${code}`)); | |
worker.on("exit", code => | |
console.log(`Worker stopped with exit code ${code}`) | |
); |
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, { Fragment } from 'react'; | |
import { Query } from 'react-apollo'; | |
import gql from 'graphql-tag'; | |
const qLaunches = gql`query ls { | |
launches { | |
launches { | |
id | |
site | |
mission { |
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
// Editor.js | |
const LOGIN = gql` | |
mutation login { | |
login(email:"${faker.internet.email}") | |
} | |
` | |
const Submit = (props) => { | |
return <Mutation mutation={LOGIN} update={(cache, { data }) => sessionStorage.setItem('auth', data.login)}> |