mirror of
https://github.com/ritz078/transform.git
synced 2026-11-22 09:01:31 +03:00
added graphql schema to typescript conversion
This commit is contained in:
1 parent
eaffa3f8d7
commit
5fe112e346
8 files changed
+6122
-38
No files matched your search
@@ -45,7 +45,8 @@ type Props = {
|
||||
pathname: string,
|
||||
initialCheckboxValue: boolean,
|
||||
leftTitle: string,
|
||||
rightTitle: string
|
||||
rightTitle: string,
|
||||
prettifyRightPanel: ?boolean
|
||||
};
|
||||
|
||||
export default class ConversionPanel extends PureComponent {
|
||||
@@ -54,7 +55,8 @@ export default class ConversionPanel extends PureComponent {
|
||||
static defaultProps = {
|
||||
leftMode: "javascript",
|
||||
rightMode: "javascript",
|
||||
pathname: "/"
|
||||
pathname: "/",
|
||||
prettifyRightPanel: true
|
||||
};
|
||||
|
||||
constructor(props) {
|
||||
@@ -159,7 +161,8 @@ export default class ConversionPanel extends PureComponent {
|
||||
checkboxText,
|
||||
initialCheckboxValue,
|
||||
leftTitle,
|
||||
rightTitle
|
||||
rightTitle,
|
||||
prettifyRightPanel
|
||||
} = this.props;
|
||||
const { infoType, resultValue, value, info } = this.state;
|
||||
|
||||
@@ -354,7 +357,7 @@ export default class ConversionPanel extends PureComponent {
|
||||
name="code"
|
||||
readOnly
|
||||
value={
|
||||
rightMode !== "rust"
|
||||
prettifyRightPanel
|
||||
? window.js_beautify(resultValue, { e4x: true })
|
||||
: resultValue
|
||||
}
|
||||
|
||||
+56
-7
@@ -86,12 +86,52 @@ const x = [
|
||||
]
|
||||
},
|
||||
{
|
||||
category: 'Scala',
|
||||
iconName: 'icon-scala',
|
||||
content: [{
|
||||
label: 'JSON to Scala case class',
|
||||
path: '/json-to-scala-case-class'
|
||||
}]
|
||||
category: "Scala",
|
||||
iconName: "icon-scala",
|
||||
content: [
|
||||
{
|
||||
label: "JSON to Scala case class",
|
||||
path: "/json-to-scala-case-class"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
category: "GraphQL",
|
||||
icon: (
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 400 400">
|
||||
<path
|
||||
fill="#ffffff"
|
||||
d="M57.468 302.66l-14.376-8.3 160.15-277.38 14.376 8.3z"
|
||||
/>
|
||||
<path fill="#ffffff" d="M39.8 272.2h320.3v16.6H39.8z" />
|
||||
<path
|
||||
fill="#ffffff"
|
||||
d="M206.348 374.026l-160.21-92.5 8.3-14.376 160.21 92.5zM345.522 132.947l-160.21-92.5 8.3-14.376 160.21 92.5z"
|
||||
/>
|
||||
<path
|
||||
fill="#ffffff"
|
||||
d="M54.482 132.883l-8.3-14.375 160.21-92.5 8.3 14.376z"
|
||||
/>
|
||||
<path
|
||||
fill="#ffffff"
|
||||
d="M342.568 302.663l-160.15-277.38 14.376-8.3 160.15 277.38zM52.5 107.5h16.6v185H52.5zM330.9 107.5h16.6v185h-16.6z"
|
||||
/>
|
||||
<path
|
||||
fill="#ffffff"
|
||||
d="M203.522 367l-7.25-12.558 139.34-80.45 7.25 12.557z"
|
||||
/>
|
||||
<path
|
||||
fill="#ffffff"
|
||||
d="M369.5 297.9c-9.6 16.7-31 22.4-47.7 12.8-16.7-9.6-22.4-31-12.8-47.7 9.6-16.7 31-22.4 47.7-12.8 16.8 9.7 22.5 31 12.8 47.7M90.9 137c-9.6 16.7-31 22.4-47.7 12.8-16.7-9.6-22.4-31-12.8-47.7 9.6-16.7 31-22.4 47.7-12.8 16.7 9.7 22.4 31 12.8 47.7M30.5 297.9c-9.6-16.7-3.9-38 12.8-47.7 16.7-9.6 38-3.9 47.7 12.8 9.6 16.7 3.9 38-12.8 47.7-16.8 9.6-38.1 3.9-47.7-12.8M309.1 137c-9.6-16.7-3.9-38 12.8-47.7 16.7-9.6 38-3.9 47.7 12.8 9.6 16.7 3.9 38-12.8 47.7-16.7 9.6-38.1 3.9-47.7-12.8M200 395.8c-19.3 0-34.9-15.6-34.9-34.9 0-19.3 15.6-34.9 34.9-34.9 19.3 0 34.9 15.6 34.9 34.9 0 19.2-15.6 34.9-34.9 34.9M200 74c-19.3 0-34.9-15.6-34.9-34.9 0-19.3 15.6-34.9 34.9-34.9 19.3 0 34.9 15.6 34.9 34.9 0 19.3-15.6 34.9-34.9 34.9"
|
||||
/>
|
||||
</svg>
|
||||
),
|
||||
content: [
|
||||
{
|
||||
label: "GraphQL schema to TypeScript",
|
||||
path: "/graphql-to-typescript"
|
||||
}
|
||||
]
|
||||
}
|
||||
];
|
||||
|
||||
@@ -321,6 +361,12 @@ export default class Layout extends PureComponent {
|
||||
border-bottom: 1px solid #252525;
|
||||
}
|
||||
|
||||
.Collapsible__trigger svg {
|
||||
width: 14px;
|
||||
height: 14px;
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
.rc-collapse-content-box a {
|
||||
display: block;
|
||||
color: #fff;
|
||||
@@ -361,7 +407,10 @@ export default class Layout extends PureComponent {
|
||||
headerClass="Collapsible__trigger"
|
||||
header={
|
||||
<span>
|
||||
<i className={route.iconName} /> {route.category}
|
||||
{route.iconName
|
||||
? <i className={route.iconName} />
|
||||
: route.icon}{" "}
|
||||
{route.category}
|
||||
</span>
|
||||
}
|
||||
>
|
||||
|
||||
@@ -15,6 +15,8 @@
|
||||
"author": "",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@gql2ts/from-schema": "^1.2.1",
|
||||
"@gql2ts/language-flow": "^1.2.1",
|
||||
"@tsuyoshiwada/htmltojsx": "^0.0.4",
|
||||
"babel-standalone": "^6.25.0",
|
||||
"babili-webpack-plugin": "^0.1.2",
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
import React, { PureComponent } from "react";
|
||||
import { schemaToInterfaces } from "@gql2ts/from-schema";
|
||||
import Layout from "../components/Layout";
|
||||
import ConversionPanel from "../components/ConversionPanel";
|
||||
import schema from "../utils/graphql-schema";
|
||||
|
||||
export default class Json2Ts extends PureComponent {
|
||||
state = {
|
||||
legacyTS: false
|
||||
};
|
||||
|
||||
getTransformedValue = newValue => {
|
||||
console.log(newValue);
|
||||
return schemaToInterfaces(JSON.parse(newValue), {
|
||||
legacy: this.state.legacyTS
|
||||
});
|
||||
};
|
||||
|
||||
render() {
|
||||
return (
|
||||
<Layout pathname={this.props.url.pathname}>
|
||||
<ConversionPanel
|
||||
leftTitle="GraphQL Schema"
|
||||
rightTitle="TypeScript Definition"
|
||||
getTransformedValue={this.getTransformedValue}
|
||||
name={"graphql_to_typescript"}
|
||||
defaultText={schema}
|
||||
leftMode="typescript"
|
||||
rightMode="typescript"
|
||||
url={this.props.url}
|
||||
onCheckboxChange={(checked, cb) =>
|
||||
this.setState({ legacyTS: checked }, cb)}
|
||||
checkboxText="Support TypeScript 1.x"
|
||||
prettifyRightPanel={false}
|
||||
/>
|
||||
</Layout>
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -30,6 +30,7 @@ export default class Json2Ts extends PureComponent {
|
||||
leftMode="json"
|
||||
rightMode="rust"
|
||||
url={this.props.url}
|
||||
prettifyRightPanel={false}
|
||||
/>
|
||||
</Layout>
|
||||
);
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -6,16 +6,16 @@ var is;
|
||||
var hasOwn = ObjProto.hasOwnProperty;
|
||||
var index_of = ArrayProto.indexOf
|
||||
? function(arr, val) {
|
||||
return arr.indexOf(val);
|
||||
}
|
||||
: function(arr, val) {
|
||||
for (var i = 0, l = arr.length; i < l; i++) {
|
||||
if (arr[i] === val) {
|
||||
return i;
|
||||
}
|
||||
return arr.indexOf(val);
|
||||
}
|
||||
return -1;
|
||||
};
|
||||
: function(arr, val) {
|
||||
for (var i = 0, l = arr.length; i < l; i++) {
|
||||
if (arr[i] === val) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
};
|
||||
function string(s) {
|
||||
return typeof s === "string" || s instanceof String;
|
||||
}
|
||||
@@ -61,11 +61,11 @@ var is;
|
||||
is.element =
|
||||
typeof HTMLElement !== "undefined"
|
||||
? function(e) {
|
||||
return e instanceof HTMLElement;
|
||||
}
|
||||
return e instanceof HTMLElement;
|
||||
}
|
||||
: function(e) {
|
||||
return !!(e && e.nodeType === 1);
|
||||
};
|
||||
return !!(e && e.nodeType === 1);
|
||||
};
|
||||
function numeric(n) {
|
||||
return !isNaN(parseFloat(n)) && isFinite(n);
|
||||
}
|
||||
@@ -324,17 +324,14 @@ var Json2dts = (function() {
|
||||
return this.classes;
|
||||
};
|
||||
Json2dts.prototype.getCode = function(flow) {
|
||||
const _this = this
|
||||
let output
|
||||
const classes = {}
|
||||
const outputModule = this.moduleName !== ''
|
||||
const interfaceTab = outputModule ? '\t' : ''
|
||||
const propertyTab = interfaceTab + '\t'
|
||||
const _this = this;
|
||||
let output;
|
||||
const classes = {};
|
||||
const outputModule = this.moduleName !== "";
|
||||
const interfaceTab = outputModule ? "\t" : "";
|
||||
const propertyTab = interfaceTab + "\t";
|
||||
Object.keys(this.classes).map(function(clsName) {
|
||||
output =
|
||||
interfaceTab + 'case class ' +
|
||||
clsName +
|
||||
" (\n";
|
||||
output = interfaceTab + "case class " + clsName + " (\n";
|
||||
Object.keys(_this.classes[clsName]).map(function(key) {
|
||||
output +=
|
||||
propertyTab + key + ": " + _this.classes[clsName][key] + ",\n";
|
||||
@@ -350,16 +347,16 @@ var Json2dts = (function() {
|
||||
return output;
|
||||
};
|
||||
Json2dts.prototype.analyse_object = function(obj, objectName) {
|
||||
const _this = this
|
||||
const _this = this;
|
||||
if (objectName === void 0) {
|
||||
objectName = "json";
|
||||
}
|
||||
objectName = this.getInterfaceType(objectName, obj);
|
||||
this.classes[objectName] = this.classes[objectName] || {};
|
||||
Object.keys(obj).map(function(key) {
|
||||
let type = 'string'
|
||||
const sha = ''
|
||||
const value = obj[key]
|
||||
let type = "string";
|
||||
const sha = "";
|
||||
const value = obj[key];
|
||||
switch (true) {
|
||||
case is.string(value):
|
||||
type = Types.STRING;
|
||||
|
||||
@@ -2,6 +2,35 @@
|
||||
# yarn lockfile v1
|
||||
|
||||
|
||||
"@gql2ts/from-schema@^1.2.1":
|
||||
version "1.2.1"
|
||||
resolved "https://registry.yarnpkg.com/@gql2ts/from-schema/-/from-schema-1.2.1.tgz#eed6d82164ba85546d40efee9f55d4852e809634"
|
||||
dependencies:
|
||||
"@gql2ts/language-typescript" "^1.2.1"
|
||||
"@gql2ts/util" "^1.2.1"
|
||||
graphql "^0.10.5"
|
||||
|
||||
"@gql2ts/language-flow@^1.2.1":
|
||||
version "1.2.1"
|
||||
resolved "https://registry.yarnpkg.com/@gql2ts/language-flow/-/language-flow-1.2.1.tgz#ccd33f5b4f52e803cc89ed605220a10779e8c2e3"
|
||||
dependencies:
|
||||
"@gql2ts/language-typescript" "^1.2.1"
|
||||
"@gql2ts/util" "^1.2.1"
|
||||
|
||||
"@gql2ts/language-typescript@^1.2.1":
|
||||
version "1.2.1"
|
||||
resolved "https://registry.yarnpkg.com/@gql2ts/language-typescript/-/language-typescript-1.2.1.tgz#e45e641e76721d038af0f2e1875c7420926347f1"
|
||||
dependencies:
|
||||
"@gql2ts/util" "^1.2.1"
|
||||
humps "^2.0.0"
|
||||
typescript "^2.2.2"
|
||||
|
||||
"@gql2ts/util@^1.2.1":
|
||||
version "1.2.1"
|
||||
resolved "https://registry.yarnpkg.com/@gql2ts/util/-/util-1.2.1.tgz#fad2d545051aeded1bf3ede94139ad52b9003a66"
|
||||
dependencies:
|
||||
graphql "^0.10.5"
|
||||
|
||||
"@tsuyoshiwada/htmltojsx@^0.0.4":
|
||||
version "0.0.4"
|
||||
resolved "https://registry.yarnpkg.com/@tsuyoshiwada/htmltojsx/-/htmltojsx-0.0.4.tgz#73e86b580183ba680f53bc53e84f19d3378f8857"
|
||||
@@ -2140,6 +2169,12 @@ graceful-fs@^4.1.2, graceful-fs@^4.1.4:
|
||||
version "1.0.1"
|
||||
resolved "https://registry.yarnpkg.com/graceful-readlink/-/graceful-readlink-1.0.1.tgz#4cafad76bc62f02fa039b2f94e9a3dd3a391a725"
|
||||
|
||||
graphql@^0.10.5:
|
||||
version "0.10.5"
|
||||
resolved "https://registry.yarnpkg.com/graphql/-/graphql-0.10.5.tgz#c9be17ca2bdfdbd134077ffd9bbaa48b8becd298"
|
||||
dependencies:
|
||||
iterall "^1.1.0"
|
||||
|
||||
gzip-size@^3.0.0:
|
||||
version "3.0.0"
|
||||
resolved "https://registry.yarnpkg.com/gzip-size/-/gzip-size-3.0.0.tgz#546188e9bdc337f673772f81660464b389dce520"
|
||||
@@ -2273,6 +2308,10 @@ https-browserify@0.0.1:
|
||||
version "0.0.1"
|
||||
resolved "https://registry.yarnpkg.com/https-browserify/-/https-browserify-0.0.1.tgz#3f91365cabe60b77ed0ebba24b454e3e09d95a82"
|
||||
|
||||
humps@^2.0.0:
|
||||
version "2.0.1"
|
||||
resolved "https://registry.yarnpkg.com/humps/-/humps-2.0.1.tgz#dd02ea6081bd0568dc5d073184463957ba9ef9aa"
|
||||
|
||||
iconv-lite@^0.4.17, iconv-lite@~0.4.13:
|
||||
version "0.4.18"
|
||||
resolved "https://registry.yarnpkg.com/iconv-lite/-/iconv-lite-0.4.18.tgz#23d8656b16aae6742ac29732ea8f0336a4789cf2"
|
||||
@@ -2497,6 +2536,10 @@ isstream@~0.1.2:
|
||||
version "0.1.2"
|
||||
resolved "https://registry.yarnpkg.com/isstream/-/isstream-0.1.2.tgz#47e63f7af55afa6f92e1500e690eb8b8529c099a"
|
||||
|
||||
iterall@^1.1.0:
|
||||
version "1.1.1"
|
||||
resolved "https://registry.yarnpkg.com/iterall/-/iterall-1.1.1.tgz#f7f0af11e9a04ec6426260f5019d9fcca4d50214"
|
||||
|
||||
js-beautify@^1.6.12:
|
||||
version "1.6.14"
|
||||
resolved "https://registry.yarnpkg.com/js-beautify/-/js-beautify-1.6.14.tgz#d3b8f7322d02b9277d58bd238264c327e58044cd"
|
||||
@@ -4086,6 +4129,10 @@ type-of-is@^3.4.0:
|
||||
version "3.5.1"
|
||||
resolved "https://registry.yarnpkg.com/type-of-is/-/type-of-is-3.5.1.tgz#eec2fc89b828dbf9900eb6416eee30f4fe0fcd31"
|
||||
|
||||
typescript@^2.2.2:
|
||||
version "2.5.1"
|
||||
resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.5.1.tgz#ce7cc93ada3de19475cc9d17e3adea7aee1832aa"
|
||||
|
||||
ua-parser-js@^0.7.9:
|
||||
version "0.7.12"
|
||||
resolved "https://registry.yarnpkg.com/ua-parser-js/-/ua-parser-js-0.7.12.tgz#04c81a99bdd5dc52263ea29d24c6bf8d4818a4bb"
|
||||
|
||||
Reference in new issue
Block a user