Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Refactor TypeScript plugins #1353

Merged
merged 178 commits into from
Mar 14, 2019
Merged
Changes from 1 commit
Commits
Show all changes
178 commits
Select commit Hold shift + click to select a range
6b5689e
WIP, move common visitor to separate package, clear flow package, add…
dotansimha Feb 25, 2019
0af742f
fix other flow plugin
dotansimha Feb 25, 2019
0024359
rebase without flow code
dotansimha Feb 25, 2019
812ca81
wip typescript package
dotansimha Feb 25, 2019
fa1ed3d
added validation for ts files
dotansimha Feb 25, 2019
72e83d5
wip
dotansimha Feb 25, 2019
c039ea3
done with basic typescript package
dotansimha Feb 26, 2019
65b7b03
WIP: move all common code from flow-documents.
dotansimha Feb 26, 2019
829e464
all green on typescript-documents and flow-documents
dotansimha Feb 26, 2019
86b0bd7
added tsc compilation to tests
dotansimha Feb 26, 2019
e431c8c
fix for arguments and variables
dotansimha Feb 26, 2019
2d1648b
wip resolvers
dotansimha Feb 27, 2019
4b3858b
implement common resolvers package
dotansimha Feb 28, 2019
af84418
fixed tests for typescript packages
dotansimha Feb 28, 2019
4d387c0
added missing features for typescript plugin
dotansimha Feb 28, 2019
966a535
added missing features
dotansimha Feb 28, 2019
35695be
added immutableTypes to typescript-documents
dotansimha Feb 28, 2019
d806787
fixes
dotansimha Feb 28, 2019
a11748a
update versions
dotansimha Mar 1, 2019
f085605
update lock file
dotansimha Mar 1, 2019
e884404
#1369 Duplicated type when fields are named the same as operation types
kamilkisiela Mar 1, 2019
1cbb746
#1380 Include __typename in fragments and metadata fields
kamilkisiela Mar 1, 2019
8c44d99
#1355 apply typesPrefix to enums in typescript-documents
kamilkisiela Mar 1, 2019
eadbfc9
refactor graphql-codegen-typescript-graphql-files-modules
dotansimha Mar 3, 2019
53b1327
wip
dotansimha Mar 4, 2019
59e566c
WIP
dotansimha Mar 4, 2019
715ea23
wip react-apollo
dotansimha Mar 4, 2019
02a4e93
wip react-apollo
dotansimha Mar 4, 2019
1f03407
fixes for react-apollo
dotansimha Mar 5, 2019
65b6c28
removed old code
dotansimha Mar 5, 2019
eb2446f
removed old example
dotansimha Mar 5, 2019
6d489df
added ts compilation to tests
dotansimha Mar 5, 2019
e5ee2e0
fixes
dotansimha Mar 5, 2019
ae4be8a
done with apollo angular
dotansimha Mar 5, 2019
40838b9
fix ci
dotansimha Mar 5, 2019
ef03340
Add IResolvers & IDirectiveResolvers
ardatan Mar 5, 2019
3c236f8
Fix flow
ardatan Mar 5, 2019
4e88769
#1400 Include used introspection types in based on documents
kamilkisiela Mar 5, 2019
ce418f6
Add Scalars to IResolvers
ardatan Mar 5, 2019
0502039
Fix IDirectiveResolvers
ardatan Mar 5, 2019
7ce6a6f
Naming convention
kamilkisiela Mar 5, 2019
2f6d69d
Apply Naming Convention to flow
kamilkisiela Mar 5, 2019
e619b89
Include objects
kamilkisiela Mar 5, 2019
0f9088f
Fix missing types and enums
kamilkisiela Mar 5, 2019
3b09205
Lazy Dotan
kamilkisiela Mar 5, 2019
0517f4c
Fix kind
kamilkisiela Mar 5, 2019
7293787
Fix tests
ardatan Mar 5, 2019
be0548e
Fix an issue with double prefix
kamilkisiela Mar 5, 2019
5933da9
Fix incorrect test in flow-documents
kamilkisiela Mar 5, 2019
86355be
Fix double i
kamilkisiela Mar 5, 2019
26f3503
Fix DirectiveResolver signature
ardatan Mar 5, 2019
d41b704
fix stupid mistake
kamilkisiela Mar 5, 2019
ba991e7
Fix ts-documents ii issue
kamilkisiela Mar 5, 2019
c608c62
update lockfile
dotansimha Mar 6, 2019
1690e3e
Refactor stencil-apollo
ardatan Mar 6, 2019
6863e55
Merge pull request #1419 from dotansimha/refactor/stencil-apollo
ardatan Mar 6, 2019
dccbd43
Enable tree-shaking
ardatan Mar 6, 2019
a4067f8
Introduce graphql-codegen-testing
ardatan Mar 6, 2019
a00131b
Remove old templates
ardatan Mar 7, 2019
19a5d6b
remove esModuleInterop and use dynamic import instead of require to i…
ardatan Mar 7, 2019
3121e7f
WIP, move common visitor to separate package, clear flow package, add…
dotansimha Feb 25, 2019
ad32bf0
fix other flow plugin
dotansimha Feb 25, 2019
638f68d
rebase without flow code
dotansimha Feb 25, 2019
44b80d7
wip typescript package
dotansimha Feb 25, 2019
72f756b
added validation for ts files
dotansimha Feb 25, 2019
7b62aef
wip
dotansimha Feb 25, 2019
0a97949
done with basic typescript package
dotansimha Feb 26, 2019
a77ccb7
WIP: move all common code from flow-documents.
dotansimha Feb 26, 2019
0b943c1
all green on typescript-documents and flow-documents
dotansimha Feb 26, 2019
d6cf20f
added tsc compilation to tests
dotansimha Feb 26, 2019
04f696e
fix for arguments and variables
dotansimha Feb 26, 2019
3232329
wip resolvers
dotansimha Feb 27, 2019
978d0d2
implement common resolvers package
dotansimha Feb 28, 2019
c87152b
fixed tests for typescript packages
dotansimha Feb 28, 2019
45b2e4e
added missing features for typescript plugin
dotansimha Feb 28, 2019
a326c17
added missing features
dotansimha Feb 28, 2019
2396ace
added immutableTypes to typescript-documents
dotansimha Feb 28, 2019
be0d009
fixes
dotansimha Feb 28, 2019
32bbb7a
update versions
dotansimha Mar 1, 2019
a0f0188
update lock file
dotansimha Mar 1, 2019
28fe025
#1369 Duplicated type when fields are named the same as operation types
kamilkisiela Mar 1, 2019
009665e
#1380 Include __typename in fragments and metadata fields
kamilkisiela Mar 1, 2019
d8a3362
#1355 apply typesPrefix to enums in typescript-documents
kamilkisiela Mar 1, 2019
a520fbc
refactor graphql-codegen-typescript-graphql-files-modules
dotansimha Mar 3, 2019
913de21
wip
dotansimha Mar 4, 2019
29a5c1c
WIP
dotansimha Mar 4, 2019
f2940ff
wip react-apollo
dotansimha Mar 4, 2019
455f536
wip react-apollo
dotansimha Mar 4, 2019
99b312a
fixes for react-apollo
dotansimha Mar 5, 2019
86eaf3e
removed old code
dotansimha Mar 5, 2019
d202f0f
removed old example
dotansimha Mar 5, 2019
d54472b
added ts compilation to tests
dotansimha Mar 5, 2019
95c6010
fixes
dotansimha Mar 5, 2019
927c47b
done with apollo angular
dotansimha Mar 5, 2019
f83c13f
fix ci
dotansimha Mar 5, 2019
1032441
Add IResolvers & IDirectiveResolvers
ardatan Mar 5, 2019
c4eb825
Fix flow
ardatan Mar 5, 2019
076fbf5
#1400 Include used introspection types in based on documents
kamilkisiela Mar 5, 2019
00b25b7
Add Scalars to IResolvers
ardatan Mar 5, 2019
06a8adf
Fix IDirectiveResolvers
ardatan Mar 5, 2019
bdefc7e
Naming convention
kamilkisiela Mar 5, 2019
1551b89
Apply Naming Convention to flow
kamilkisiela Mar 5, 2019
baaa2e4
Include objects
kamilkisiela Mar 5, 2019
e3873d7
Fix missing types and enums
kamilkisiela Mar 5, 2019
776da58
Lazy Dotan
kamilkisiela Mar 5, 2019
2fea7f2
Fix kind
kamilkisiela Mar 5, 2019
adb2f63
Fix tests
ardatan Mar 5, 2019
802255c
Fix an issue with double prefix
kamilkisiela Mar 5, 2019
0da9e35
Fix incorrect test in flow-documents
kamilkisiela Mar 5, 2019
854e358
Fix double i
kamilkisiela Mar 5, 2019
fe7ea6b
Fix DirectiveResolver signature
ardatan Mar 5, 2019
fbf59ce
fix stupid mistake
kamilkisiela Mar 5, 2019
32e9e5b
Fix ts-documents ii issue
kamilkisiela Mar 5, 2019
8c4a495
update lockfile
dotansimha Mar 6, 2019
9a9a205
Make sure bug with useFlowReadOnlyTypes on Enums is fixed #1413
kamilkisiela Mar 6, 2019
67644ee
Refactor stencil-apollo
ardatan Mar 6, 2019
e0a0ea7
wip mongo
dotansimha Mar 11, 2019
3505b21
Merge branch 'refactor/typescript' of github.com:dotansimha/graphql-c…
ardatan Mar 11, 2019
28b2921
fix
ardatan Mar 11, 2019
83524b7
Merge branch 'refactor/typescript' into refactor/tree-shaking
ardatan Mar 11, 2019
a6eded5
fixes
dotansimha Mar 11, 2019
05886e4
fixes
ardatan Mar 11, 2019
f78652f
Merge branch 'refactor/typescript' of github.com:dotansimha/graphql-c…
ardatan Mar 11, 2019
34e4082
cleanup
dotansimha Mar 11, 2019
6ec94bd
empty commit
dotansimha Mar 11, 2019
c197dd8
fix
dotansimha Mar 11, 2019
88c21dc
gql-gen init
kamilkisiela Mar 11, 2019
eaadb84
Merge branch 'refactor/typescript' of github.com:dotansimha/graphql-c…
kamilkisiela Mar 11, 2019
14dc463
fix
ardatan Mar 11, 2019
8cfde08
Merge branch 'refactor/typescript' of github.com:dotansimha/graphql-c…
ardatan Mar 11, 2019
5d4e608
Merge branch 'refactor/typescript' into refactor/tree-shaking
ardatan Mar 11, 2019
b8a815c
Merge pull request #1417 from dotansimha/apply/init
dotansimha Mar 11, 2019
0d1c696
remove all pretest scripts
dotansimha Mar 11, 2019
2da4f26
Support schema stitching in typescript-resolvers
kamilkisiela Mar 11, 2019
aee3ac6
Merge pull request #1439 from dotansimha/feat/resolvers-stitching
dotansimha Mar 11, 2019
2d4a70f
Schema Definition Object was printed as object
kamilkisiela Mar 11, 2019
3f859ab
Merge pull request #1441 from dotansimha/fix/schema-definition-as-object
dotansimha Mar 11, 2019
6f654a3
WIP mongo plugin
dotansimha Mar 12, 2019
813c8d3
Merge branch 'refactor/typescript' of github.com:dotansimha/graphql-c…
dotansimha Mar 12, 2019
7276237
No core package
kamilkisiela Mar 12, 2019
02a522e
Old stuff
kamilkisiela Mar 12, 2019
82e27c4
comment
kamilkisiela Mar 12, 2019
df8aa0d
Merge pull request #1446 from dotansimha/refactor/no-core
dotansimha Mar 12, 2019
f5d41c9
fix graphql dep conflict for jest
ardatan Mar 12, 2019
b9599e1
Merge branch 'refactor/typescript' of github.com:dotansimha/graphql-c…
ardatan Mar 12, 2019
9114d18
Merge branch 'refactor/typescript' into refactor/tree-shaking
ardatan Mar 12, 2019
f7d3368
DONE
ardatan Mar 12, 2019
d823090
Optimize website for lazy-loading
ardatan Mar 12, 2019
3e3181f
Fix custom plugin loading
ardatan Mar 12, 2019
22e1155
Add cjs proxy to flow-operations
ardatan Mar 12, 2019
fdbb791
Update examples
ardatan Mar 12, 2019
2b103fb
Fix Stencil-Apollo demo
ardatan Mar 12, 2019
52db8d2
Use graphql-codegen-testing for mongodb plugin
ardatan Mar 12, 2019
cbaa90b
Merge pull request #1420 from dotansimha/refactor/tree-shaking
dotansimha Mar 13, 2019
df8117c
Merge branch 'master' into refactor/typescript
dotansimha Mar 13, 2019
4551613
fixes
dotansimha Mar 13, 2019
e359e2c
fixes
dotansimha Mar 13, 2019
8a247e2
Docs WIP
kamilkisiela Mar 12, 2019
7c247a8
More docs
kamilkisiela Mar 13, 2019
8e3376c
Repo's readme
kamilkisiela Mar 13, 2019
16bda3d
added tests
dotansimha Mar 14, 2019
8cc09fa
Merge branch 'master' into refactor/typescript
dotansimha Mar 14, 2019
6f29999
Merge pull request #1447 from dotansimha/refactor/docs
dotansimha Mar 14, 2019
825c889
update docs
dotansimha Mar 14, 2019
515e2e1
Generate different bundles instead of esm package (#1460)
ardatan Mar 14, 2019
ddf5d60
cleanup for jest config
dotansimha Mar 14, 2019
411d62e
Merge branch 'refactor/typescript' of github.com:dotansimha/graphql-c…
dotansimha Mar 14, 2019
37f8ada
move testing package to utils dir
dotansimha Mar 14, 2019
ec24200
Move part of logic into a separate package (#1458)
kamilkisiela Mar 14, 2019
c22538c
Merge branch 'refactor/typescript' of github.com:dotansimha/graphql-c…
dotansimha Mar 14, 2019
c69ca8b
Remove old-templates (#1461)
kamilkisiela Mar 14, 2019
4859306
fixes
dotansimha Mar 14, 2019
d705104
Merge branch 'refactor/typescript' of github.com:dotansimha/graphql-c…
dotansimha Mar 14, 2019
bc19151
remove old changelog file
dotansimha Mar 14, 2019
56111db
Merge branch 'master' into refactor/typescript
dotansimha Mar 14, 2019
e1c06b8
update lockfile
dotansimha Mar 14, 2019
1ce660a
fixes and cleanup
dotansimha Mar 14, 2019
f30ac65
fixes
dotansimha Mar 14, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Optimize website for lazy-loading
  • Loading branch information
ardatan committed Mar 12, 2019

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit d823090e212e5af6e8f8b809f7b04b4473c3cdd5
4 changes: 3 additions & 1 deletion packages/graphql-codegen-cli/src/codegen.ts
Original file line number Diff line number Diff line change
@@ -9,6 +9,8 @@ import { mergeSchemas } from './merge-schemas';
import { GraphQLError, DocumentNode, visit } from 'graphql';
import { executePlugin, getPluginByName } from './execute-plugin';

export const defaultPluginLoader = (mod: string) => import(mod);

export interface GenerateOutputOptions {
filename: string;
plugins: Types.ConfiguredPlugin[];
@@ -211,7 +213,7 @@ export async function executeCodegen(config: Types.Config): Promise<FileOutput[]
...rootConfig,
...outputFileTemplateConfig
},
pluginLoader: config.pluginLoader || require
pluginLoader: config.pluginLoader || defaultPluginLoader
});
result.push(output);
}, filename)
3 changes: 3 additions & 0 deletions packages/plugins/flow-operations/tests/__mocks__/graphql.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
jest.genMockFromModule('graphql');
require = require('esm')(module, { force: true });
module.exports = require('graphql/index.js');
3 changes: 3 additions & 0 deletions packages/plugins/flow-resolvers/tests/__mocks__/graphql.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
jest.genMockFromModule('graphql');
require = require('esm')(module, { force: true });
module.exports = require('graphql/index.js');
3 changes: 3 additions & 0 deletions packages/plugins/flow/tests/__mocks__/graphql.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
jest.genMockFromModule('graphql');
require = require('esm')(module, { force: true });
module.exports = require('graphql/index.js');
3 changes: 3 additions & 0 deletions packages/plugins/fragment-matcher/tests/__mocks__/graphql.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
jest.genMockFromModule('graphql');
require = require('esm')(module, { force: true });
module.exports = require('graphql/index.js');
3 changes: 3 additions & 0 deletions packages/plugins/introspection/tests/__mocks__/graphql.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
jest.genMockFromModule('graphql');
require = require('esm')(module, { force: true });
module.exports = require('graphql/index.js');
3 changes: 3 additions & 0 deletions packages/plugins/schema-ast/tests/__mocks__/graphql.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
jest.genMockFromModule('graphql');
require = require('esm')(module, { force: true });
module.exports = require('graphql/index.js');
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
jest.genMockFromModule('graphql');
require = require('esm')(module, { force: true });
module.exports = require('graphql/index.js');
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
jest.genMockFromModule('graphql');
require = require('esm')(module, { force: true });
module.exports = require('graphql/index.js');
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
jest.genMockFromModule('graphql');
require = require('esm')(module, { force: true });
module.exports = require('graphql/index.js');
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
jest.genMockFromModule('graphql');
require = require('esm')(module, { force: true });
module.exports = require('graphql/index.js');
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
jest.genMockFromModule('graphql');
require = require('esm')(module, { force: true });
module.exports = require('graphql/index.js');
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
jest.genMockFromModule('graphql');
require = require('esm')(module, { force: true });
module.exports = require('graphql/index.js');
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
jest.genMockFromModule('graphql');
require = require('esm')(module, { force: true });
module.exports = require('graphql/index.js');
3 changes: 3 additions & 0 deletions packages/plugins/typescript/tests/__mocks__/graphql.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
jest.genMockFromModule('graphql');
require = require('esm')(module, { force: true });
module.exports = require('graphql/index.js');
3 changes: 3 additions & 0 deletions website/i18n/en.json
Original file line number Diff line number Diff line change
@@ -103,6 +103,9 @@
},
"plugins/typescript-server": {
"title": "TypeScript Server"
},
"plugins/typescript-stencil-apollo": {
"title": "TypeScript Stencil Apollo"
}
},
"links": {
11 changes: 5 additions & 6 deletions website/live-demo/package.json
Original file line number Diff line number Diff line change
@@ -16,25 +16,24 @@
"js-yaml": "3.12.2",
"graphql-code-generator": "0.18.0",
"graphql-codegen-flow": "0.18.0",
"graphql-codegen-flow-documents": "0.18.0",
"graphql-codegen-flow-operations": "0.18.0",
"graphql-codegen-flow-resolvers": "0.18.0",
"graphql-codegen-typescript-common": "0.18.0",
"graphql-codegen-typescript-client": "0.18.0",
"graphql-codegen-typescript-server": "0.18.0",
"graphql-codegen-add": "0.18.0",
"graphql-codegen-time": "0.18.0",
"graphql-codegen-introspection": "0.18.0",
"graphql-codegen-schema-ast": "0.18.0",
"graphql-codegen-typescript": "0.18.0",
"graphql-codegen-typescript-operations": "0.18.0",
"graphql-codegen-typescript-resolvers": "0.18.0",
"graphql-codegen-typescript-apollo-angular": "0.18.0",
"graphql-codegen-typescript-graphql-files-modules": "0.18.0",
"graphql-codegen-typescript-mongodb": "0.18.0",
"graphql-codegen-typescript-react-apollo": "0.18.0",
"graphql-codegen-typescript-resolvers": "0.18.0",
"prettier": "1.16.4",
"@material-ui/core": "3.9.2"
},
"scripts": {
"analyze": "source-map-explorer build/static/js/main.*",
"analyze": "NODE_OPTIONS=--max_old_space_size=8192 react-scripts build && source-map-explorer build/static/js/main.*",
"start": "NODE_OPTIONS=--max_old_space_size=8192 react-scripts start",
"build": "GENERATE_SOURCEMAP=false NODE_OPTIONS=--max_old_space_size=8192 react-scripts build"
},
128 changes: 65 additions & 63 deletions website/live-demo/src/App.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import React, { Component } from 'react';
import './App.css';
import { Editor } from './editor.component';
import { executeCodegen } from 'graphql-code-generator';
import { safeLoad } from 'js-yaml';
import * as prettier from 'prettier/standalone';
import MagicIcon from './magic.svg';
import CodegenLogo from './logo.svg';
import GraphQLLogo from './GraphQL_Logo.svg';
@@ -14,38 +12,44 @@ import FormControl from '@material-ui/core/FormControl';
import Select from '@material-ui/core/Select';
import { pascalCase } from 'change-case';

