Skip to content

[wip] migrate graphql-language-service-server to vitest #3834

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 91 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
91 commits
Select commit Hold shift + click to select a range
f590ae4
aa
dimaMachina Dec 11, 2024
810b0b2
aa
dimaMachina Dec 11, 2024
8066724
aa
dimaMachina Dec 11, 2024
4039e39
aa
dimaMachina Dec 11, 2024
4b7e458
aa
dimaMachina Dec 11, 2024
777eac5
aa
dimaMachina Dec 11, 2024
3786aca
aa
dimaMachina Dec 11, 2024
e1260f4
aa
dimaMachina Dec 11, 2024
1c5c46f
aa
dimaMachina Dec 11, 2024
16424ae
aa
dimaMachina Dec 11, 2024
dae03ba
aa
dimaMachina Dec 11, 2024
e1b3cc5
aa
dimaMachina Dec 11, 2024
67a2250
aa
dimaMachina Dec 11, 2024
2be769b
[skip ci]
dimaMachina Dec 13, 2024
785c103
fix
dimaMachina Dec 13, 2024
9a0a3cd
migrate `graphiql` from `jest` to `vitest`
dimaMachina Dec 13, 2024
a862023
add .js extension
dimaMachina Dec 13, 2024
3f3472a
add .js extension
dimaMachina Dec 13, 2024
5fd2901
Merge branch 'do-not-bundle-codemirror' into graphiql-vitest
dimaMachina Dec 13, 2024
be801e4
upd
dimaMachina Dec 13, 2024
398b087
upd
dimaMachina Dec 13, 2024
a337e82
Merge branch 'do-not-bundle-codemirror' into graphiql-vitest
dimaMachina Dec 13, 2024
731082d
upd
dimaMachina Dec 13, 2024
f69cd78
upd
dimaMachina Dec 13, 2024
ce223e3
upd
dimaMachina Dec 13, 2024
6f6f481
upd
dimaMachina Dec 13, 2024
a04d46d
upd
dimaMachina Dec 13, 2024
1be7078
Merge branch 'do-not-bundle-codemirror' into react-compiler
dimaMachina Dec 13, 2024
adf7725
Merge branch 'graphiql-vitest' into react-compiler
dimaMachina Dec 13, 2024
d6f62d4
upd
dimaMachina Dec 13, 2024
3ecae05
upd
dimaMachina Dec 13, 2024
8092f10
upd
dimaMachina Dec 13, 2024
ab2fec8
add
dimaMachina Dec 13, 2024
63bb7b4
upd
dimaMachina Dec 14, 2024
25129f5
upd
dimaMachina Dec 14, 2024
d2fb423
upd
dimaMachina Dec 14, 2024
1968198
upd
dimaMachina Dec 14, 2024
d7e2434
upd
dimaMachina Dec 14, 2024
57348be
upd
dimaMachina Dec 14, 2024
b28be43
upd
dimaMachina Dec 14, 2024
3546a58
upd
dimaMachina Dec 14, 2024
cc537f6
clean up deps
dimaMachina Dec 14, 2024
4031182
clean up deps
dimaMachina Dec 14, 2024
1878a0b
clean up deps
dimaMachina Dec 14, 2024
7453fe4
clean up deps
dimaMachina Dec 14, 2024
63674ed
clean up deps
dimaMachina Dec 14, 2024
dfb7578
upd
dimaMachina Dec 14, 2024
4993c1c
upd
dimaMachina Dec 14, 2024
12cd0b6
more changes from graphiql v4
dimaMachina Dec 14, 2024
1b91371
more
dimaMachina Dec 14, 2024
2f829f8
fix path isn't exported
dimaMachina Dec 14, 2024
4a23084
fix integration tests
dimaMachina Dec 14, 2024
6e95096
fix e2e
dimaMachina Dec 14, 2024
948fef0
bump
dimaMachina Dec 14, 2024
8c34ceb
add changeset
dimaMachina Dec 14, 2024
8410fed
remove unneeded beforeDevServer.js
dimaMachina Dec 14, 2024
d89dc49
found case which was not optimized
dimaMachina Dec 14, 2024
346a936
Merge branch 'main' into react-compiler2
dimaMachina Dec 14, 2024
460b51e
Delete .changeset/sour-onions-rhyme.md
dimaMachina Dec 14, 2024
42f65cc
Delete .changeset/silly-nails-double.md
dimaMachina Dec 14, 2024
65778d2
Merge branch 'main' into react-compiler2
dimaMachina Dec 14, 2024
d4d9062
polish graphiql tests setup
dimaMachina Dec 14, 2024
107e0b6
polish graphiql tests setup
dimaMachina Dec 14, 2024
22c4e7a
upd
dimaMachina Dec 14, 2024
dc8a6a5
upd
dimaMachina Dec 14, 2024
935cd6c
upd
dimaMachina Dec 14, 2024
130ee12
more
dimaMachina Dec 14, 2024
7f2fa66
more
dimaMachina Dec 14, 2024
20fa910
more
dimaMachina Dec 14, 2024
5d93679
more
dimaMachina Dec 14, 2024
009f8d8
more
dimaMachina Dec 14, 2024
403de21
more
dimaMachina Dec 14, 2024
79a5061
more
dimaMachina Dec 14, 2024
13304f0
more [skip ci]
dimaMachina Dec 14, 2024
69f401d
more [skip ci]
dimaMachina Dec 14, 2024
f252dcd
more
dimaMachina Dec 14, 2024
f5742e9
more
dimaMachina Dec 14, 2024
b60581e
more
dimaMachina Dec 14, 2024
05b8540
rm
dimaMachina Dec 14, 2024
fbca258
rm
dimaMachina Dec 14, 2024
0dc6f86
rm
dimaMachina Dec 14, 2024
439e7a5
rm babel
dimaMachina Dec 14, 2024
2c9d960
rm
dimaMachina Dec 14, 2024
a88a00b
rollback
dimaMachina Dec 14, 2024
c080231
fix build
dimaMachina Dec 14, 2024
8cc4fcf
Merge branch 'main' into react-compiler2
dimaMachina Dec 14, 2024
e0949ac
should be good
dimaMachina Dec 14, 2024
ad75cda
prettier
dimaMachina Dec 14, 2024
fe75b41
Merge branch 'react-compiler2' into gls-server
dimaMachina Dec 14, 2024
75b6457
fix ci
dimaMachina Dec 14, 2024
21d467d
polish
dimaMachina Dec 14, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
upd
  • Loading branch information
