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

feat: monaco-graphql docs, api, improvements #1521

Merged
merged 7 commits into from
May 16, 2020
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ coverage/
packages/**/dist/.gitignore
packages/**/dist/.npmignore
packages/graphiql/storybook
packages/graphiql/lsp
packages/graphiql/typedoc
dist
esm
bundle
Expand Down
7 changes: 4 additions & 3 deletions examples/monaco-graphql-webpack/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
"private": true,
"license": "MIT",
"description": "A simple monaco example with webpack and typescript",
"typings": "src/types.d.ts",
"scripts": {
"build": "cross-env NODE_ENV=production webpack ",
"build": "cross-env NODE_ENV=production webpack-cli",
"build-demo": "yarn build && yarn copy-demo",
"copy-demo": "mkdirp ../../packages/graphiql/monaco && copy 'bundle/*' '../../packages/graphiql/monaco'",
"start": "cross-env NODE_ENV=development webpack-dev-server"
Expand All @@ -28,9 +29,9 @@
"monaco-editor-webpack-plugin": "^1.9.0",
"react-dom": "^16.12.0",
"style-loader": "^1.1.3",
"webpack": "4.42.1",
"webpack": "^4.42.0",
"webpack-cli": "^3.3.11",
"webpack-dev-server": "^3.10.1",
"webpack-dev-server": "^3.10.3",
"worker-loader": "^2.0.0"
}
}
62 changes: 35 additions & 27 deletions examples/monaco-graphql-webpack/src/index.html.ejs
Original file line number Diff line number Diff line change
@@ -1,34 +1,42 @@
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="UTF-8" />
<meta
name="viewport"
content="width=device-width, initial-scale=1, shrink-to-fit=no"
/>
<title>Monaco Example!</title>
<style>
.div {
margin: 0;
padding: 0;
}

<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
<title>Monaco Example!</title>
<style>
.div {
margin: 0;
padding: 0;
}
.full-height {
height: 100vh;
}

.full-height {
height: 100vh;
}
.column {
width: 50%;
}
</style>
</head>

.column {
width: 50%;
}
</style>
</head>

<body style="margin: 0; padding:0;">
<div style="display: flex;">
<div class="full-height column">
<div id="operation" style="height:70vh;"></div>
<div id="variables" style="height:30vh;"></div>
<body style="margin: 0; padding: 0;">
<div style="display: flex;">
<div class="full-height column">
<div id="toolbar" style=""></div>
<div id="operation" style="height: 70vh;"></div>
<div id="variables" style="height: 30vh;"></div>
</div>
<div
id="results"
class="full-height column"
aria-label="Result Window"
aria-live="polite"
aria-atomic="true"
></div>
</div>
<div id="results" class="full-height column"></div>
</div>
</body>

</body>
</html>
61 changes: 43 additions & 18 deletions examples/monaco-graphql-webpack/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import * as monaco from 'monaco-editor/esm/vs/editor/editor.api.js';
/* global monaco */

import 'regenerator-runtime/runtime';
import 'monaco-graphql/esm/monaco.contribution';

// eslint-disable-next-line spaced-comment
/// <reference path='../../../node_modules/monaco-editor/monaco.d.ts'/>
// eslint-disable-next-line spaced-comment
/// <reference path='../../../packages/monaco-graphql/src/typings/monaco.d.ts'/>

// NOTE: using loader syntax becuase Yaml worker imports editor.worker directly and that
// import shouldn't go through loader syntax.
// @ts-ignore
Expand All @@ -12,7 +17,7 @@ import JSONWorker from 'worker-loader!monaco-editor/esm/vs/language/json/json.wo
// @ts-ignore
import GraphQLWorker from 'worker-loader!monaco-graphql/esm/graphql.worker';

const SCHEMA_URL = 'https://swapi-graphql.netlify.app/.netlify/functions/index';
const SCHEMA_URL = 'https://api.spacex.land/graphql/';

// @ts-ignore
window.MonacoEnvironment = {
Expand All @@ -27,19 +32,22 @@ window.MonacoEnvironment = {
},
};

// const schemaInput = document.createElement('input');
// schemaInput.type = 'text'
const schemaInput = document.createElement('input');
schemaInput.type = 'text';

// // @ts-ignore
// schemaInput.value = SCHEMA_URL
schemaInput.value = SCHEMA_URL;

// schemaInput.onchange = (e) => {
// e.preventDefault()
// console.log(e.target.value)
// }
schemaInput.onkeyup = e => {
e.preventDefault();
// @ts-ignore
const val = e?.target?.value as string;
if (val && typeof val === 'string') {
monaco.languages.graphql.graphqlDefaults.setSchemaConfig({ uri: val });
}
};

