From c747327df9f4f3049775daf7354c8264e7f6c27e Mon Sep 17 00:00:00 2001 From: Paul Le Cam Date: Fri, 16 Feb 2018 13:06:19 +0000 Subject: [PATCH] GraphQL v0.13 --- CHANGELOG.md | 9 +++---- LICENSE | 2 +- README.md | 16 ++++++------- package.json | 10 ++++---- src/cli.js | 2 -- src/index.js | 68 ++-------------------------------------------------- yarn.lock | 55 +++++++++++++++--------------------------- 7 files changed, 40 insertions(+), 122 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c490c44..fce5caf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## v0.8.0 (2018-02-15) + +* Update GraphQL to v0.13.1 +* Remove `sort` option as the schema is sorted by default + ## v0.7.2 (2017-12-06) Update repository URL @@ -10,10 +15,6 @@ Fix exporting the binary Update GraphQL to v0.11.2 -## v0.7.0 (2017-08-29) - -Update GraphQL to v0.11.2 - ## v0.6.1 (2017-06-29) Fix version diff --git a/LICENSE b/LICENSE index d031b36..b1337b6 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2017 Mainframe +Copyright (c) 2018 Mainframe Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 1e3d135..e192e23 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,6 @@ graphql-fetch-schema [options] -g, --graphql write schema.graphql file -j, --json write schema.json file -o, --output write to specified directory --s, --sort sort field keys ``` ## API usage @@ -36,13 +35,14 @@ fetchSchema('https://api.myserver.com/graphql', { graphql: false, outputPath: '../schema', cookie: 'cookiename=foo;', -}) -.then(() => { - console.log('Schema successfully written') -}) -.catch((err) => { - console.error(err) -}) +}).then( + () => { + console.log('Schema successfully written') + }, + err => { + console.error(err) + }, +) ``` ## License diff --git a/package.json b/package.json index f436e47..54d8091 100644 --- a/package.json +++ b/package.json @@ -23,9 +23,9 @@ }, "dependencies": { "babel-runtime": "^6.26.0", - "commander": "^2.12.2", - "graphql": "^0.11.7", - "node-fetch": "^1.7.3" + "commander": "^2.14.1", + "graphql": "^0.13.1", + "node-fetch": "^2.0.0" }, "devDependencies": { "babel-cli": "^6.26.0", @@ -33,7 +33,7 @@ "babel-plugin-transform-flow-strip-types": "^6.22.0", "babel-plugin-transform-runtime": "^6.22.0", "babel-preset-env": "^1.6.1", - "flow-bin": "^0.60.1", - "prettier": "^1.9.1" + "flow-bin": "^0.65.0", + "prettier": "^1.10.2" } } diff --git a/src/cli.js b/src/cli.js index a0363b3..f2ccef7 100644 --- a/src/cli.js +++ b/src/cli.js @@ -23,7 +23,6 @@ program .option('-c, --cookie ', 'pass additional Cookie header') .option('-j, --json', 'write schema.json file') .option('-o, --output ', 'write to specified directory') - .option('-s, --sort', 'sort field keys') .parse(process.argv) run(program.args[0], { @@ -31,5 +30,4 @@ run(program.args[0], { json: !!program.json, outputPath: program.output, cookie: program.cookie, - sort: !!program.sort, }) diff --git a/src/index.js b/src/index.js index 6770a2f..65402eb 100644 --- a/src/index.js +++ b/src/index.js @@ -1,11 +1,7 @@ // @flow -import { - buildClientSchema, - introspectionQuery, - printSchema, -} from 'graphql/utilities' import fs from 'fs' +import { buildClientSchema, getIntrospectionQuery, printSchema } from 'graphql' import fetch from 'node-fetch' import path from 'path' @@ -31,62 +27,6 @@ const writeFile = ({ }) } -const sortType = (type: Object) => { - if (type['kind'] === 'OBJECT') { - return sortObject(type) - } else if (type['kind'] === 'INTERFACE') { - return sortInterface(type) - } else if (type['kind'] === 'ENUM') { - return sortEnum(type) - } else if (type['kind'] === 'INPUT_OBJECT') { - return sortInputObject(type) - } else if (type['kind'] === 'UNION') { - return type - } else if (type.kind === 'SCALAR') { - return type - } - - throw new Error('Unknown kind') -} - -const sortObject = (type: Object) => { - type.interfaces = type.interfaces.sort((int1, int2) => - int1.name.localeCompare(int2.name), - ) - type.fields = type.fields - .sort((field1, field2) => field1.name.localeCompare(field2.name)) - .map(sortArgs) - return type -} - -const sortInterface = (type: Object) => { - type.fields = type.fields.sort((field1, field2) => - field1.name.localeCompare(field2.name), - ) - return type -} - -const sortEnum = (type: Object) => { - type.enumValues = type.enumValues.sort((value1, value2) => - value1.name.localeCompare(value2.name), - ) - return type -} - -const sortInputObject = (type: Object) => { - type.inputFields = type.inputFields.sort((field1, field2) => - field1.name.localeCompare(field2.name), - ) - return type -} - -const sortArgs = (field: Object) => { - field.args = field.args.sort((arg1, arg2) => - arg1.name.localeCompare(arg2.name), - ) - return field -} - export default async (url: string, options: Options = {}) => { // If no option is set, consider it's all if (!options.graphql && !options.json) { @@ -107,14 +47,10 @@ export default async (url: string, options: Options = {}) => { method: 'POST', headers: headers, body: JSON.stringify({ - query: introspectionQuery, + query: getIntrospectionQuery(), }), }) const schema = await res.json() - if (options.sort) { - const types = schema.data.__schema.types.map(sortType) - schema.data.__schema.types = types - } const files = [] if (options.graphql) { diff --git a/yarn.lock b/yarn.lock index ab03383..26c7850 100644 --- a/yarn.lock +++ b/yarn.lock @@ -749,9 +749,9 @@ commander@^2.11.0: version "2.11.0" resolved "https://registry.yarnpkg.com/commander/-/commander-2.11.0.tgz#157152fd1e7a6c8d98a5b715cf376df928004563" -commander@^2.12.2: - version "2.12.2" - resolved "https://registry.yarnpkg.com/commander/-/commander-2.12.2.tgz#0f5946c427ed9ec0d91a46bb9def53e54650e555" +commander@^2.14.1: + version "2.14.1" + resolved "https://registry.yarnpkg.com/commander/-/commander-2.14.1.tgz#2235123e37af8ca3c65df45b026dbd357b01b9aa" concat-map@0.0.1: version "0.0.1" @@ -823,12 +823,6 @@ electron-to-chromium@^1.3.18: version "1.3.18" resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.18.tgz#3dcc99da3e6b665f6abbc71c28ad51a2cd731a9c" -encoding@^0.1.11: - version "0.1.12" - resolved "https://registry.yarnpkg.com/encoding/-/encoding-0.1.12.tgz#538b66f3ee62cd1ab51ec323829d1f9480c74beb" - dependencies: - iconv-lite "~0.4.13" - escape-string-regexp@^1.0.2: version "1.0.5" resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz#1b61c0562190a8dff6ae3bb2cf0200ca130b86d4" @@ -877,9 +871,9 @@ fill-range@^2.1.0: repeat-element "^1.1.2" repeat-string "^1.5.2" -flow-bin@^0.60.1: - version "0.60.1" - resolved "https://registry.yarnpkg.com/flow-bin/-/flow-bin-0.60.1.tgz#0f4fa7b49be2a916f18cd946fc4a51e32ffe4b48" +flow-bin@^0.65.0: + version "0.65.0" + resolved "https://registry.yarnpkg.com/flow-bin/-/flow-bin-0.65.0.tgz#64ffeca27211c786e2d68508c65686ba1b8a2169" for-in@^1.0.1: version "1.0.2" @@ -986,11 +980,11 @@ graceful-fs@^4.1.2, graceful-fs@^4.1.4: version "4.1.11" resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.1.11.tgz#0e8bdfe4d1ddb8854d64e04ea7c00e2a026e5658" -graphql@^0.11.7: - version "0.11.7" - resolved "https://registry.yarnpkg.com/graphql/-/graphql-0.11.7.tgz#e5abaa9cb7b7cccb84e9f0836bf4370d268750c6" +graphql@^0.13.1: + version "0.13.1" + resolved "https://registry.yarnpkg.com/graphql/-/graphql-0.13.1.tgz#9b3db3d8e40d1827e4172404bfdd2e4e17a58b55" dependencies: - iterall "1.1.3" + iterall "^1.2.0" har-schema@^1.0.5: version "1.0.5" @@ -1041,10 +1035,6 @@ http-signature@~1.1.0: jsprim "^1.2.2" sshpk "^1.7.0" -iconv-lite@~0.4.13: - version "0.4.18" - resolved "https://registry.yarnpkg.com/iconv-lite/-/iconv-lite-0.4.18.tgz#23d8656b16aae6742ac29732ea8f0336a4789cf2" - inflight@^1.0.4: version "1.0.6" resolved "https://registry.yarnpkg.com/inflight/-/inflight-1.0.6.tgz#49bd6331d7d02d0c09bc910a1075ba8165b56df9" @@ -1132,10 +1122,6 @@ is-primitive@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/is-primitive/-/is-primitive-2.0.0.tgz#207bab91638499c07b2adf240a41a87210034575" -is-stream@^1.0.1: - version "1.1.0" - resolved "https://registry.yarnpkg.com/is-stream/-/is-stream-1.1.0.tgz#12d4a3dd4e68e0b79ceb8dbc84173ae80d91ca44" - is-typedarray@~1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/is-typedarray/-/is-typedarray-1.0.0.tgz#e479c80858df0c1b11ddda6940f96011fcda4a9a" @@ -1154,9 +1140,9 @@ isstream@~0.1.2: version "0.1.2" resolved "https://registry.yarnpkg.com/isstream/-/isstream-0.1.2.tgz#47e63f7af55afa6f92e1500e690eb8b8529c099a" -iterall@1.1.3: - version "1.1.3" - resolved "https://registry.yarnpkg.com/iterall/-/iterall-1.1.3.tgz#1cbbff96204056dde6656e2ed2e2226d0e6d72c9" +iterall@^1.2.0: + version "1.2.0" + resolved "https://registry.yarnpkg.com/iterall/-/iterall-1.2.0.tgz#434e9f41f0b99911ab9c3d49d95f0e079176a2a2" js-tokens@^3.0.0, js-tokens@^3.0.2: version "3.0.2" @@ -1283,12 +1269,9 @@ nan@^2.3.0: version "2.6.2" resolved "https://registry.yarnpkg.com/nan/-/nan-2.6.2.tgz#e4ff34e6c95fdfb5aecc08de6596f43605a7db45" -node-fetch@^1.7.3: - version "1.7.3" - resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-1.7.3.tgz#980f6f72d85211a5347c6b2bc18c5b84c3eb47ef" - dependencies: - encoding "^0.1.11" - is-stream "^1.0.1" +node-fetch@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.0.0.tgz#982bba43ecd4f2922a29cc186a6bbb0bb73fcba6" node-pre-gyp@^0.6.36: version "0.6.36" @@ -1395,9 +1378,9 @@ preserve@^0.2.0: version "0.2.0" resolved "https://registry.yarnpkg.com/preserve/-/preserve-0.2.0.tgz#815ed1f6ebc65926f865b310c0713bcb3315ce4b" -prettier@^1.9.1: - version "1.9.1" - resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.9.1.tgz#41638a0d47c1efbd1b7d5a742aaa5548eab86d70" +prettier@^1.10.2: + version "1.10.2" + resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.10.2.tgz#1af8356d1842276a99a5b5529c82dd9e9ad3cc93" private@^0.1.6, private@^0.1.7: version "0.1.7"