const plugins = [
require('prettier/parser-graphql'),
require('prettier/parser-babylon'),
require('prettier/parser-yaml'),
require('prettier/parser-typescript')
];

const EXT_TO_FORMATTER = {
ts: 'typescript',
graphql: 'graphql',
'd.ts': 'typescript',
json: 'json'
};

const DEFAULT_EXAMPLE = 'typescript-client';
const DEFAULT_EXAMPLE = 'typescript';

const getPrettierPlugins = async mode => {
switch (mode) {
case 'graphql':
return [await import('prettier/parser-graphql')];
case 'yaml':
return [await import('prettier/parser-yaml')];
case 'typescript':
return [await import('prettier/parser-typescript')];
default:
return [await import('prettier/parser-babylon')];
}
};

const pluginsMap = {
'graphql-codegen-flow': require('graphql-codegen-flow'),
'graphql-codegen-flow-documents': require('graphql-codegen-flow-documents'),
'graphql-codegen-flow-resolvers': require('graphql-codegen-flow-resolvers'),
'graphql-codegen-typescript-common': require('graphql-codegen-typescript-common'),
'graphql-codegen-typescript-client': require('graphql-codegen-typescript-client'),
'graphql-codegen-typescript-server': require('graphql-codegen-typescript-server'),
'graphql-codegen-add': require('graphql-codegen-add'),
'graphql-codegen-time': require('graphql-codegen-time'),
'graphql-codegen-introspection': require('graphql-codegen-introspection'),
'graphql-codegen-schema-ast': require('graphql-codegen-schema-ast'),
'graphql-codegen-typescript-apollo-angular': require('graphql-codegen-typescript-apollo-angular'),
'graphql-codegen-typescript-graphql-files-modules': require('graphql-codegen-typescript-graphql-files-modules'),
'graphql-codegen-typescript-mongodb': require('graphql-codegen-typescript-mongodb'),
'graphql-codegen-typescript-react-apollo': require('graphql-codegen-typescript-react-apollo'),
'graphql-codegen-typescript-resolvers': require('graphql-codegen-typescript-resolvers')
'graphql-codegen-flow': () => import('graphql-codegen-flow'),
'graphql-codegen-flow-operations': () => import('graphql-codegen-flow-operations'),
'graphql-codegen-flow-resolvers': () => import('graphql-codegen-flow-resolvers'),
'graphql-codegen-typescript': () => import('graphql-codegen-typescript'),
'graphql-codegen-typescript-operations': () => import('graphql-codegen-typescript-operations'),
'graphql-codegen-typescript-resolvers': () => import('graphql-codegen-typescript-resolvers'),
'graphql-codegen-typescript-apollo-angular': () => import('graphql-codegen-typescript-apollo-angular'),
'graphql-codegen-typescript-react-apollo': () => import('graphql-codegen-typescript-react-apollo'),
'graphql-codegen-typescript-stencil-apollo': () => import('graphql-codegen-typescript-stencil-apollo'),
'graphql-codegen-typescript-graphql-files-modules': () => import('graphql-codegen-typescript-graphql-files-modules'),
'graphql-codegen-typescript-mongodb': () => import('graphql-codegen-typescript-mongodb'),
'graphql-codegen-add': () => import('graphql-codegen-add'),
'graphql-codegen-time': () => import('graphql-codegen-time'),
'graphql-codegen-introspection': () => import('graphql-codegen-introspection'),
'graphql-codegen-schema-ast': () => import('graphql-codegen-schema-ast')
};

