Skip to content

Commit

Permalink
🐛 Final fix :D
Browse files Browse the repository at this point in the history
  • Loading branch information
aexol committed Aug 14, 2023
1 parent fe52094 commit 0575013
Show file tree
Hide file tree
Showing 12 changed files with 62 additions and 37 deletions.
36 changes: 18 additions & 18 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.9.0",
"version": "6.9.1",
"private": false,
"license": "MIT",
"description": "Visual node editor for GraphQL",
Expand Down Expand Up @@ -30,7 +30,7 @@
"@qix/elkjs-patched": "^0.8.0-patch3",
"d3": "^7.8.4",
"elkjs": "^0.8.2",
"graphql-js-tree": "^1.0.3",
"graphql-js-tree": "^1.0.5",
"graphql-language-service": "3.1.4"
},
"config": {
Expand Down
1 change: 1 addition & 0 deletions packages/editor-worker/src/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export const catchSchemaErrors = (
code = mergeResult.sdl;
}
const errors = validateSDLErrors(code);

if (errors.length > 0) {
return errors
.filter((e) => allowMultipleDirectivesAtLocation(e.text))
Expand Down
12 changes: 10 additions & 2 deletions packages/editor-worker/src/worker/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,16 @@ export class GraphQLEditorWorker {
static generateCode(tree: ParserTree) {
return send("parse", { tree });
}
static generateTree(schema: string, libraries?: string) {
return send("parseSchema", { schema, libraries });
static generateTree({
schema,
libraries,
cutSchemaDefinition,
}: {
schema: string;
libraries?: string;
cutSchemaDefinition?: boolean;
}) {
return send("parseSchema", { schema, libraries, cutSchemaDefinition });
}
static getTokenAtPosition(
document: string,
Expand Down
11 changes: 11 additions & 0 deletions packages/editor-worker/src/worker/validation.worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
ParserField,
ParserTree,
TreeToGraphQL,
TypeSystemDefinition,
mergeTrees,
} from "graphql-js-tree";
import { getTokenAtPosition, IPosition } from "graphql-language-service";
Expand All @@ -29,6 +30,7 @@ export type WorkerEvents = {
args: {
schema: string;
libraries?: string;
cutSchemaDefinition?: boolean;
};
returned: ParserTree;
};
Expand Down Expand Up @@ -119,7 +121,16 @@ ctx.addEventListener("message", (message) => {
Parser.parse(args.schema),
args.libraries ? Parser.parse(args.libraries) : { nodes: [] }
);
console.log(mtress, args);
if (mtress.nodes) {
if (args.cutSchemaDefinition) {
return {
...mtress,
nodes: mtress.nodes.filter(
(n) => n.data.type !== TypeSystemDefinition.SchemaDefinition
),
};
}
return mtress;
}
throw new Error("No nodes to parse");
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.9.0",
"version": "6.9.1",
"private": false,
"license": "MIT",
"description": "Visual node editor for GraphQL",
Expand Down Expand Up @@ -45,8 +45,8 @@
"file-saver": "^2.0.5",
"framer-motion": "^10.12.16",
"fuzzyjs": "^5.0.1",
"graphql-editor-worker": "^6.9.0",
"graphql-js-tree": "^1.0.3",
"graphql-editor-worker": "^6.9.1",
"graphql-js-tree": "^1.0.5",
"graphql-language-service": "3.1.4",
"html-to-image": "^1.10.8",
"re-resizable": "^6.9.1",
Expand Down
5 changes: 4 additions & 1 deletion packages/editor/src/editor/Editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,10 @@ export const Editor = React.forwardRef<ExternalEditorAPI, EditorProps>(

useEffect(() => {
if (schema.libraries) {
GraphQLEditorWorker.generateTree(schema.libraries).then(setLibraryTree);
GraphQLEditorWorker.generateTree({
schema: schema.libraries,
cutSchemaDefinition: true,
}).then(setLibraryTree);
} else {
setLibraryTree({ nodes: [] });
}
Expand Down
11 changes: 4 additions & 7 deletions packages/editor/src/state/containers/trees/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,10 +243,10 @@ const useTreesStateContainer = createContainer(() => {
return;
}
try {
await GraphQLEditorWorker.generateTree(
schema.code,
schema.libraries
).then((parsedResult) => {
await GraphQLEditorWorker.generateTree({
schema: schema.code,
libraries: schema.libraries,
}).then((parsedResult) => {
setTree(
{
nodes: parsedResult.nodes,
Expand Down Expand Up @@ -340,7 +340,6 @@ const useTreesStateContainer = createContainer(() => {
};
const idempotentOperationAssign = (node: ParserField) => {
const nodeName = node.name.toLowerCase();
console.log(nodeName);
if (
!(
nodeName === "query" ||
Expand Down Expand Up @@ -383,7 +382,6 @@ const useTreesStateContainer = createContainer(() => {
tree.nodes = tree.nodes.filter(
(n) => n.data.type !== TypeSystemDefinition.SchemaDefinition
);
console.log(schemaNode);
tree.nodes.push(schemaNode);
};
const setOperationNode = (
Expand All @@ -401,7 +399,6 @@ const useTreesStateContainer = createContainer(() => {
type: node.name,
}),
];
console.log(n);
}
});
if (noSchemaDefinitionNode) {
Expand Down
1 change: 0 additions & 1 deletion packages/sandbox/apps/mergedLibraries.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ export const MergedLibraries = () => {
code: schemas.mergedLibs.code,
libraries: schemas.mergedLibs.libraries,
});
console.log(mySchema);
return (
<div
style={{
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.0",
"version": "6.9.1",
"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.0",
"graphql-editor": "^6.9.1",
"graphql-js-tree": "^0.1.6"
},
"config": {
Expand Down
6 changes: 6 additions & 0 deletions packages/sandbox/schema/mergedLibs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,11 @@ export const mergedLibs = {
type Animal{
kind: String
}
type Query{
health: String
}
type Mutation{
health: String
}
`,
};
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.0",
"version": "0.8.1",
"private": false,
"license": "MIT",
"description": "Sync folders with svg's to react typescript components",
Expand Down

0 comments on commit 0575013

Please sign in to comment.