Skip to content

Commit

Permalink
✨ Merging of schemas now peossivble
Browse files Browse the repository at this point in the history
  • Loading branch information
aexol committed Jun 18, 2023
1 parent d84b0f3 commit 069d15c
Show file tree
Hide file tree
Showing 23 changed files with 220 additions and 183 deletions.
101 changes: 36 additions & 65 deletions package-lock.json

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

4 changes: 2 additions & 2 deletions 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.6.2",
"version": "6.6.3",
"private": false,
"license": "MIT",
"description": "Visual node editor for GraphQL",
Expand Down Expand Up @@ -28,7 +28,7 @@
},
"dependencies": {
"d3": "^7.8.4",
"graphql-js-tree": "^0.3.1",
"graphql-js-tree": "^0.4.0",
"graphql-language-service": "3.1.4"
},
"config": {
Expand Down
13 changes: 10 additions & 3 deletions packages/editor-worker/src/validation.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { buildSchema, validateSchema, parse, GraphQLError } from "graphql";
import { validateSDL } from "graphql/validation/validate";
import { mergeSDLs } from "graphql-js-tree";

export interface EditorError {
type: "error";
Expand Down Expand Up @@ -55,17 +56,23 @@ export const catchSchemaErrors = (
schema: string,
libraries = ""
): EditorError[] => {
const s = libraries + "\n" + schema;
const s = mergeSDLs(schema, libraries);
if (s.__typename === "error") {
return s.errors.map((e) => ({
type: "error",
text: `There is a conflict with library schema on Type.field: ${e.conflictingNode}.${e.conflictingField}`,
}));
}
const paddingFunction = moveErrorsByLibraryPadding(libraries);
try {
const errors = validateSDLErrors(s);
const errors = validateSDLErrors(s.sdl);
if (errors.length > 0) {
return errors
.filter((e) => allowMultipleDirectivesAtLocation(e.text))
.map(paddingFunction);
}
try {
return validateTypes(s).map(paddingFunction);
return validateTypes(s.sdl).map(paddingFunction);
} catch (error) {
console.log(error);
}
Expand Down
24 changes: 21 additions & 3 deletions packages/editor-worker/src/worker/validation.worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
ParserField,
ParserTree,
TreeToGraphQL,
mergeTrees,
} from "graphql-js-tree";
import { getTokenAtPosition, IPosition } from "graphql-language-service";
const ctx: Worker = self as any;
Expand Down Expand Up @@ -92,10 +93,27 @@ ctx.addEventListener("message", (message) => {
receive("validate", (args) => catchSchemaErrors(args.schema, args.libraries))(
message
);
receive("parse", (args) => TreeToGraphQL.parse(args.tree))(message);
receive("parseSchema", (args) =>
Parser.parse(args.schema, [], args.libraries)
receive("parse", (args) =>
TreeToGraphQL.parse({
nodes: args.tree.nodes
.filter((n) => !n.fromLibrary)
.map((n) => ({
...n,
args: n.args.filter((a) => !a.fromLibrary),
directives: n.directives.filter((a) => !a.fromLibrary),
})),
})
)(message);
receive("parseSchema", (args) => {
const mtress = mergeTrees(
Parser.parse(args.schema),
args.libraries ? Parser.parse(args.libraries) : { nodes: [] }
);
if (mtress.nodes) {
return mtress;
}
throw new Error("No nodes to parse");
})(message);
receive("token", (args) =>
JSON.stringify(
getTokenAtPosition(args.document, args.position as IPosition)
Expand Down
6 changes: 3 additions & 3 deletions packages/editor/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "graphql-editor",
"version": "6.6.2",
"version": "6.6.3",
"private": false,
"license": "MIT",
"description": "Visual node editor for GraphQL",
Expand Down Expand Up @@ -46,8 +46,8 @@
"file-saver": "^2.0.5",
"framer": "^2.3.0",
"fuzzyjs": "^5.0.1",
"graphql-editor-worker": "^6.6.2",
"graphql-js-tree": "^0.3.1",
"graphql-editor-worker": "^6.6.3",
"graphql-js-tree": "^0.4.0",
"graphql-language-service": "3.1.4",
"html-to-image": "^1.10.8",
"re-resizable": "^6.9.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/editor/src/Docs/DocsElement.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export const DocsElement: React.FC<DocsElementI> = ({ node }) => {

const [isEdit, setIsEdit] = useState(false);

const isReadonly = readonly || isLibrary(node.id);
const isReadonly = readonly || isLibrary(node);

const setNode = (nodeName: string) => {
const newSelectedNode = tree.nodes.filter((node) => node.name === nodeName);
Expand Down
Loading

0 comments on commit 069d15c

Please sign in to comment.