Skip to content

Commit 9f703c9

Browse files
notKvSanwarulislam
andauthored
fix(common): GraphQL argument addition and click event propagation (hoppscotch#5448)
Co-authored-by: Viraj <[email protected]> Co-authored-by: Anwarul Islam <[email protected]>
1 parent 4c1911c commit 9f703c9

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

packages/hoppscotch-common/src/components/graphql/Argument.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
v-if="showAddButton"
1919
class="hover:text-accent cursor-pointer flex items-center justify-center px-4 py-2"
2020
:class="{ 'text-accent': isArgumentInOperation(arg) }"
21-
@click="insertQuery"
21+
@click.stop="insertQuery"
2222
>
2323
<icon-lucide-plus-circle
2424
v-if="!isArgumentInOperation(arg)"

packages/hoppscotch-common/src/helpers/graphql/query.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
FieldNode,
66
getNamedType,
77
GraphQLArgument,
8+
GraphQLField,
89
GraphQLType,
910
Kind,
1011
OperationDefinitionNode,
@@ -95,7 +96,7 @@ export function useQuery() {
9596
*/
9697
const createFieldNode = (
9798
name: string,
98-
args: GraphQLArgument[] | undefined,
99+
args: readonly GraphQLArgument[] | undefined,
99100
hasNestedFields = false
100101
): Mutable<FieldNode> => ({
101102
kind: Kind.FIELD,
@@ -145,8 +146,10 @@ export function useQuery() {
145146
// Build from bottom up starting with the last field
146147
let currentSelection = createFieldNode(
147148
lastItem.name,
148-
lastItem.def?.args,
149-
lastItem.def?.fields?.length > 0
149+
isArgument && argumentItem
150+
? [argumentItem.def as GraphQLArgument]
151+
: (lastItem.def as GraphQLField<unknown, unknown>)?.args,
152+
lastItem.def && (lastItem.def as any)?.fields?.length > 0
150153
)
151154

152155
for (let i = queryPath.length - 2; i >= 0; i--) {
@@ -260,7 +263,9 @@ export function useQuery() {
260263
} else {
261264
const newField = createFieldNode(
262265
item.name,
263-
(item.def as any)?.args, // these type assertion is avoidable
266+
isLastItem && isArgument && argumentItem
267+
? [argumentItem.def as GraphQLArgument]
268+
: (item.def as GraphQLField<unknown, unknown>)?.args,
264269
!isLastItem || (isLastItem && (item.def as any)?.fields?.length > 0)
265270
)
266271

@@ -280,7 +285,7 @@ export function useQuery() {
280285
}
281286
}
282287

283-
currentSelectionSet.selections.push(newField)
288+
;(currentSelectionSet.selections as Mutable<FieldNode[]>).push(newField)
284289

285290
if (!isLastItem) {
286291
// Move to the next level
@@ -419,7 +424,7 @@ export function useQuery() {
419424
fieldNode.loc.start <= cursorPosition &&
420425
fieldNode.loc.end >= cursorPosition
421426
) {
422-
args = fieldNode.arguments || []
427+
args = [...(fieldNode.arguments || [])]
423428
}
424429
}
425430
})

0 commit comments

Comments
 (0)