dimaMachina committed Dec 14, 2024
commit 63bb7b4740c890c2c148959c05f0f2cea3fcdffa
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,8 @@ packages/codemirror-graphql/*.d.ts
packages/codemirror-graphql/*.map
!packages/codemirror-graphql/*.config.js

packages/graphiql/dev.html
packages/graphiql/analyzer.html
packages/graphiql/graphiql*.js
packages/graphiql/*.css
packages/graphiql/*.map
packages/graphiql/cypress/screenshots/
packages/graphiql/typedoc/
packages/graphiql/webpack/
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"scripts": {
"build": "yarn build-clean && yarn tsc && yarn build:nontsc",
"build-bundles": "yarn prebuild-bundles && yarn wsrun:noexamples --stages build-bundles",
"build-bundles-clean": "rimraf '{packages,examples,plugins}/**/{bundle,cdn,webpack}' && yarn workspace graphiql build-bundles-clean",
"build-bundles-clean": "rimraf '{packages,examples}/**/{bundle,cdn,webpack}'",
"build-clean": "yarn tsc --clean",
"build-docs": "rimraf packages/graphiql/typedoc && typedoc packages",
"build:nontsc": "yarn wsrun:noexamples --exclude-missing --serial build",
Expand Down
189 changes: 79 additions & 110 deletions packages/graphiql/src/GraphiQL.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@ import React, {
PropsWithChildren,
ReactNode,
ReactElement,
useCallback,
useState,
useEffect,
useMemo,
} from 'react';

import {
Expand Down Expand Up @@ -254,13 +252,10 @@ export function GraphiQLInterface(props: GraphiQLInterfaceProps) {
const schemaContext = useSchemaContext({ nonNull: true });
const storageContext = useStorageContext();
const pluginContext = usePluginContext();
const forcedTheme = useMemo(
() =>
props.forcedTheme && THEMES.includes(props.forcedTheme)
? props.forcedTheme
: undefined,
[props.forcedTheme],
);
const forcedTheme =
props.forcedTheme && THEMES.includes(props.forcedTheme)
? props.forcedTheme
: undefined;

const copy = useCopyQuery({ onCopyQuery: props.onCopyQuery });
const merge = useMergeQuery();
Expand Down Expand Up @@ -378,97 +373,80 @@ export function GraphiQLInterface(props: GraphiQLInterfaceProps) {
}
}, [pluginResize]);

const handleClearData = useCallback(() => {
const handleClearData = () => {
try {
storageContext?.clear();
setClearStorageStatus('success');
} catch {
setClearStorageStatus('error');
}
}, [storageContext]);
};

