Skip to content

Commit 9cc2613

Browse files
authored
Merge branch 'main' into graphiql-5
2 parents 2455907 + 403dfc2 commit 9cc2613

File tree

11 files changed

+69
-72
lines changed

11 files changed

+69
-72
lines changed

.changeset/few-lamps-rest.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'graphql-language-service': minor
3+
---
4+
5+
feat: set `additionalProperties: false` to report unused variables
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
'monaco-graphql': patch
3+
---
4+
5+
remove unused `MonacoCompletionItem` type
6+
7+
fix `types` field in `package.json`, should be first, before `import` or `require` fields
8+
9+
fixed `monaco-graphql` severity, it was hardcoded to `5` which is not valid value of monaco severity

packages/codemirror-graphql/src/utils/SchemaReference.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@ export function getEnumValueReference(typeInfo: TypeInfo): EnumValueReference {
100100
return {
101101
kind: 'EnumValue',
102102
value: typeInfo.enumValue || undefined,
103-
// $FlowFixMe
104103
type: typeInfo.inputType
105104
? (getNamedType(typeInfo.inputType) as GraphQLEnumType)
106105
: undefined,

packages/graphql-language-service-server/src/__tests__/MessageProcessor.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ describe('MessageProcessor', () => {
359359
});
360360

361361
it('properly removes from the file cache with the didClose handler', async () => {
362-
await messageProcessor.handleDidCloseNotification(initialDocument);
362+
messageProcessor.handleDidCloseNotification(initialDocument);
363363

364364
const position = { line: 4, character: 5 };
365365
const params = { textDocument: initialDocument.textDocument, position };
@@ -407,7 +407,7 @@ describe('MessageProcessor', () => {
407407
};
408408

409409
const result = await messageProcessor.handleDefinitionRequest(test);
410-
await expect(result[0].uri).toEqual(`${queryPathUri}/test3.graphql`);
410+
expect(result[0].uri).toEqual(`${queryPathUri}/test3.graphql`);
411411
});
412412

413413
it('retrieves custom results from locateCommand', async () => {

packages/graphql-language-service/src/interface/getDiagnostics.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -193,11 +193,9 @@ export function getRange(location: SourceLocation, queryText: string): IRange {
193193

194194
invariant(stream, 'Expected Parser stream to be available.');
195195
const line = location.line - 1;
196-
// @ts-ignore
197-
// https://github.com/microsoft/TypeScript/pull/32695
196+
// @ts-expect-error -- https://github.com/microsoft/TypeScript/pull/32695
198197
const start = stream.getStartOfToken();
199-
// @ts-ignore
200-
// https://github.com/microsoft/TypeScript/pull/32695
198+
// @ts-expect-error -- https://github.com/microsoft/TypeScript/pull/32695
201199
const end = stream.getCurrentPosition();
202200
return new Range(new Position(line, start), new Position(line, end));
203201
}

packages/graphql-language-service/src/interface/getHoverInformation.ts

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ export function getHoverInformation(
105105
return '';
106106
}
107107

108-
function renderMdCodeStart(into: string[], options: any) {
108+
function renderMdCodeStart(into: string[], options: HoverConfig) {
109109
if (options.useMarkdown) {
110110
text(into, '```graphql\n');
111111
}
@@ -119,7 +119,7 @@ function renderMdCodeEnd(into: string[], options: any) {
119119
export function renderField(
120120
into: string[],
121121
typeInfo: AllTypeInfo,
122-
options: any,
122+
options: HoverConfig,
123123
) {
124124
renderQualifiedField(into, typeInfo, options);
125125
renderTypeAnnotation(into, typeInfo, options, typeInfo.type!);
@@ -128,7 +128,7 @@ export function renderField(
128128
function renderQualifiedField(
129129
into: string[],
130130
typeInfo: AllTypeInfo,
131-
options: any,
131+
options: HoverConfig,
132132
) {
133133
if (!typeInfo.fieldDef) {
134134
return;
@@ -144,7 +144,7 @@ function renderQualifiedField(
144144
export function renderDirective(
145145
into: string[],
146146
typeInfo: AllTypeInfo,
147-
_options: any,
147+
_options: HoverConfig,
148148
) {
149149
if (!typeInfo.directiveDef) {
150150
return;
@@ -153,7 +153,11 @@ export function renderDirective(
153153
text(into, name);
154154
}
155155

156-
export function renderArg(into: string[], typeInfo: AllTypeInfo, options: any) {
156+
export function renderArg(
157+
into: string[],
158+
typeInfo: AllTypeInfo,
159+
options: HoverConfig,
160+
) {
157161
if (typeInfo.directiveDef) {
158162
renderDirective(into, typeInfo, options);
159163
} else if (typeInfo.fieldDef) {
@@ -174,7 +178,7 @@ export function renderArg(into: string[], typeInfo: AllTypeInfo, options: any) {
174178
function renderTypeAnnotation(
175179
into: string[],
176180
typeInfo: AllTypeInfo,
177-
options: any,
181+
options: HoverConfig,
178182
t: GraphQLType,
179183
) {
180184
text(into, ': ');
@@ -184,7 +188,7 @@ function renderTypeAnnotation(
184188
export function renderEnumValue(
185189
into: string[],
186190
typeInfo: AllTypeInfo,
187-
options: any,
191+
options: HoverConfig,
188192
) {
189193
if (!typeInfo.enumValue) {
190194
return;
@@ -198,7 +202,7 @@ export function renderEnumValue(
198202
export function renderType(
199203
into: string[],
200204
typeInfo: AllTypeInfo,
201-
options: any,
205+
options: HoverConfig,
202206
t: GraphQLType,
203207
) {
204208
if (!t) {
@@ -219,7 +223,7 @@ export function renderType(
219223

220224
function renderDescription(
221225
into: string[],
222-
options: any,
226+
options: HoverConfig,
223227
// TODO: Figure out the right type for this one
224228
def: any,
225229
) {
@@ -237,14 +241,14 @@ function renderDescription(
237241

238242
function renderDeprecation(
239243
into: string[],
240-
_options: any,
241-
def: GraphQLField<any, any> | GraphQLFieldConfig<any, any>,
244+
_options: HoverConfig,
245+
def: GraphQLField<unknown, unknown> | GraphQLFieldConfig<unknown, unknown>,
242246
) {
243247
if (!def) {
244248
return;
245249
}
246250

247-
const reason = def.deprecationReason || null;
251+
const reason = def.deprecationReason;
248252
if (!reason) {
249253
return;
250254
}

packages/graphql-language-service/src/utils/getVariablesJSONSchema.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,7 @@ export function getVariablesJSONSchema(
359359
type: 'object',
360360
properties: {},
361361
required: [],
362+
additionalProperties: false,
362363
};
363364

364365
const runtimeOptions: JSONSchemaRunningOptions = {

packages/monaco-graphql/package.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,37 +18,37 @@
1818
],
1919
"exports": {
2020
".": {
21+
"types": "./esm/monaco.contribution.d.ts",
2122
"import": "./esm/monaco.contribution.js",
2223
"require": "./dist/monaco.contribution.js",
23-
"types": "./esm/monaco.contribution.d.ts",
2424
"default": "./dist/monaco.contribution.js"
2525
},
2626
"./*": {
27+
"types": "./*",
2728
"import": "./*",
2829
"require": "./*",
29-
"types": "./*",
3030
"default": "./*"
3131
},
3232
"./esm/graphql.worker": {
33+
"types": "./esm/graphql.worker.d.ts",
3334
"import": "./esm/graphql.worker.js",
34-
"require": "./dist/graphql.worker.js",
35-
"types": "./esm/graphql.worker.d.ts"
35+
"require": "./dist/graphql.worker.js"
3636
},
3737
"./lite": {
38-
"import": "./esm/lite.js",
3938
"types": "./esm/lite.d.ts",
39+
"import": "./esm/lite.js",
4040
"require": "./dist/lite.js",
4141
"default": "./dist/lite.js"
4242
},
4343
"./graphql.worker": {
44-
"import": "./esm/graphql.worker.js",
4544
"types": "./esm/graphql.worker.d.ts",
45+
"import": "./esm/graphql.worker.js",
4646
"require": "./dist/graphql.worker.js",
4747
"default": "./dist/graphql.worker.js"
4848
},
4949
"./initializeMode": {
50-
"import": "./esm/initializeMode.js",
5150
"types": "./esm/initializeMode.d.ts",
51+
"import": "./esm/initializeMode.js",
5252
"require": "./dist/initializeMode.js",
5353
"default": "./dist/initializeMode.js"
5454
}

packages/monaco-graphql/src/GraphQLWorker.ts

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,11 @@ import {
1717
GraphQLWorkerCompletionItem,
1818
} from './utils';
1919

20-
export type MonacoCompletionItem = monaco.languages.CompletionItem & {
21-
isDeprecated?: boolean;
22-
deprecationReason?: string | null;
23-
};
2420
export class GraphQLWorker {
2521
private _ctx: monaco.worker.IWorkerContext;
2622
private _languageService: LanguageService;
2723
private _formattingOptions: FormattingOptions | undefined;
24+
2825
constructor(ctx: monaco.worker.IWorkerContext, createData: ICreateData) {
2926
this._ctx = ctx;
3027
this._languageService = new LanguageService(createData.languageConfig);
@@ -82,24 +79,18 @@ export class GraphQLWorker {
8279
return null;
8380
}
8481
const graphQLPosition = toGraphQLPosition(position);
85-
8682
const hover = this._languageService.getHover(
8783
uri,
8884
document,
8985
graphQLPosition,
9086
);
91-
87+
const location = {
88+
column: graphQLPosition.character,
89+
line: graphQLPosition.line,
90+
};
9291
return {
9392
content: hover,
94-
range: toMonacoRange(
95-
getRange(
96-
{
97-
column: graphQLPosition.character,
98-
line: graphQLPosition.line,
99-
},
100-
document,
101-
),
102-
),
93+
range: toMonacoRange(getRange(location, document)),
10394
};
10495
} catch (err) {
10596
// eslint-disable-next-line no-console
@@ -157,9 +148,11 @@ export class GraphQLWorker {
157148
}
158149
return null;
159150
}
151+
160152
public doUpdateSchema(schema: SchemaConfig) {
161153
return this._languageService.updateSchema(schema);
162154
}
155+
163156
public doUpdateSchemas(schemas: SchemaConfig[]) {
164157
return this._languageService.updateSchemas(schemas);
165158
}

packages/monaco-graphql/src/languageFeatures.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,10 +242,9 @@ export class CompletionAdapter implements languages.CompletionItemProvider {
242242
_token: monaco.CancellationToken,
243243
): Promise<languages.CompletionList> {
244244
try {
245-
const resource = model.uri;
246245
const worker = await this._worker(model.uri);
247246
const completionItems = await worker.doComplete(
248-
resource.toString(),
247+
model.uri.toString(),
249248
position,
250249
);
251250
return {

0 commit comments

Comments
 (0)