From 920c5cbaa5e9cbfa5267f162925b40eff13f8b34 Mon Sep 17 00:00:00 2001 From: Ian Fabs Date: Tue, 27 Nov 2018 20:58:21 -0500 Subject: [PATCH 01/15] Simple template-tagged jraph --- index.ts | 64 ++++++++++++++++--------------- test/examples/vanilla.mutation.js | 33 ---------------- test/examples/vanilla.query.js | 33 ---------------- test/test.js | 46 +++++++++++++--------- tsconfig.json | 2 +- 5 files changed, 62 insertions(+), 116 deletions(-) delete mode 100644 test/examples/vanilla.mutation.js delete mode 100644 test/examples/vanilla.query.js diff --git a/index.ts b/index.ts index ca5a6f5..f5e04ac 100644 --- a/index.ts +++ b/index.ts @@ -1,48 +1,52 @@ import es6 from 'es6-promise'; es6.polyfill(); - import 'isomorphic-fetch'; interface JraphBasic{ - url: string | Request; + uri: string; options: any; } -abstract class JraphQuery implements JraphBasic{ - url: string = ""; - options: any = {}; - query: string = ""; - constructor(args: any){ - Object.assign(this, args); - } -} -abstract class JraphMutation implements JraphBasic{ - url: string = ""; - options: any = {}; - mutation: string = ""; - constructor(args: any){ - Object.assign(this, args); - } + +type JraphOptions = JraphBasic; + +function cleanQueryString(string: string):string{ + //This removes whitespaces and slashes and '\n's + return string.replace(/([\\][n])?([\s])+/g, " "); } -type JraphOptions = JraphQuery | JraphMutation; +function prepareFetchBody(queryString: string):string{ + return JSON.stringify({ query: queryString }); +} -async function jraph(argv: JraphOptions){ - const url : string | Request = argv.url; +function jraph(args: JraphOptions){ + let uri : string = args.uri; const headers = { 'Content-Type': 'application/json' }; - const body = JSON.stringify( { query: ( (argv instanceof JraphQuery) ? argv.query : `mutation ${argv.mutation}`).replace(/([\\][n])?([\s])+/g, " ") } ); - //(argv instanceof JraphQuery) ? {query: argv.query} : { query: `mutation ${argv.mutation.replace(/([\\][n])?([\s])+/g, " ")}`} ); - const fetch_options = { + let options = args.options; + if(!options.method) options.method = "POST"; + let fetch_options = { headers, - body: body, - ...argv.options + ...options + }; + return async (args: string[])=>{ + console.log(args); + let queryString = args.join(""); + queryString = cleanQueryString(queryString); + let url = new URL(uri); + if(options.method && (options.method == "GET" || options.method == "get")) { + let searchParams = url.searchParams; + searchParams.append("query", queryString); + fetch_options = {...fetch_options}; + }else { + let body = prepareFetchBody(queryString); + fetch_options = {...fetch_options, body}; + } + const request = await fetch(String(url), fetch_options).then(res=>res.json()); + return request; }; - console.log(body); - const request = await fetch(url, fetch_options).then(res=>res.json()); - return request; } /* * Some notes for the next version * - Nevermind, I had notes but they were redundant. */ -export default jraph; -export { jraph, JraphOptions, JraphQuery, JraphMutation } \ No newline at end of file +export { jraph, JraphOptions } +export default jraph; \ No newline at end of file diff --git a/test/examples/vanilla.mutation.js b/test/examples/vanilla.mutation.js deleted file mode 100644 index 0cf9191..0000000 --- a/test/examples/vanilla.mutation.js +++ /dev/null @@ -1,33 +0,0 @@ -const chai = require("chai"); -var chaiAsPromised = require("chai-as-promised"); -chai.use(chaiAsPromised); -const expect = chai.expect; -let {jraph, JraphMutation} = require('../../dist/index'); - -describe('JraphMutation', () => { - it('should return a json object with property `data`, without errors', () => { - async function addItem(){ - const JraphConfig = new JraphMutation({ - url: "https://csb-xpwq1o2824-alczxhlphl.now.sh/", - options: { - method: "POST" - }, - mutation:`{ - addItem(title: "sample", info: "test item"){ - title - info - } - }` - }); - return jraph(JraphConfig); - } - - let testPromise = new Promise( function(resolve, reject){ - resolve(addItem()); - } ); - return testPromise.then(function(result){ - console.dir(result, {depth: 10}); - expect(result).to.have.property("data"); - }) - }) -}); \ No newline at end of file diff --git a/test/examples/vanilla.query.js b/test/examples/vanilla.query.js deleted file mode 100644 index 30b04e4..0000000 --- a/test/examples/vanilla.query.js +++ /dev/null @@ -1,33 +0,0 @@ -const chai = require("chai"); -var chaiAsPromised = require("chai-as-promised"); -chai.use(chaiAsPromised); -const expect = chai.expect; -let {jraph, JraphQuery} = require('../../dist/index'); - -describe('JraphQuery', () => { - it('should return a json object with property `data`, without errors', () => { - async function getItems(){ - const JraphConfig = new JraphQuery({ - url: "https://csb-xpwq1o2824-alczxhlphl.now.sh/", - options: { - method: "POST" - }, - query:`{ - items{ - title - info - } - }` - }); - return jraph(JraphConfig); - } - - let testPromise = new Promise( function(resolve, reject){ - resolve(getItems()); - } ); - return testPromise.then(function(result){ - console.dir(result, {depth: 10}); - expect(result).to.have.property("data"); - }) - }) -}); \ No newline at end of file diff --git a/test/test.js b/test/test.js index 522267f..186b0a6 100644 --- a/test/test.js +++ b/test/test.js @@ -2,27 +2,35 @@ const chai = require("chai"); var chaiAsPromised = require("chai-as-promised"); chai.use(chaiAsPromised); const expect = chai.expect; -let {jraph, JraphQuery} = require('../dist/index'); +let { + jraph, + JraphOptions +} = require('../dist/index'); describe('jraph()', () => { - it('should return a json object with property `data`', () => { - let options = new JraphQuery({ - url: 'https://csb-8kj415zvx9-yaccgwjitv.now.sh/', - options: { - method: "POST" - }, - query: `{ - posts{ - content - } - }` - }); + it('should return a json object with property `data`', () => { + //=============================================================== - let testPromise = new Promise( function(resolve, reject){ - resolve(jraph(options)); - } ); - return testPromise.then(function(result){ - expect(result).to.have.property("data"); - }) + let jql = jraph({ + uri: "https://csb-xpwq1o2824-alczxhlphl.now.sh/", + options: {method: "POST"} + }); + let results = + jql` + query{ + items{ + title + } + } + `; + + //================================================================ + let testPromise = new Promise(function (resolve, reject) { + resolve(results); + }); + return testPromise.then(function (result) { + console.log(result); + expect(result).to.have.property("data"); }) + }) }); \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json index 288adb5..33260d5 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,7 +1,7 @@ { "compilerOptions": { /* Basic Options */ - "target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */ + "target": "es6", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */ "module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */ "lib": ["es2017", "es7", "es6", "dom"], /* Specify library files to be included in the compilation. */ // "allowJs": true, /* Allow javascript files to be compiled. */ From f5fda8d8e6a6f906d65102ffef5866f2a4b61a3d Mon Sep 17 00:00:00 2001 From: Ian Fabs Date: Wed, 28 Nov 2018 15:20:01 -0500 Subject: [PATCH 02/15] Updated readme with examples for new syntax --- README.md | 45 +++++++++++++++++++++++++++++---------------- 1 file changed, 29 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index aca13c7..3e4477a 100644 --- a/README.md +++ b/README.md @@ -13,42 +13,55 @@ jraph is written in typescript, but can be used in both a VanillaJS and a TypeSc #### Queries ```js - import {jraph, JraphQuery} from 'jraph'; + import {jraph} from 'jraph'; async function getItems(){ - const JraphConfig = new JraphQuery({ + const jql = jraph({ url: "https://csb-xpwq1o2824-alczxhlphl.now.sh/", options: { method: "POST" - }, - query:`{ + } + }); + return ( + jql` + query{ items{ title info } }` - }); - return jraph(JraphConfig); + ); + } + + async function showStuff(){ + console.log(await getItems()) } ``` #### Mutations ```js - import {jraph, JraphMutation} from 'jraph'; + import {jraph} from 'jraph'; - async function addItems(){ - const JraphConfig = new JraphMutation({ + async function addItem(){ + const jql = jraph({ url: "https://csb-xpwq1o2824-alczxhlphl.now.sh/", options: { method: "POST" - }, - mutation:`{ - addItem(title: "Eggs", info: "Cumberbatch"){ - content - } - }`; + } }); - return jraph(JraphConfig); + return ( + jql` + mutation{ + addItem(title: "egg", info: "salad"){ + title + info + } + }` + ); + } + + async function showStuff(){ + console.log(await addItem()) } ``` From 0bcf6fe4e27ee36ff94a02dedccf20b89a0aa70f Mon Sep 17 00:00:00 2001 From: Ian Fabs Date: Wed, 28 Nov 2018 15:20:45 -0500 Subject: [PATCH 03/15] Updated tests with new syntax --- test/mutation.test.js | 43 +++++++++++++++++++++++++++++++++++++++++++ test/query.test.js | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+) create mode 100644 test/mutation.test.js create mode 100644 test/query.test.js diff --git a/test/mutation.test.js b/test/mutation.test.js new file mode 100644 index 0000000..a2f9227 --- /dev/null +++ b/test/mutation.test.js @@ -0,0 +1,43 @@ +const chai = require("chai"); +const chaiAsPromised = require("chai-as-promised"); +chai.use(chaiAsPromised); +const expect = chai.expect; +let { + jraph, + JraphOptions +} = require('../dist/index'); + +describe('jraph mutation', () => { + it('should return a json object with property `data`', () => { + //=============================================================== + const jql = jraph({ + uri: "https://csb-xpwq1o2824-alczxhlphl.now.sh/", + options: { + method: "POST" + } + }); + const item = { + title: "Toast", + info: "butter" + } + let results = ( + jql` + mutation{ + addItem(title: "${item.title}", info: "${item.info}"){ + title + info + } + } + ` + ); + + //================================================================ + let testPromise = new Promise(function (resolve, reject) { + resolve(results); + }); + return testPromise.then(function (result) { + console.log(result); + expect(result).to.have.property("data"); + }) + }) +}); \ No newline at end of file diff --git a/test/query.test.js b/test/query.test.js new file mode 100644 index 0000000..61523ef --- /dev/null +++ b/test/query.test.js @@ -0,0 +1,37 @@ +const chai = require("chai"); +const chaiAsPromised = require("chai-as-promised"); +chai.use(chaiAsPromised); +const expect = chai.expect; +let { + jraph, + JraphOptions +} = require('../dist/index'); + +describe('jraph query', () => { + it('should return a json object with property `data`', () => { + //=============================================================== + + let jql = jraph({ + uri: "https://csb-xpwq1o2824-alczxhlphl.now.sh/", + options: {method: "POST"} + }); + + let results = + jql` + query{ + items{ + title + } + } + `; + + //================================================================ + let testPromise = new Promise(function (resolve, reject) { + resolve(results); + }); + return testPromise.then(function (result) { + console.log(result); + expect(result).to.have.property("data"); + }) + }) +}); \ No newline at end of file From 25ba2074ff5fc62393c7dc185fb87936e8bbf5e0 Mon Sep 17 00:00:00 2001 From: Ian Fabs Date: Wed, 28 Nov 2018 15:21:42 -0500 Subject: [PATCH 04/15] removed general test --- test/test.js | 36 ------------------------------------ 1 file changed, 36 deletions(-) delete mode 100644 test/test.js diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 186b0a6..0000000 --- a/test/test.js +++ /dev/null @@ -1,36 +0,0 @@ -const chai = require("chai"); -var chaiAsPromised = require("chai-as-promised"); -chai.use(chaiAsPromised); -const expect = chai.expect; -let { - jraph, - JraphOptions -} = require('../dist/index'); - -describe('jraph()', () => { - it('should return a json object with property `data`', () => { - //=============================================================== - - let jql = jraph({ - uri: "https://csb-xpwq1o2824-alczxhlphl.now.sh/", - options: {method: "POST"} - }); - let results = - jql` - query{ - items{ - title - } - } - `; - - //================================================================ - let testPromise = new Promise(function (resolve, reject) { - resolve(results); - }); - return testPromise.then(function (result) { - console.log(result); - expect(result).to.have.property("data"); - }) - }) -}); \ No newline at end of file From 663e59c3e3d3f7b7924cd04981a7e689b0a1dae8 Mon Sep 17 00:00:00 2001 From: Ian Fabs Date: Wed, 28 Nov 2018 15:22:11 -0500 Subject: [PATCH 05/15] Changed core functionality, new use syntax --- index.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/index.ts b/index.ts index f5e04ac..1a902ce 100644 --- a/index.ts +++ b/index.ts @@ -27,9 +27,13 @@ function jraph(args: JraphOptions){ headers, ...options }; - return async (args: string[])=>{ + return async (args: string[], ...values:any)=>{ console.log(args); - let queryString = args.join(""); + //let queryString = args.join(""); + let queryString = ""; + args.forEach( (string, i) => { + queryString += string + (values[i] || ''); + }); queryString = cleanQueryString(queryString); let url = new URL(uri); if(options.method && (options.method == "GET" || options.method == "get")) { From 91a0ec3fc01d11bf2219a71019f544f7c6075e81 Mon Sep 17 00:00:00 2001 From: Ian Fabs Date: Mon, 10 Dec 2018 15:48:27 -0500 Subject: [PATCH 06/15] Removed export default and changed jql function return spec --- index.ts | 59 ++++++++++++++++++++++++++++++++------------------------ 1 file changed, 34 insertions(+), 25 deletions(-) diff --git a/index.ts b/index.ts index 1a902ce..f6cb8c5 100644 --- a/index.ts +++ b/index.ts @@ -1,14 +1,26 @@ -import es6 from 'es6-promise'; -es6.polyfill(); -import 'isomorphic-fetch'; -interface JraphBasic{ - uri: string; - options: any; +if(typeof global !== 'undefined'){ + const realFetch = require('node-fetch'); + let fetch = function(url:any, options:any) { + if (/^\/\//.test(url)) { + url = 'https:' + url; + } + // @ts-ignore + return realFetch.call(this, url, options); + }; + // @ts-ignore + if (!global.fetch) { + // @ts-ignore + global.fetch = fetch; + // @ts-ignore + global.Response = realFetch.Response; + // @ts-ignore + global.Headers = realFetch.Headers; + // @ts-ignore + global.Request = realFetch.Request; + } } -type JraphOptions = JraphBasic; - function cleanQueryString(string: string):string{ //This removes whitespaces and slashes and '\n's return string.replace(/([\\][n])?([\s])+/g, " "); @@ -18,39 +30,36 @@ function prepareFetchBody(queryString: string):string{ return JSON.stringify({ query: queryString }); } -function jraph(args: JraphOptions){ - let uri : string = args.uri; +function jraph(uri: string, args: object): any{ const headers = { 'Content-Type': 'application/json' }; - let options = args.options; - if(!options.method) options.method = "POST"; let fetch_options = { + method: "POST", + body: "", + ...args, headers, - ...options }; return async (args: string[], ...values:any)=>{ - console.log(args); - //let queryString = args.join(""); let queryString = ""; args.forEach( (string, i) => { queryString += string + (values[i] || ''); }); queryString = cleanQueryString(queryString); let url = new URL(uri); - if(options.method && (options.method == "GET" || options.method == "get")) { + if(fetch_options.method && (fetch_options.method == "GET" || fetch_options.method == "get")) { let searchParams = url.searchParams; searchParams.append("query", queryString); - fetch_options = {...fetch_options}; }else { let body = prepareFetchBody(queryString); fetch_options = {...fetch_options, body}; } - const request = await fetch(String(url), fetch_options).then(res=>res.json()); - return request; + const request = await fetch(String(url), fetch_options).then(res=>res.text()); + try{ + let json = JSON.parse(request); + return json; + }catch(e){ + return request; + } }; } -/* -* Some notes for the next version -* - Nevermind, I had notes but they were redundant. -*/ -export { jraph, JraphOptions } -export default jraph; \ No newline at end of file + +export { jraph } \ No newline at end of file From 8acae820ceb21029f681726587e34b9add1a5f58 Mon Sep 17 00:00:00 2001 From: Ian Fabs Date: Mon, 10 Dec 2018 15:49:49 -0500 Subject: [PATCH 07/15] Removed ES6 Promise Polyfill and isomorphic fetch --- package.json | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 4452e2c..49fb778 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "scripts": { "build": "tsc", "version": "tsc && npm publish", - "test": "mocha --recursive \"./test/**/*.js\"" + "test": "npm run build && mocha --recursive \"./test/**/*.js\"" }, "keywords": [ "graphql", @@ -22,8 +22,7 @@ }, "dependencies": { "typescript": "^3.1.6", - "es6-promise": "^4.2.5", - "isomorphic-fetch": "^2.2.1" + "node-fetch": "^1.0.1" }, "devDependencies": { "chai": "^4.2.0", From a16c3e9a5ace96641ae802e80105e4ceb477926c Mon Sep 17 00:00:00 2001 From: Ian Fabs Date: Mon, 10 Dec 2018 15:50:38 -0500 Subject: [PATCH 08/15] Updated tsconfig.json --- tsconfig.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tsconfig.json b/tsconfig.json index 33260d5..a03fb8a 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -2,7 +2,7 @@ "compilerOptions": { /* Basic Options */ "target": "es6", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */ - "module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */ + "module": "umd", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */ "lib": ["es2017", "es7", "es6", "dom"], /* Specify library files to be included in the compilation. */ // "allowJs": true, /* Allow javascript files to be compiled. */ // "checkJs": true, /* Report errors in .js files. */ @@ -14,7 +14,7 @@ "outDir": "dist", /* Redirect output structure to the directory. */ // "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */ // "composite": true, /* Enable project compilation */ - // "removeComments": true, /* Do not emit comments to output. */ + "removeComments": true, /* Do not emit comments to output. */ // "noEmit": true, /* Do not emit outputs. */ // "importHelpers": true, /* Import emit helpers from 'tslib'. */ // "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */ From 982f01742b2d5518334ab7c53b9eaf5eb440edb4 Mon Sep 17 00:00:00 2001 From: Ian Fabs Date: Mon, 10 Dec 2018 15:52:02 -0500 Subject: [PATCH 09/15] Updated tests --- test/multiple.test.js | 60 ++++++++++++++++++++++++++++++++++++++++ test/mutation.test.js | 64 +++++++++++++++++++++++-------------------- test/query.test.js | 38 ++++++++++++------------- 3 files changed, 113 insertions(+), 49 deletions(-) create mode 100644 test/multiple.test.js diff --git a/test/multiple.test.js b/test/multiple.test.js new file mode 100644 index 0000000..1bbb1e8 --- /dev/null +++ b/test/multiple.test.js @@ -0,0 +1,60 @@ +const chai = require("chai"); +const chaiAsPromised = require("chai-as-promised"); +chai.use(chaiAsPromised); +const expect = chai.expect; + +let {jraph} = require('../dist/index'); + +describe('reusing the jql function', () => { + const jql = jraph( + "https://csb-xpwq1o2824-xravvsjkul.now.sh/", + { + method: "POST" + } + ); + const item = { + title: "Toast", + info: "butter" + } + let results1 = ( + jql` + query{ + items{ + title + } + } + ` + ); + let results2 = ( + jql` + query{ + items{ + info + } + } + ` +); + //=============================================================== + let testPromise1 = new Promise(function (resolve, reject) { + resolve(results1); + }); + let testPromise2 = new Promise(function (resolve, reject) { + resolve(results2); + }); + //=============================================================== + it('should be okay', ()=>{ + return Promise.all([testPromise1, testPromise2]).then(res=>{ + expect(res).to.be.ok; + }) + }) + + it('should return a json object with property `data`', () => { + return Promise.all([testPromise1, testPromise2]).then(res=>{ + expect(res[0]).to.have.property("data"); + console.log(res[0]); + expect(res[1]).to.have.property("data"); + console.log(res[1]); + }) + }) + +}); \ No newline at end of file diff --git a/test/mutation.test.js b/test/mutation.test.js index a2f9227..522a284 100644 --- a/test/mutation.test.js +++ b/test/mutation.test.js @@ -2,42 +2,46 @@ const chai = require("chai"); const chaiAsPromised = require("chai-as-promised"); chai.use(chaiAsPromised); const expect = chai.expect; -let { - jraph, - JraphOptions -} = require('../dist/index'); -describe('jraph mutation', () => { - it('should return a json object with property `data`', () => { - //=============================================================== - const jql = jraph({ - uri: "https://csb-xpwq1o2824-alczxhlphl.now.sh/", - options: { - method: "POST" - } - }); - const item = { - title: "Toast", - info: "butter" - } - let results = ( - jql` - mutation{ - addItem(title: "${item.title}", info: "${item.info}"){ - title - info - } - } - ` - ); +let {jraph} = require('../dist/index'); - //================================================================ - let testPromise = new Promise(function (resolve, reject) { +describe('jraph mutation', () => { + const jql = jraph( + "https://csb-xpwq1o2824-xravvsjkul.now.sh/", + { + method: "POST" + } + ); + const item = { + title: "Toast", + info: "butter" + } + let results = ( + jql` + mutation{ + addItem(title: "${item.title}", info: "${item.info}"){ + title + info + } + } + ` + ); + //=============================================================== + let testPromise = new Promise(function (resolve, reject) { resolve(results); - }); + }); + + it('should be okay', ()=>{ + return testPromise.then(function (result) { + expect(result).to.be.ok; + }) + }) + + it('should return a json object with property `data`', () => { return testPromise.then(function (result) { console.log(result); expect(result).to.have.property("data"); }) }) + }); \ No newline at end of file diff --git a/test/query.test.js b/test/query.test.js index 61523ef..9a9db79 100644 --- a/test/query.test.js +++ b/test/query.test.js @@ -2,22 +2,14 @@ const chai = require("chai"); const chaiAsPromised = require("chai-as-promised"); chai.use(chaiAsPromised); const expect = chai.expect; -let { - jraph, - JraphOptions -} = require('../dist/index'); +let {jraph} = require('../dist/index'); describe('jraph query', () => { - it('should return a json object with property `data`', () => { - //=============================================================== - - let jql = jraph({ - uri: "https://csb-xpwq1o2824-alczxhlphl.now.sh/", - options: {method: "POST"} - }); + let jql = jraph("https://csb-xpwq1o2824-xravvsjkul.now.sh/", { + method: "POST" + }); - let results = - jql` + let results = jql` query{ items{ title @@ -25,13 +17,21 @@ describe('jraph query', () => { } `; - //================================================================ - let testPromise = new Promise(function (resolve, reject) { - resolve(results); - }); + let testPromise = new Promise(function (resolve, reject) { + resolve(results); + }); + + it('should be ok', ()=>{ + return testPromise.then(function (result) { + expect(result).to.be.ok; + }) + }); + + it('should return a json object with property `data`', () => { return testPromise.then(function (result) { console.log(result); - expect(result).to.have.property("data"); + expect(result).to.have.property("data") }) - }) + }); + }); \ No newline at end of file From 07f8d7d05b7dea185812b05cbd37ba575bd1067e Mon Sep 17 00:00:00 2001 From: Ian Fabs Date: Mon, 10 Dec 2018 15:54:40 -0500 Subject: [PATCH 10/15] Added versioning scripts --- package.json | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 49fb778..90b0d8c 100644 --- a/package.json +++ b/package.json @@ -6,8 +6,11 @@ "types": "dist/index.d.ts", "scripts": { "build": "tsc", - "version": "tsc && npm publish", - "test": "npm run build && mocha --recursive \"./test/**/*.js\"" + "pretest": "npm install && npm run build", + "test": "mocha --recursive \"./test/**/*.js\"", + "preversion": "npm test", + "version": "npm run build && git add -A .", + "postversion": "git push && git push --tags && npm publish" }, "keywords": [ "graphql", From 9774ec15bc120cd3a77b3b1701f877197a66214d Mon Sep 17 00:00:00 2001 From: Ian Fabs Date: Mon, 10 Dec 2018 15:56:48 -0500 Subject: [PATCH 11/15] Minor dependency fix --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 90b0d8c..709a867 100644 --- a/package.json +++ b/package.json @@ -24,10 +24,10 @@ "type": "github" }, "dependencies": { - "typescript": "^3.1.6", "node-fetch": "^1.0.1" }, "devDependencies": { + "typescript": "^3.1.6", "chai": "^4.2.0", "chai-as-promised": "^7.1.1", "mocha": "^5.2.0" From 16f180c9d0cd5481f6f8f82fac38fbe7e6834fb4 Mon Sep 17 00:00:00 2001 From: Fabricatore Date: Mon, 10 Dec 2018 15:57:11 -0500 Subject: [PATCH 12/15] 2.0.0 --- package-lock.json | 34 ++++------------------------------ package.json | 2 +- 2 files changed, 5 insertions(+), 31 deletions(-) diff --git a/package-lock.json b/package-lock.json index 14ccf5b..325548a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "jraph", - "version": "1.1.9", + "version": "2.0.0", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -101,17 +101,10 @@ "version": "0.1.12", "resolved": "https://registry.npmjs.org/encoding/-/encoding-0.1.12.tgz", "integrity": "sha1-U4tm8+5izRq1HsMjgp0flIDHS+s=", - "dev": true, "requires": { "iconv-lite": "~0.4.13" } }, - "es6-promise": { - "version": "4.2.5", - "resolved": "https://registry.npmjs.org/es6-promise/-/es6-promise-4.2.5.tgz", - "integrity": "sha512-n6wvpdE43VFtJq+lUDYDBFUwV8TZbuGXLV4D6wKafg13ldznKsyEvatubnmUe31zcvelSzOHF+XbaT+Bl9ObDg==", - "dev": true - }, "escape-string-regexp": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz", @@ -166,7 +159,6 @@ "version": "0.4.24", "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz", "integrity": "sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==", - "dev": true, "requires": { "safer-buffer": ">= 2.1.2 < 3" } @@ -190,18 +182,7 @@ "is-stream": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/is-stream/-/is-stream-1.1.0.tgz", - "integrity": "sha1-EtSj3U5o4Lec6428hBc66A2RykQ=", - "dev": true - }, - "isomorphic-fetch": { - "version": "2.2.1", - "resolved": "https://registry.npmjs.org/isomorphic-fetch/-/isomorphic-fetch-2.2.1.tgz", - "integrity": "sha1-YRrhrPFPXoH3KVB0coGf6XM1WKk=", - "dev": true, - "requires": { - "node-fetch": "^1.0.1", - "whatwg-fetch": ">=0.10.0" - } + "integrity": "sha1-EtSj3U5o4Lec6428hBc66A2RykQ=" }, "minimatch": { "version": "3.0.4", @@ -256,7 +237,6 @@ "version": "1.7.3", "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-1.7.3.tgz", "integrity": "sha512-NhZ4CsKx7cYm2vSrBAr2PvFOe6sWDf0UYLRqA6svUYg7+/TSfVAu49jYC4BvQ4Sms9SZgdqGBgroqfDhJdTyKQ==", - "dev": true, "requires": { "encoding": "^0.1.11", "is-stream": "^1.0.1" @@ -286,8 +266,7 @@ "safer-buffer": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", - "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==", - "dev": true + "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==" }, "supports-color": { "version": "5.4.0", @@ -307,12 +286,7 @@ "typescript": { "version": "3.1.6", "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.1.6.tgz", - "integrity": "sha512-tDMYfVtvpb96msS1lDX9MEdHrW4yOuZ4Kdc4Him9oU796XldPYF/t2+uKoX0BBa0hXXwDlqYQbXY5Rzjzc5hBA==" - }, - "whatwg-fetch": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/whatwg-fetch/-/whatwg-fetch-3.0.0.tgz", - "integrity": "sha512-9GSJUgz1D4MfyKU7KRqwOjXCXTqWdFNvEr7eUBYchQiVc744mqK/MzXPNR2WsPkmkOa4ywfg8C2n8h+13Bey1Q==", + "integrity": "sha512-tDMYfVtvpb96msS1lDX9MEdHrW4yOuZ4Kdc4Him9oU796XldPYF/t2+uKoX0BBa0hXXwDlqYQbXY5Rzjzc5hBA==", "dev": true }, "wrappy": { diff --git a/package.json b/package.json index 709a867..80631ad 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "jraph", - "version": "1.1.9", + "version": "2.0.0", "description": "A fetch wrapper for GraphQL", "main": "dist/index.js", "types": "dist/index.d.ts", From 693376122556d2c5224a3f5a35bf83a665416d82 Mon Sep 17 00:00:00 2001 From: Ian Fabs Date: Mon, 10 Dec 2018 16:05:41 -0500 Subject: [PATCH 13/15] Updated README.md --- README.md | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 3e4477a..d890886 100644 --- a/README.md +++ b/README.md @@ -16,15 +16,14 @@ jraph is written in typescript, but can be used in both a VanillaJS and a TypeSc import {jraph} from 'jraph'; async function getItems(){ - const jql = jraph({ - url: "https://csb-xpwq1o2824-alczxhlphl.now.sh/", - options: { + const jql = jraph( + "https://csb-xpwq1o2824-alczxhlphl.now.sh/", + { method: "POST" } }); return ( - jql` - query{ + jql`{ items{ title info @@ -43,9 +42,9 @@ jraph is written in typescript, but can be used in both a VanillaJS and a TypeSc import {jraph} from 'jraph'; async function addItem(){ - const jql = jraph({ - url: "https://csb-xpwq1o2824-alczxhlphl.now.sh/", - options: { + const jql = jraph( + "https://csb-xpwq1o2824-alczxhlphl.now.sh/", + { method: "POST" } }); From f0faa4390d78fc8c3df7faa9e7d72ca8fc87f4cc Mon Sep 17 00:00:00 2001 From: Ian Fabs Date: Mon, 10 Dec 2018 16:07:32 -0500 Subject: [PATCH 14/15] Updated github url for v2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 80631ad..9d55b8a 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,7 @@ "author": "Ian Fabs", "license": "MIT", "repository": { - "url": "https://github.com/ianfabs/jraph.git", + "url": "https://github.com/ianfabs/jraph/tree/gql", "type": "github" }, "dependencies": { From 1d78b759a938b64432f092a60e31a85de1ea29f0 Mon Sep 17 00:00:00 2001 From: Fabricatore Date: Mon, 10 Dec 2018 16:08:06 -0500 Subject: [PATCH 15/15] 2.0.1 --- package-lock.json | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index 325548a..ae7a695 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "jraph", - "version": "2.0.0", + "version": "2.0.1", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 9d55b8a..bf99899 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "jraph", - "version": "2.0.0", + "version": "2.0.1", "description": "A fetch wrapper for GraphQL", "main": "dist/index.js", "types": "dist/index.d.ts",