Skip to content

Commit

Permalink
🐛 Fixed marker library bug
Browse files Browse the repository at this point in the history
  • Loading branch information
aexol committed Sep 29, 2023
1 parent 65c7c5c commit 88abcbd
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 20 deletions.
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/editor-worker/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "graphql-editor-worker",
"version": "6.9.8",
"version": "6.9.9",
"private": false,
"license": "MIT",
"description": "Visual node editor for GraphQL",
Expand Down
4 changes: 2 additions & 2 deletions packages/editor/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "graphql-editor",
"version": "6.9.8",
"version": "6.9.9",
"private": false,
"license": "MIT",
"description": "Visual node editor for GraphQL",
Expand Down Expand Up @@ -45,7 +45,7 @@
"file-saver": "^2.0.5",
"framer-motion": "^10.12.16",
"fuzzyjs": "^5.0.1",
"graphql-editor-worker": "^6.9.8",
"graphql-editor-worker": "^6.9.9",
"graphql-js-tree": "^1.0.5",
"graphql-language-service": "3.1.4",
"html-to-image": "^1.10.8",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
IPosition as GraphQLPosition,
ContextToken,
} from "graphql-language-service";
import type * as monaco from "monaco-editor";
import * as monaco from "monaco-editor";
import {
BridgeOptions,
coreDefinitionSource,
Expand All @@ -20,6 +20,7 @@ import {
toMonacoRange,
removeFalsey,
} from "./utils";
import { mergeSDLs } from "graphql-js-tree";

export class EnrichedLanguageService extends LanguageService {
async getNodeAtPosition(
Expand Down Expand Up @@ -164,7 +165,8 @@ export class EnrichedLanguageService extends LanguageService {
private async handleDiagnostics(
rawDiagnosticsSources: DiagnosticsSource[],
model: monaco.editor.ITextModel,
monacoInstance: typeof monaco
monacoInstance: typeof monaco,
libraries?: string
): Promise<void> {
const diagnosticsSources = [
...rawDiagnosticsSources,
Expand All @@ -175,10 +177,34 @@ export class EnrichedLanguageService extends LanguageService {
await Promise.all(
diagnosticsSources.map(async (source) => {
try {
let c = model.getValue().toString();
if (libraries) {
const result = mergeSDLs(model.getValue().toString(), libraries);
if (result.__typename === "error") {
return [
{
message:
"Cannot merge nodes: " +
result.errors
.map(
(e) => `${e.conflictingNode}.${e.conflictingField}`
)
.join(","),
endColumn: 1000,
endLineNumber: 19999,
startColumn: 0,
startLineNumber: 0,
severity: monaco.MarkerSeverity.Warning,
},
];
} else {
c = result.sdl;
}
}
const s = await source.forDocument({
languageService: this,
model,
document: model.getValue().toString(),
document: c,
});
return s;
} catch (e) {
Expand All @@ -194,7 +220,9 @@ export class EnrichedLanguageService extends LanguageService {
monacoInstance.editor.setModelMarkers(model, "graphql", markerData);
}

getModelChangeHandler(): (
getModelChangeHandler(
libraries?: string
): (
editorInstance: monaco.editor.IStandaloneCodeEditor,
monacoInstance: typeof monaco,
diagnosticsSources: DiagnosticsSource[],
Expand All @@ -213,7 +241,12 @@ export class EnrichedLanguageService extends LanguageService {
}

await Promise.all([
this.handleDiagnostics(diagnosticsSources, model, monacoInstance),
this.handleDiagnostics(
diagnosticsSources,
model,
monacoInstance,
libraries
),
this.handleDecorations(
decorationsSources,
model,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,9 @@ export const useSchemaServices = (options: SchemaServicesOptions) => {
});
}

const handler = languageService.getModelChangeHandler();
const handler = languageService.getModelChangeHandler(
options.schema?.libraries
);
handler(
editorRef,
monacoRef,
Expand Down
4 changes: 2 additions & 2 deletions packages/sandbox/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sandbox",
"version": "6.9.8",
"version": "6.9.9",
"private": false,
"license": "MIT",
"description": "Visual node editor for GraphQL",
Expand Down Expand Up @@ -48,7 +48,7 @@
"@aexol-studio/styling-system": "^0.0.8",
"@emotion/react": "^11.10.5",
"@emotion/styled": "^11.10.5",
"graphql-editor": "^6.9.8",
"graphql-editor": "^6.9.9",
"graphql-js-tree": "^0.1.6",
"socket.io-client": "^4.7.2"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/socket-live-test/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "socket-live-test",
"version": "1.0.6",
"version": "1.0.7",
"description": "testing editor live",
"main": "index.js",
"type": "module",
Expand Down
2 changes: 1 addition & 1 deletion packages/svg-ts-sync/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "svg-ts-sync",
"version": "0.8.8",
"version": "0.8.9",
"private": false,
"license": "MIT",
"description": "Sync folders with svg's to react typescript components",
Expand Down

0 comments on commit 88abcbd

Please sign in to comment.