Skip to content

Commit d776799

Browse files
authored
improvement: cleaner types for monaco-graphql (#1549)
1 parent e54e1a8 commit d776799

File tree

4 files changed

+25
-17
lines changed

4 files changed

+25
-17
lines changed

examples/monaco-graphql-webpack/src/index.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import 'regenerator-runtime/runtime';
44
import 'monaco-graphql/esm/monaco.contribution';
55

66
// eslint-disable-next-line spaced-comment
7-
/// <reference path='../../../node_modules/monaco-editor/monaco.d.ts'/>
7+
/// <reference types='monaco-editor'/>
88
// eslint-disable-next-line spaced-comment
9-
/// <reference path='../../../packages/monaco-graphql/src/typings/monaco.d.ts'/>
9+
/// <reference types='monaco-graphql'/>
1010

1111
// NOTE: using loader syntax becuase Yaml worker imports editor.worker directly and that
1212
// import shouldn't go through loader syntax.
@@ -99,7 +99,17 @@ const operationEditor = monaco.editor.create(
9999
},
100100
);
101101

102-
monaco.languages.graphql.graphqlDefaults.setSchemaConfig({ uri: SCHEMA_URL });
102+
monaco.languages.graphql.graphqlDefaults.setFormattingOptions({
103+
// TODO: get these types working properly
104+
prettierConfig: {
105+
printWith: 120,
106+
},
107+
});
108+
109+
monaco.languages.graphql.graphqlDefaults.setSchemaConfig({
110+
// TODO: get these types working properly
111+
uri: SCHEMA_URL,
112+
});
103113

104114
/**
105115
* Basic Operation Exec Example

packages/monaco-graphql/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"version": "0.1.1",
55
"main": "dist/monaco.contribution.js",
66
"module": "esm/monaco.contribution.js",
7-
"typings": "esm/typings/monaco.d.ts",
7+
"typings": "src/typings/monaco.d.ts",
88
"contributors": [
99
{
1010
"name": "Peng Lyu",

packages/monaco-graphql/src/GraphQLWorker.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
*/
77

88
// eslint-disable-next-line spaced-comment
9-
/// <reference path='../../../node_modules/monaco-editor/monaco.d.ts'/>
9+
/// <reference types='monaco-editor'/>
1010
// eslint-disable-next-line spaced-comment
11-
/// <reference path='../../../packages/monaco-graphql/src/typings/monaco.d.ts'/>
11+
/// <reference types='monaco-graphql'/>
1212

1313
import type { worker, editor, Position, IRange } from 'monaco-editor';
1414

packages/monaco-graphql/src/typings/monaco.d.ts

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,18 @@
66
*/
77

88
// eslint-disable-next-line spaced-comment
9-
/// <reference path='../../../../node_modules/monaco-editor/monaco.d.ts'/>
9+
/// <reference types='monaco-editor'/>
1010

1111
declare module monaco.languages.graphql {
12-
import type { SchemaLoader, SchemaConfig } from 'graphql-language-service';
12+
import type {
13+
SchemaLoader,
14+
SchemaConfig as SchemaConfiguration,
15+
SchemaResponse,
16+
} from 'graphql-language-service';
1317

14-
import type { GraphQLSchema } from 'graphql';
1518
import type { Options as PrettierConfig } from 'prettier';
1619

1720
import { MonacoGraphQLApi } from '../api';
18-
1921
export interface IDisposable {
2022
dispose(): void;
2123
}
@@ -28,9 +30,7 @@ declare module monaco.languages.graphql {
2830

2931
export type FilePointer = string | string[];
3032

31-
export interface FormattingOptions {
32-
prettierConfig: PrettierConfig;
33-
}
33+
export type FormattingOptions = PrettierConfig;
3434

3535
export interface ModeConfiguration {
3636
/**
@@ -88,14 +88,12 @@ declare module monaco.languages.graphql {
8888
languageId: string;
8989
enableSchemaRequest: boolean;
9090
schemaConfig: SchemaConfig;
91-
schemaLoader: () => Promise<GraphQLSchema>;
91+
schemaLoader: () => Promise<SchemaResponse>;
9292
formattingOptions?: FormattingOptions;
9393
}
9494

9595
export interface LanguageServiceDefaults {
96-
readonly onDidChange: IEvent<
97-
monaco.languages.graphql.LanguageServiceDefaults
98-
>;
96+
readonly onDidChange: IEvent<LanguageServiceDefaults>;
9997
readonly schemaConfig: SchemaConfig;
10098
readonly formattingOptions: FormattingOptions;
10199
readonly modeConfiguration: ModeConfiguration;

0 commit comments

Comments
 (0)