1- import * as monaco from 'monaco-editor/esm/vs/editor/editor.api.js' ;
1+ /* global monaco */
22
33import 'regenerator-runtime/runtime' ;
44import 'monaco-graphql/esm/monaco.contribution' ;
55
6+ // eslint-disable-next-line spaced-comment
7+ /// <reference path='../../../node_modules/monaco-editor/monaco.d.ts'/>
8+ // eslint-disable-next-line spaced-comment
9+ /// <reference path='../../../packages/monaco-graphql/src/typings/monaco.d.ts'/>
10+
611// NOTE: using loader syntax becuase Yaml worker imports editor.worker directly and that
712// import shouldn't go through loader syntax.
813// @ts -ignore
@@ -12,7 +17,7 @@ import JSONWorker from 'worker-loader!monaco-editor/esm/vs/language/json/json.wo
1217// @ts -ignore
1318import GraphQLWorker from 'worker-loader!monaco-graphql/esm/graphql.worker' ;
1419
15- const SCHEMA_URL = 'https://swapi-graphql.netlify.app/.netlify/functions/index ' ;
20+ const SCHEMA_URL = 'https://api.spacex.land/graphql/ ' ;
1621
1722// @ts -ignore
1823window . MonacoEnvironment = {
@@ -27,19 +32,22 @@ window.MonacoEnvironment = {
2732 } ,
2833} ;
2934
30- // const schemaInput = document.createElement('input');
31- // schemaInput.type = 'text'
35+ const schemaInput = document . createElement ( 'input' ) ;
36+ schemaInput . type = 'text' ;
3237
33- // // @ts -ignore
34- // schemaInput.value = SCHEMA_URL
38+ schemaInput . value = SCHEMA_URL ;
3539
36- // schemaInput.onchange = (e) => {
37- // e.preventDefault()
38- // console.log(e.target.value)
39- // }
40+ schemaInput . onkeyup = e => {
41+ e . preventDefault ( ) ;
42+ // @ts -ignore
43+ const val = e ?. target ?. value as string ;
44+ if ( val && typeof val === 'string' ) {
45+ monaco . languages . graphql . graphqlDefaults . setSchemaConfig ( { uri : val } ) ;
46+ }
47+ } ;
4048
41- // const toolbar = document.getElementById('toolbar')
42- // toolbar?.appendChild(schemaInput)
49+ const toolbar = document . getElementById ( 'toolbar' ) ;
50+ toolbar ?. appendChild ( schemaInput ) ;
4351
4452const variablesModel = monaco . editor . createModel (
4553 `{}` ,
@@ -51,22 +59,31 @@ const resultsEditor = monaco.editor.create(
5159 document . getElementById ( 'results' ) as HTMLElement ,
5260 {
5361 model : variablesModel ,
62+ automaticLayout : true ,
5463 } ,
5564) ;
5665const variablesEditor = monaco . editor . create (
5766 document . getElementById ( 'variables' ) as HTMLElement ,
5867 {
59- value : `{ }` ,
68+ value : `{ "limit": 10 }` ,
6069 language : 'json' ,
70+ automaticLayout : true ,
6171 } ,
6272) ;
6373const model = monaco . editor . createModel (
6474 `
65- query Example {
66- allFilms {
67- films {
68- id
69- }
75+ query Example($limit: Int) {
76+ launchesPast(limit: $limit) {
77+ mission_name
78+ # format me using the right click context menu
79+ launch_date_local
80+ launch_site {
81+ site_name_long
82+ }
83+ links {
84+ article_link
85+ video_link
86+ }
7087 }
7188}
7289` ,
@@ -78,9 +95,12 @@ const operationEditor = monaco.editor.create(
7895 document . getElementById ( 'operation' ) as HTMLElement ,
7996 {
8097 model,
98+ automaticLayout : true ,
8199 } ,
82100) ;
83101
102+ monaco . languages . graphql . graphqlDefaults . setSchemaConfig ( { uri : SCHEMA_URL } ) ;
103+
84104/**
85105 * Basic Operation Exec Example
86106 */
@@ -99,6 +119,7 @@ async function executeCurrentOp() {
99119 headers : { 'content-type' : 'application/json' } ,
100120 body : JSON . stringify ( body ) ,
101121 } ) ;
122+
102123 const resultText = await result . text ( ) ;
103124 resultsEditor . setValue ( JSON . stringify ( JSON . parse ( resultText ) , null , 2 ) ) ;
104125 } catch ( err ) {
@@ -135,3 +156,7 @@ resultsEditor.addAction(opAction);
135156// endColumn: 0,
136157// }],
137158// );
159+
160+ // operationEditor.onDidChangeModelContent(() => {
161+ // // this is where
162+ // })
0 commit comments