class App extends Component {
@@ -74,62 +78,60 @@ class App extends Component {
return EXT_TO_FORMATTER[ext];
}

prettify(str, config) {
async prettify(str, config, tabWidth) {
try {
const mode = this.getMode(config) || 'typescript';

return prettier.format(str, { parser: mode, plugins });
const prettier = await import('prettier/standalone');
return prettier.format(str, { parser: mode, plugins: await getPrettierPlugins(mode), tabWidth });
} catch (e) {
return str;
}
}

generate = () => {
generate = async () => {
try {
const cleanTabs = this.state.config.replace(/\t/g, ' ');
const prettyYaml = prettier.format(cleanTabs, { parser: 'yaml', plugins, tabWidth: 2 });
const prettier = await import('prettier/standalone');
const prettyYaml = prettier.format(cleanTabs, {
parser: 'yaml',
plugins: await getPrettierPlugins('yaml'),
tabWidth: 2
});
const config = safeLoad(prettyYaml);
config.namingConvention = pascalCase;

const fullConfig = {
pluginLoader: m => pluginsMap[m] || null,
pluginLoader: m => (m in pluginsMap ? pluginsMap[m]() : null || null),
schema: [this.state.schema],
documents: this.state.documents,
...config
};

executeCodegen(fullConfig)
.then(([{ content }]) => {
this.setState({ output: this.prettify(content, config) });
})
.catch(e => {
if (e.details) {
this.setState({
output: `
${e.message}:

${e.details}
`
});
} else if (e.errors) {
this.setState({
output: e.errors
.map(
subError => `${subError.message}:
${subError.details}`
)
.join('\n')
});
} else {
this.setState({
output: e.message
});
}
});
const { executeCodegen } = await import('graphql-code-generator');
const [{ content }] = await executeCodegen(fullConfig);
this.setState({ output: await this.prettify(content, config) });
} catch (e) {
this.setState({
output: e.message
});
if (e.details) {
this.setState({
output: `
${e.message}:

${e.details}
`
});
} else if (e.errors) {
this.setState({
output: e.errors
.map(
subError => `${subError.message}:
${subError.details}`
)
.join('\n')
});
} else {
this.setState({
output: e.message
});
}
}
};

27 changes: 25 additions & 2 deletions website/live-demo/src/editor.component.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,31 @@
import React from 'react';
import CodeMirror from 'codemirror';

export class Editor extends React.Component {
componentDidMount() {
async componentDidMount() {
const [{ default: CodeMirror }] = await Promise.all([
import('codemirror'),
import('codemirror/addon/lint/lint'),
import('codemirror/addon/lint/yaml-lint'),
import('codemirror/addon/hint/show-hint'),
import('codemirror/addon/comment/comment'),
import('codemirror/addon/edit/matchbrackets'),
import('codemirror/addon/edit/closebrackets'),
import('codemirror/addon/fold/foldgutter'),
import('codemirror/addon/fold/brace-fold'),
import('codemirror/addon/search/search'),
import('codemirror/addon/search/searchcursor'),
import('codemirror/addon/search/jump-to-line'),
import('codemirror/addon/dialog/dialog'),
import('codemirror/addon/lint/lint'),
import('codemirror/mode/yaml/yaml'),
import('codemirror/mode/javascript/javascript'),
import('codemirror/keymap/sublime'),
import('codemirror-graphql/hint'),
import('codemirror-graphql/lint'),
import('codemirror-graphql/info'),
import('codemirror-graphql/jump'),
import('codemirror-graphql/mode')
]);
this.editor = CodeMirror(this._node, {
value: this.props.value || '',
lineNumbers: true,
Loading