Skip to content

Commit

Permalink
GraphQL v0.13
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul Le Cam committed Feb 16, 2018
1 parent 46acacc commit c747327
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 122 deletions.
9 changes: 5 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -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
Expand Down
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ graphql-fetch-schema <url> [options]
-g, --graphql write schema.graphql file
-j, --json write schema.json file
-o, --output <directory> write to specified directory
-s, --sort sort field keys
```

## API usage
Expand All @@ -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
Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@
},
"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",
"babel-plugin-syntax-flow": "^6.18.0",
"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"
}
}
2 changes: 0 additions & 2 deletions src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,11 @@ program
.option('-c, --cookie <cookie>', 'pass additional Cookie header')
.option('-j, --json', 'write schema.json file')
.option('-o, --output <directory>', 'write to specified directory')
.option('-s, --sort', 'sort field keys')
.parse(process.argv)

run(program.args[0], {
graphql: !!program.graphql,
json: !!program.json,
outputPath: program.output,
cookie: program.cookie,
sort: !!program.sort,
})
68 changes: 2 additions & 66 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -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'

Expand All @@ -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) {
Expand All @@ -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) {
Expand Down
55 changes: 19 additions & 36 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"

[email protected]:
version "0.0.1"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit c747327

Please sign in to comment.