GitBucket
4.23.0
Toggle navigation
Sign in
Files
Branches
1
Releases
Issues
Pull requests
Labels
Priorities
Milestones
Wiki
Forks
yhornisse
/
gqldoc
Browse code
新規作成
master
0 parent
commit
5bbb80f5931b74bfda0876f3d5b07f0080712831
yo-saito
authored
on 26 Dec 2018
Patch
Showing
7 changed files
LICENSE
README.md
gqldoc.js
main.js
package.json
query.gql
temp/index.ejs
Ignore Space
Show notes
View
LICENSE
0 → 100644
The MIT License (MIT) Copyright (c) Adam Stankiewicz <sheerun@sher.pl> (sheerun.net) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Ignore Space
Show notes
View
README.md
0 → 100644
Ignore Space
Show notes
View
gqldoc.js
0 → 100755
#!/usr/bin/env node /* * The MIT License (MIT) * * Copyright (c) 2018 Yoshimune Saito * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * */ /** * @param {node} a * @param {node} b */ function order(a, b){ if (a.name && a.name.value && b.name && b.name.value ){ return a.name.value > b.name.value; }else{ return a.kind > b.kind; } } /** * @param {description} node */ function showFieldDef(node){ let retval = ""; let type; let name; let desc = "unset"; if (node.description && node.description.kind && (node.description.kind == 'StringValue')){ desc = node.description.value; } if (node.name && node.name.value){ name = node.name.value; } if (node.type && node.type.name && node.type.name.value){ type = node.type.name.value; } if (type && name){ retval += " <td>" + name + "</td><td>" + type + "</td><td>" + desc + "</td>\n"; }else{ retval += "Gyaaaaaa!" + name + " type:" + type + "\n"; } return retval; } /** * @param {ObjectTypeDefinition} node */ function showTypeDef(node){ let retval = ""; if (!node || !node.kind || (node.kind!='ObjectTypeDefinition')){ return retval; } if (node.name && node.name.value){ retval += " <h3>" + node.name.value + "</h3>\n"; } if (node.description && node.description.value){ retval += " <p>" + node.description.value + "</p>\n"; } retval += " <table>\n"; if (node.fields){ retval += " <thead>\n"; retval += " <tr><th>Name</th><th>type</th><th>description</th></tr>\n"; retval += " </thead>\n"; retval += " <tbody>\n"; for (let x of node.fields){ if (x.kind && (x.kind = 'FieldDefinition')){ retval += " <tr>\n"; retval += showFieldDef(x) + "\n"; retval += " </tr>\n"; } } retval += " </tbody>\n"; retval += " </table>\n"; } return retval; } /** * @param {FragmentDefinition} node */ function showFragDef(node){ let retval = ""; if (!node.selectionSet || !node.selectionSet.selections || !node.name || !node.name.value){ return ""; } retval += " <h3>" + node.name.value + "</h3>\n"; retval += " <ul>\n"; for (let v of node.selectionSet.selections){ if (v.name && v.name.value){ retval += " <li>" + v.name.value + "</li>\n"; } } retval += " </ul>\n"; return retval; } /** * @param {OperationDefinition} node */ function showOpDef(node){ let = ""; if (!node || !node.kind || (node.kind!='OperationDefinition')){ return ""; } if (node.name && node.name.value){ retval += "<h3>" + node.name.value + "</h3>\n"; } // TODO retval += "TODO\n" retval += node; return retval; } /** * @param {Document} node */ function showDocument(node){ let retval = ''; let ary; if (node && node.kind && node.definitions && (node.kind = 'Document')){ // Type retval += " <h2>Type</h2>\n"; ary = node.definitions.filter(v => v.kind && v.kind=='ObjectTypeDefinition'); if (ary.length){ for (let v of ary.sort(order)){ retval += showTypeDef(v); } }else{ retval += " <p>未定義</p>\n"; } retval += "\n"; // Operation retval += " <h2>Operation</h2>\n"; ary = node.definitions.filter(v => v.kind && v.kind=='OperationDefinition'); if (ary.length){ for (let v of ary.sort(order)){ // TODO retval += showFragDef(v); } }else{ retval += " <p>未定義</p>\n"; } retval += "\n"; // Fragment retval += " <h2>Fragment</h2>\n"; ary = node.definitions.filter(v => v.kind && v.kind=='FragmentDefinition'); if (ary.length){ for (let v of ary.sort(order)){ retval += showFragDef(v); } }else{ retval += " <p>未定義</p>\n"; } retval += "\n"; retval += " <h2>Others</h2>\n"; for (let x of node.definitions.filter(v => ["ObjectTypeDefinition", "FragmentDefinition", "OperationDefinition"].indexOf(v.kind)==-1) .sort((a,b) => (a.kind > b.kind))){ retval += x + "\n"; retval += "<hr>\n"; } } return retval; } if (typeof exports != 'undefined'){ exports.showDocument = showDocument; }
Ignore Space
Show notes
View
main.js
0 → 100755
#!/usr/bin/env node let fetch = require('isomorphic-fetch'); let path = require('path'); let meow = require('meow'); let fs = require('fs'); let GraphQL = require('graphql'); let gqldoc = require('./gqldoc'); let ejs = require('ejs'); let strip = require('strip-bom'); let graphql = GraphQL.graphql; let parse = GraphQL.parse; /* */ function terminate () { console.error(cli.help); process.exit(1); } /* */ let cli = meow(` Options: -g --graphql use graphql schema language as input -v --verbose print introspection result -a --auth set Authorization header for graphql server -t --title HTML title Usage: $ gqldoc [param] Examples: $ gqldoc path/to/schema.gql -g `, { flags: { verbose: { type: 'boolean', alias: 'v' }, graphql: { type: 'boolean', alias: 'g' }, auth: { type: 'string', alias: 'a' }, title: { type: 'string', alias: 't' } } }); if (cli.flags.graphql && cli.input[0]){ fs.readFile("./temp/index.ejs", "utf-8", function(err, temp){ fs.readFile(cli.input[0], "utf-8", function(err, x){ let str = gqldoc.showDocument(parse(x)); console.log(ejs.render(temp, { title:"Schema:" + path.basename(cli.input[0]), main: str })); }) }); }else if (cli.input[0] && cli.input[0].slice(0, 4) === 'http'){ let headers = { 'Accept': 'application/json', 'Content-Type': 'application/json' }; if (cli.flags.auth) { headers.Authorization = cli.flags.auth; } p = fetch(cli.input[0], { method: 'POST', headers: headers, body: JSON.stringify({"query":fs.readFileSync('./query.gql', 'utf-8')}) }).then(function (res) { if (!res.ok && cli.flags.verbose) { console.log('Request for schema failed w/ ' + res.status + ' (' + res.statusText + ')'); } return res.text(); }).then(function(text){ // TODO console.log(text); }); }else{ terminate(); }
Ignore Space
Show notes
View
package.json
0 → 100644
{ "name": "gqldoc", "version": "0.1.0", "description": "GraphQLのスキーマ情報からドキュメントを作成", "main": "main.js", "dependencies": { "ejs": "^2.6.1", "fs": "0.0.1-security", "graphql": "^14.0.2", "isomorphic-fetch": "^2.2.1", "meow": "^5.0.0" }, "devDependencies": {}, "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, "repository": { "type": "git", "url": "git+https://github.com/yhornisse/gqldoc.git" }, "keywords": [ "graphql", "javascript" ], "author": "Yoshimune Saito", "license": "MIT", "bugs": { "url": "https://github.com/yhornisse/gqldoc/issues" }, "homepage": "https://github.com/yhornisse/gqldoc#readme" }
Ignore Space
Show notes
View
query.gql
0 → 100644
query IntrospectionQuery { __schema { queryType { name } mutationType { name } subscriptionType { name } types { ...FullType } directives { name description locations args { ...InputValue } } } } fragment FullType on __Type { kind name description fields(includeDeprecated: true) { name description args { ...InputValue } type { ...TypeRef } isDeprecated deprecationReason } inputFields { ...InputValue } interfaces { ...TypeRef } enumValues(includeDeprecated: true) { name description isDeprecated deprecationReason } possibleTypes { ...TypeRef } } fragment InputValue on __InputValue { name description type { ...TypeRef } defaultValue } fragment TypeRef on __Type { kind name ofType { kind name ofType { kind name ofType { kind name ofType { kind name ofType { kind name ofType { kind name ofType { kind name } } } } } } } }
Ignore Space
Show notes
View
temp/index.ejs
0 → 100644
<!doctype html> <html> <head> <title><%= title %></title> </head> <body> <h1><%= title %></h1> <%- main %> </body> </html>
Show line notes below