-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[3634] Simplifying the contribution to the GraphQL subscription of th…
…e diagram for custom nodes Bug: #3634 Signed-off-by: Michaël Charfadi <[email protected]>
- Loading branch information
1 parent
11e5b3b
commit f3c26b7
Showing
13 changed files
with
145 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
packages/sirius-web/frontend/sirius-web/src/nodes/ElipseNodeDocumentTransform.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2024 Obeo. | ||
* This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v2.0 | ||
* which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Obeo - initial API and implementation | ||
*******************************************************************************/ | ||
|
||
import { DocumentTransform } from '@apollo/client'; | ||
import { DocumentNode, FieldNode, InlineFragmentNode, Kind, SelectionNode, visit } from 'graphql'; | ||
|
||
const shouldTransform = (document: DocumentNode) => { | ||
return ( | ||
document.definitions[0] && | ||
document.definitions[0].kind === Kind.OPERATION_DEFINITION && | ||
document.definitions[0].name?.value === 'diagramEvent' | ||
); | ||
}; | ||
|
||
const isNodeStyleFragment = (field: FieldNode) => { | ||
if (field.name.value === 'style') { | ||
const inLinesFragment = field.selectionSet.selections | ||
.filter((selection) => selection.kind === Kind.INLINE_FRAGMENT) | ||
.map((inlineFragment: InlineFragmentNode) => inlineFragment.typeCondition.name.value); | ||
if (inLinesFragment.includes('RectangularNodeStyle') && inLinesFragment.includes('ImageNodeStyle')) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
}; | ||
|
||
const borderColorField: SelectionNode = { | ||
kind: Kind.FIELD, | ||
name: { | ||
kind: Kind.NAME, | ||
value: 'borderColor', | ||
}, | ||
}; | ||
|
||
const borderSizeField: SelectionNode = { | ||
kind: Kind.FIELD, | ||
name: { | ||
kind: Kind.NAME, | ||
value: 'borderSize', | ||
}, | ||
}; | ||
|
||
const borderStyleField: SelectionNode = { | ||
kind: Kind.FIELD, | ||
name: { | ||
kind: Kind.NAME, | ||
value: 'borderStyle', | ||
}, | ||
}; | ||
|
||
const backgroundField: SelectionNode = { | ||
kind: Kind.FIELD, | ||
name: { | ||
kind: Kind.NAME, | ||
value: 'background', | ||
}, | ||
}; | ||
|
||
export const ellipseNodeStyleDocumentTransform = new DocumentTransform((document) => { | ||
if (shouldTransform(document)) { | ||
const transformedDocument = visit(document, { | ||
Field(field) { | ||
if (!isNodeStyleFragment(field)) { | ||
return undefined; | ||
} | ||
|
||
const selections = field.selectionSet?.selections ?? []; | ||
|
||
const ellipseNodeStyleInlineFragment: InlineFragmentNode = { | ||
kind: Kind.INLINE_FRAGMENT, | ||
selectionSet: { | ||
kind: Kind.SELECTION_SET, | ||
selections: [borderColorField, borderSizeField, borderStyleField, backgroundField], | ||
}, | ||
typeCondition: { | ||
kind: Kind.NAMED_TYPE, | ||
name: { | ||
kind: Kind.NAME, | ||
value: 'EllipseNodeStyle', | ||
}, | ||
}, | ||
}; | ||
|
||
return { | ||
...field, | ||
selectionSet: { | ||
...field.selectionSet, | ||
selections: [...selections, ellipseNodeStyleInlineFragment], | ||
}, | ||
}; | ||
}, | ||
}); | ||
|
||
return transformedDocument; | ||
} | ||
return document; | ||
}); |