From cd0b07b3adb36fb5ec098f9e511ab45d774fee7b Mon Sep 17 00:00:00 2001 From: Wes Bos Date: Tue, 30 Jan 2018 12:41:01 -0500 Subject: Move to Prisma Backend --- graphcool/src/createCharge.js | 52 -------------------------------------- graphcool/src/createCharge.test.js | 23 ----------------- graphcool/src/getPrice.js | 26 ------------------- graphcool/src/hello.graphql | 7 ----- graphcool/src/hello.js | 11 -------- graphcool/src/index.js | 2 -- 6 files changed, 121 deletions(-) delete mode 100644 graphcool/src/createCharge.js delete mode 100644 graphcool/src/createCharge.test.js delete mode 100644 graphcool/src/getPrice.js delete mode 100644 graphcool/src/hello.graphql delete mode 100644 graphcool/src/hello.js delete mode 100644 graphcool/src/index.js (limited to 'graphcool/src') diff --git a/graphcool/src/createCharge.js b/graphcool/src/createCharge.js deleted file mode 100644 index ccf9c11..0000000 --- a/graphcool/src/createCharge.js +++ /dev/null @@ -1,52 +0,0 @@ -const stripe = require('stripe')('sk_ycLkGc2cAaBDSCKkHiKVBeT71CMxd'); - -const endpoint = 'https://api.graph.cool/simple/v1/cj99zm6ye06sb01325ic751ww'; - -require('isomorphic-fetch'); - -const getPrice = itemId => { - const query = ` - query SingleItem { - Item(id: "${itemId}") { - price - } - } - `; - - return fetch(endpoint, { - method: 'post', - headers: { - 'Content-Type': 'application/json', - }, - body: JSON.stringify({ query }), - }); -}; - -const createStripeCharge = (token, amount) => - stripe.charges.create({ - amount, - currency: 'usd', - description: `a test charge`, - source: token, - }); - -module.exports = function(event) { - return new Promise((resolve, reject) => { - // first find out the price of the item - getPrice(event.data.itemId) - .then(res => res.json()) - .then(res => { - console.log(`Back with the price ${res.data.Item.price}!`); - return createStripeCharge(event.data.token, res.data.Item.price); - }) - .then(res => { - console.log(`Back! charge ${res.id} for the amount ${res.amount}`); - event.data.charge = res.id; - event.data.amount = res.amount; - resolve(event); - }) - .catch(err => { - reject(err); - }); - }); -}; diff --git a/graphcool/src/createCharge.test.js b/graphcool/src/createCharge.test.js deleted file mode 100644 index 65dde47..0000000 --- a/graphcool/src/createCharge.test.js +++ /dev/null @@ -1,23 +0,0 @@ -const takeMoney = require('./createCharge'); - -const event = { - "data": { - "user": "cj6ntm8qic3260140vkuzif9d", - "token": "tok_visa", - }, - "context": { - "headers": {} - } -} - - -describe('Take Money', () => { - - test('A charge has come back', async () => { - const res = await takeMoney(event); - console.log(res); - expect(res.data.amount).toBeGreaterThanOrEqual(0); - }); - -}); - diff --git a/graphcool/src/getPrice.js b/graphcool/src/getPrice.js deleted file mode 100644 index 7808a85..0000000 --- a/graphcool/src/getPrice.js +++ /dev/null @@ -1,26 +0,0 @@ -require('isomorphic-fetch') - -const query = ` -query SingleItem { - Item(id: "cj64bs7vuuqgu0116ul5cm223") { - price - } -} -`; - -function getItem(id) { - return fetch('https://api.graph.cool/simple/v1/cj5xz8szs28930145gct82bdj', { - method: 'post', - headers: { - 'Content-Type': 'application/json', - }, - body: JSON.stringify({ query }), - }) -} - - -module.exports = function(event) { - getItem().then(x => x.json()).then(res => { - console.log(res.data.Item.price); - }).catch(console.log) -} diff --git a/graphcool/src/hello.graphql b/graphcool/src/hello.graphql deleted file mode 100644 index d43c729..0000000 --- a/graphcool/src/hello.graphql +++ /dev/null @@ -1,7 +0,0 @@ -type HelloPayload { - message: String! -} - -extend type Query { - hello(name: String): HelloPayload -} diff --git a/graphcool/src/hello.js b/graphcool/src/hello.js deleted file mode 100644 index 0e3e7ba..0000000 --- a/graphcool/src/hello.js +++ /dev/null @@ -1,11 +0,0 @@ -export default async event => { - // you can use ES7 with async/await and even TypeScript in your functions :) - - await new Promise(r => setTimeout(r, 50)) - - return { - data: { - message: `Hello ${event.data.name || 'World'}` - } - } -} \ No newline at end of file diff --git a/graphcool/src/index.js b/graphcool/src/index.js deleted file mode 100644 index ee451f6..0000000 --- a/graphcool/src/index.js +++ /dev/null @@ -1,2 +0,0 @@ -module.exports = () => 'Welcome to Micro' -exports.what = () => 'What' -- cgit v1.3