const handlePersistHeaders: MouseEventHandler<HTMLButtonElement> =
useCallback(
event => {
editorContext.setShouldPersistHeaders(
event.currentTarget.dataset.value === 'true',
);
},
[editorContext],
const handlePersistHeaders: MouseEventHandler<HTMLButtonElement> = event => {
editorContext.setShouldPersistHeaders(
event.currentTarget.dataset.value === 'true',
);
};

const handleChangeTheme: MouseEventHandler<HTMLButtonElement> = useCallback(
event => {
const selectedTheme = event.currentTarget.dataset.theme as
| 'light'
| 'dark'
| undefined;
setTheme(selectedTheme || null);
},
[setTheme],
);
const handleChangeTheme: MouseEventHandler<HTMLButtonElement> = event => {
const selectedTheme = event.currentTarget.dataset.theme as
| 'light'
| 'dark'
| undefined;
setTheme(selectedTheme || null);
};

const handleAddTab = editorContext.addTab;
const handleRefetchSchema = schemaContext.introspect;
const handleReorder = editorContext.moveTab;

const handleShowDialog: MouseEventHandler<HTMLButtonElement> = useCallback(
event => {
setShowDialog(
event.currentTarget.dataset.value as 'short-keys' | 'settings',
);
},
[],
);
const handleShowDialog: MouseEventHandler<HTMLButtonElement> = event => {
setShowDialog(
event.currentTarget.dataset.value as 'short-keys' | 'settings',
);
};

const handlePluginClick: MouseEventHandler<HTMLButtonElement> = useCallback(
event => {
const context = pluginContext!;
const pluginIndex = Number(event.currentTarget.dataset.index!);
const plugin = context.plugins.find((_, index) => pluginIndex === index)!;
const isVisible = plugin === context.visiblePlugin;
if (isVisible) {
context.setVisiblePlugin(null);
pluginResize.setHiddenElement('first');
} else {
context.setVisiblePlugin(plugin);
pluginResize.setHiddenElement(null);
}
},
[pluginContext, pluginResize],
);
const handlePluginClick: MouseEventHandler<HTMLButtonElement> = event => {
const context = pluginContext!;
const pluginIndex = Number(event.currentTarget.dataset.index!);
const plugin = context.plugins.find((_, index) => pluginIndex === index)!;
const isVisible = plugin === context.visiblePlugin;
if (isVisible) {
context.setVisiblePlugin(null);
pluginResize.setHiddenElement('first');
} else {
context.setVisiblePlugin(plugin);
pluginResize.setHiddenElement(null);
}
};

const handleToolsTabClick: MouseEventHandler<HTMLButtonElement> = useCallback(
event => {
if (editorToolsResize.hiddenElement === 'second') {
editorToolsResize.setHiddenElement(null);
}
setActiveSecondaryEditor(
event.currentTarget.dataset.name as 'variables' | 'headers',
);
},
[editorToolsResize],
);
const handleToolsTabClick: MouseEventHandler<HTMLButtonElement> = event => {
if (editorToolsResize.hiddenElement === 'second') {
editorToolsResize.setHiddenElement(null);
}
setActiveSecondaryEditor(
event.currentTarget.dataset.name as 'variables' | 'headers',
);
};

const toggleEditorTools: MouseEventHandler<HTMLButtonElement> =
useCallback(() => {
editorToolsResize.setHiddenElement(
editorToolsResize.hiddenElement === 'second' ? null : 'second',
);
}, [editorToolsResize]);
const toggleEditorTools: MouseEventHandler<HTMLButtonElement> = () => {
editorToolsResize.setHiddenElement(
editorToolsResize.hiddenElement === 'second' ? null : 'second',
);
};

const handleOpenShortKeysDialog = useCallback((isOpen: boolean) => {
const handleOpenShortKeysDialog = (isOpen: boolean) => {
if (!isOpen) {
setShowDialog(null);
}
}, []);
};

const handleOpenSettingsDialog = useCallback((isOpen: boolean) => {
const handleOpenSettingsDialog = (isOpen: boolean) => {
if (!isOpen) {
setShowDialog(null);
setClearStorageStatus(null);
}
}, []);
};

const addTab = (
<Tooltip label="Add tab">
Expand All @@ -486,46 +464,37 @@ export function GraphiQLInterface(props: GraphiQLInterfaceProps) {
const className = props.className ? ` ${props.className}` : '';
const confirmClose = props.confirmCloseTab;

const handleTabClose: MouseEventHandler<HTMLButtonElement> = useCallback(
async event => {
const tabButton = event.currentTarget
.previousSibling as HTMLButtonElement;
const index = Number(tabButton.id.replace(TAB_CLASS_PREFIX, ''));
const handleTabClose: MouseEventHandler<HTMLButtonElement> = async event => {
const tabButton = event.currentTarget.previousSibling as HTMLButtonElement;
const index = Number(tabButton.id.replace(TAB_CLASS_PREFIX, ''));

/** TODO:
* Move everything after into `editorContext.closeTab` once zustand will be used instead of
* React context, since now we can't use execution context inside editor context, since editor
* context is used in execution context.
*/
const shouldCloseTab = confirmClose ? await confirmClose(index) : true;

if (!shouldCloseTab) {
return;
}
/** TODO:
* Move everything after into `editorContext.closeTab` once zustand will be used instead of
* React context, since now we can't use execution context inside editor context, since editor
* context is used in execution context.
*/
const shouldCloseTab = confirmClose ? await confirmClose(index) : true;

if (editorContext.activeTabIndex === index) {
executionContext.stop();
}
editorContext.closeTab(index);
},
[confirmClose, editorContext, executionContext],
);
if (!shouldCloseTab) {
return;
}

const handleTabClick: MouseEventHandler<HTMLButtonElement> = useCallback(
event => {
const index = Number(
event.currentTarget.id.replace(TAB_CLASS_PREFIX, ''),
);
/** TODO:
* Move everything after into `editorContext.changeTab` once zustand will be used instead of
* React context, since now we can't use execution context inside editor context, since editor
* context is used in execution context.
*/
if (editorContext.activeTabIndex === index) {
executionContext.stop();
editorContext.changeTab(index);
},
[editorContext, executionContext],
);
}
editorContext.closeTab(index);
};

const handleTabClick: MouseEventHandler<HTMLButtonElement> = event => {
const index = Number(event.currentTarget.id.replace(TAB_CLASS_PREFIX, ''));
/** TODO:
* Move everything after into `editorContext.changeTab` once zustand will be used instead of
* React context, since now we can't use execution context inside editor context, since editor
* context is used in execution context.
*/
executionContext.stop();
editorContext.changeTab(index);
};

return (
<Tooltip.Provider>
Expand Down
2 changes: 2 additions & 0 deletions packages/graphiql/src/cdn.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use no memo';

/**
* Copyright (c) 2021 GraphQL Contributors.
*
Expand Down
2 changes: 2 additions & 0 deletions packages/graphiql/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use no memo';

/**
* Copyright (c) 2021 GraphQL Contributors.
*
Expand Down
22 changes: 0 additions & 22 deletions packages/graphiql/tsconfig.esm.json

This file was deleted.

28 changes: 25 additions & 3 deletions packages/graphiql/vite.config.mts
Original file line number Diff line number Diff line change
@@ -1,7 +1,29 @@
import { sep } from 'node:path';
import { defineConfig, PluginOption } from 'vite';
import packageJSON from './package.json';
import dts from 'vite-plugin-dts';
import commonjs from 'vite-plugin-commonjs';
import react from '@vitejs/plugin-react';
import packageJSON from './package.json';

const ReactCompilerConfig = {
target: '17',
sources(filename) {
if (!filename.includes(`packages${sep}graphiql${sep}`)) {
return false;
}
// eslint-disable-next-line no-console
console.log({ filename });
return true;
},
};

const plugins = [
react({
babel: {
plugins: [['babel-plugin-react-compiler', ReactCompilerConfig]],
},
}),
];

const umdConfig = defineConfig({
define: {
Expand All @@ -12,7 +34,7 @@ const umdConfig = defineConfig({
'process.env.NODE_ENV': '"production"',
},
// To bundle `const { createClient } = require('graphql-ws')` in `createWebsocketsFetcherFromUrl` function
plugins: [commonjs()],
plugins: [...plugins, commonjs()],
build: {
minify: 'terser', // produce less bundle size
sourcemap: true,
Expand Down Expand Up @@ -64,7 +86,7 @@ const esmConfig = defineConfig({
},
},
},
plugins: [htmlPlugin(), dts({ rollupTypes: true })],
plugins: [...plugins, htmlPlugin(), dts({ rollupTypes: true })],
});

function htmlPlugin(): PluginOption {
Expand Down
2 changes: 1 addition & 1 deletion resources/patches/@vitejs+plugin-react+4.3.1.patch
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ index e61f42b..a6ad925 100644
});
if (result) {
let code2 = result.code;
+ if (filepath.includes('graphiql-react')) {
+ if (/packages[/\\](graphiql|graphiql-react)[/\\]/.test(filepath)) {
+ if (
+ /^import \{ c as _c } from "/m.test(code2)
+ ) {
Expand Down
Loading