Skip to content

Commit 9585f11

Browse files
authored
Fix: share operation graphiql to lab (#7839)
1 parent 4233513 commit 9585f11

4 files changed

Lines changed: 17 additions & 15 deletions

File tree

.changeset/tall-guests-slide.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@graphql-hive/laboratory': patch
3+
'@graphql-hive/render-laboratory': patch
4+
---
5+
6+
exposed renderLaboratory function to use window location as default endpoint

packages/libraries/laboratory/src/index.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ export const renderLaboratory = (el: HTMLElement) => {
3636
return ReactDOM.createRoot(el).render(
3737
<Laboratory
3838
theme="dark"
39-
defaultEndpoint={getLocalStorage('endpoint') ?? null}
39+
defaultEndpoint={
40+
getLocalStorage('endpoint') ?? window.location.origin + window.location.pathname
41+
}
4042
onEndpointChange={endpoint => {
4143
setLocalStorage('endpoint', endpoint ?? '');
4244
}}

packages/web/app/src/lib/hooks/laboratory/use-current-operation.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ export function useCurrentOperationWithFetchingState(props: {
6161
id: operationIdFromSearch || '',
6262
},
6363
pause: !operationIdFromSearch,
64+
requestPolicy: 'network-only',
6465
});
6566

6667
return {

packages/web/app/src/pages/target-laboratory-new.tsx

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import { useRedirect } from '@/lib/access/common';
2828
import { useLocalStorage, useToggle } from '@/lib/hooks';
2929
import { useCurrentOperationWithFetchingState } from '@/lib/hooks/laboratory/use-current-operation';
3030
import { TargetLaboratoryPageQuery } from '@/lib/hooks/laboratory/use-operation-collections-plugin';
31-
import { useSyncOperationState } from '@/lib/hooks/laboratory/use-sync-operation-state';
3231
import { useOperationFromQueryString } from '@/lib/hooks/laboratory/useOperationFromQueryString';
3332
import { useResetState } from '@/lib/hooks/use-reset-state';
3433
import { cn } from '@/lib/utils';
@@ -403,7 +402,7 @@ function useLaboratoryState(props: {
403402

404403
const deleteOperation = useMemo(
405404
() =>
406-
throttle((collection: LaboratoryCollection, operation: LaboratoryCollectionOperation) => {
405+
throttle((_collection: LaboratoryCollection, operation: LaboratoryCollectionOperation) => {
407406
void mutateDelete({
408407
selector: {
409408
targetSlug: props.targetSlug,
@@ -478,32 +477,26 @@ function useLaboratoryState(props: {
478477
targetSlug: props.targetSlug,
479478
});
480479

481-
const { savedOperation } = useSyncOperationState({
482-
organizationSlug: props.organizationSlug,
483-
projectSlug: props.projectSlug,
484-
targetSlug: props.targetSlug,
485-
});
486-
487480
const defaultOperations = useMemo(() => {
488-
if (currentOperation && savedOperation) {
481+
if (currentOperation) {
489482
return [
490483
...getLocalStorageState('operations', []),
491484
{
492485
id: currentOperation.id,
493486
name: currentOperation.name,
494-
query: savedOperation.query,
495-
variables: savedOperation.variables ?? '{}',
487+
query: currentOperation.query,
488+
variables: currentOperation.variables ?? '{}',
496489
headers: currentOperation.headers ?? '{}',
497490
extensions: '{}',
498491
} satisfies LaboratoryOperation,
499492
];
500493
}
501494

502495
return getLocalStorageState('operations', []);
503-
}, [currentOperation, savedOperation]);
496+
}, [currentOperation]);
504497

505498
const defaultTabs = useMemo(() => {
506-
if (currentOperation && savedOperation) {
499+
if (currentOperation) {
507500
return [
508501
...getLocalStorageState('tabs', []),
509502
{
@@ -522,7 +515,7 @@ function useLaboratoryState(props: {
522515
}
523516

524517
return getLocalStorageState('tabs', []);
525-
}, [currentOperation, savedOperation]);
518+
}, [currentOperation]);
526519

527520
const operationIdFromSearch = useOperationFromQueryString();
528521

0 commit comments

Comments
 (0)