// const toolbar = document.getElementById('toolbar')
// toolbar?.appendChild(schemaInput)
const toolbar = document.getElementById('toolbar');
toolbar?.appendChild(schemaInput);

const variablesModel = monaco.editor.createModel(
`{}`,
Expand All @@ -51,22 +59,31 @@ const resultsEditor = monaco.editor.create(
document.getElementById('results') as HTMLElement,
{
model: variablesModel,
automaticLayout: true,
},
);
const variablesEditor = monaco.editor.create(
document.getElementById('variables') as HTMLElement,
{
value: `{ }`,
value: `{ "limit": 10 }`,
language: 'json',
automaticLayout: true,
},
);
const model = monaco.editor.createModel(
`
query Example {
allFilms {
films {
id
}
query Example($limit: Int) {
launchesPast(limit: $limit) {
mission_name
# format me using the right click context menu
launch_date_local
launch_site {
site_name_long
}
links {
article_link
video_link
}
}
}
`,
Expand All @@ -78,9 +95,12 @@ const operationEditor = monaco.editor.create(
document.getElementById('operation') as HTMLElement,
{
model,
automaticLayout: true,
},
);

monaco.languages.graphql.graphqlDefaults.setSchemaConfig({ uri: SCHEMA_URL });

/**
* Basic Operation Exec Example
*/
Expand All @@ -99,6 +119,7 @@ async function executeCurrentOp() {
headers: { 'content-type': 'application/json' },
body: JSON.stringify(body),
});

const resultText = await result.text();
resultsEditor.setValue(JSON.stringify(JSON.parse(resultText), null, 2));
} catch (err) {
Expand Down Expand Up @@ -135,3 +156,7 @@ resultsEditor.addAction(opAction);
// endColumn: 0,
// }],
// );

// operationEditor.onDidChangeModelContent(() => {
// // this is where
// })
4 changes: 4 additions & 0 deletions examples/monaco-graphql-webpack/src/types.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// eslint-disable-next-line spaced-comment
/// <reference path='../../../node_modules/monaco-editor/monaco.d.ts'/>
// eslint-disable-next-line spaced-comment
/// <reference path='../../../packages/monaco-graphql/src/typings/monaco.d.ts'/>
1 change: 0 additions & 1 deletion examples/monaco-graphql-webpack/webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const path = require('path');
const webpack = require('webpack');

const HtmlWebpackPlugin = require('html-webpack-plugin');
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
Expand Down
2 changes: 1 addition & 1 deletion netlify.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[build]
command = "yarn build && yarn build-bundles && yarn build-demo"
command = "yarn build && yarn build-bundles && yarn build-demo && yarn build-docs"
publish = "packages/graphiql"


Expand Down
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"build-clean": "lerna run build-clean",
"build-validate": "lerna run build-validate",
"build-demo": "lerna run build-demo",
"build-docs": "rimraf 'packages/graphiql/lsp' && typedoc 'packages'",
"build-docs": "rimraf 'packages/graphiql/typedoc' && typedoc 'packages'",
"build-bundles": "yarn prebuild-bundles && yarn workspace graphiql run build-bundles",
"prebuild-bundles": "yarn build-ts-esm && yarn build-bundles-clean",
"build-bundles-clean": "rimraf '{packages,examples}/**/{bundle,cdn,webpack}' && lerna run build-bundles-clean",
Expand Down Expand Up @@ -72,7 +72,6 @@
"@commitlint/cli": "^8.3.5",
"@commitlint/config-conventional": "^8.3.4",
"@commitlint/config-lerna-scopes": "^8.3.4",
"@strictsoftware/typedoc-plugin-monorepo": "0.3.1",
"@testing-library/jest-dom": "^5.4.0",
"@types/codemirror": "^0.0.90",
"@types/fetch-mock": "^7.3.2",
Expand Down Expand Up @@ -115,5 +114,8 @@
"ts-jest": "^25.3.1",
"typedoc": "0.17.4",
"typescript": "^3.8.3"
},
"dependencies": {
"@strictsoftware/typedoc-plugin-monorepo": "^0.3.1"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export function forEachState(
}
}

export function objectValues(object: Record<string, any>): Array<any> {
export function objectValues<T>(object: Record<string, T>): Array<T> {
const keys = Object.keys(object);
const len = keys.length;
const values = new Array(len);
Expand Down
Loading