Skip to content
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

[v3] migrate graphiql to vite and react compiler #3826

Open
wants to merge 68 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
68 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
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
bdd41ba
upd
dimaMachina Dec 25, 2024
fd8411b
Merge branch 'main' into react-compiler2
dimaMachina Dec 25, 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
5 changes: 5 additions & 0 deletions .changeset/stupid-lamps-search.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'graphiql': minor
---

migrate `graphiql` to `vite` and `react compiler`
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ module.exports = {
},
},
{
files: ['packages/graphiql-react/**'],
files: ['packages/{graphiql-react,graphiql}/**'],
plugins: ['react-compiler'],
rules: {
'@typescript-eslint/no-restricted-imports': [
Expand Down
4 changes: 0 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,8 @@ packages/codemirror-graphql/*.d.ts
packages/codemirror-graphql/*.map
!packages/codemirror-graphql/*.config.js

packages/graphiql/index.html
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: 2 additions & 0 deletions examples/monaco-graphql-webpack/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,13 @@
"cross-env": "^7.0.2",
"css-loader": "^6.7.3",
"file-loader": "6.2.0",
"fork-ts-checker-webpack-plugin": "7.3.0",
"html-webpack-plugin": "^5.5.0",
"monaco-editor-webpack-plugin": "^7.0.1",
"style-loader": "^3.3.1",
"typescript": "^4.6.3",
"webpack": "5.76.0",
"webpack-bundle-analyzer": "^3.6.1",
"webpack-cli": "^5.0.1",
"webpack-dev-server": "^4.11.1"
}
Expand Down
9 changes: 5 additions & 4 deletions 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 All @@ -46,8 +46,7 @@
"check": "yarn tsc --noEmit",
"cypress-open": "yarn workspace graphiql cypress-open",
"dev-graphiql": "yarn workspace graphiql dev",
"e2e": "yarn run e2e:build && yarn workspace graphiql e2e",
"e2e:build": "WEBPACK_SERVE=1 yarn workspace graphiql build-bundles",
"e2e": "yarn workspace graphiql e2e",
"eslint": "NODE_OPTIONS=--max-old-space-size=4096 ESLINT_USE_FLAT_CONFIG=false eslint --max-warnings=0 --ignore-path .gitignore --cache .",
"format": "yarn eslint --fix && yarn pretty",
"jest": "jest",
Expand Down Expand Up @@ -106,14 +105,15 @@
"@typescript-eslint/eslint-plugin": "^7.17.0",
"@typescript-eslint/parser": "^7.17.0",
"babel-jest": "^29.4.3",
"babel-plugin-macros": "^3.1.0",
"babel-plugin-transform-import-meta": "^2.2.1",
"concurrently": "^7.0.0",
"copy": "^0.3.2",
"cspell": "^5.15.2",
"eslint": "9.14.0",
"eslint-config-prettier": "^9.1.0",
"eslint-import-resolver-typescript": "^3.6.1",
"eslint-plugin-cypress": "^3.4.0",
"eslint-plugin-cypress": "^4.1.0",
"eslint-plugin-import-x": "^3.1.0",
"eslint-plugin-jest": "^28.6.0",
"eslint-plugin-mdx": "^3.1.5",
Expand All @@ -124,6 +124,7 @@
"eslint-plugin-sonarjs": "^1.0.4",
"eslint-plugin-unicorn": "^55.0.0",
"execa": "^7.1.1",
"identity-obj-proxy": "^3.0.0",
"fetch-mock": "6.5.2",
"husky": "^4.2.3",
"jest": "^27.5.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/graphiql-plugin-explorer/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@

### Patch Changes

- [#3124](https://github.com/graphql/graphiql/pull/3124) [`c645932c`](https://github.com/graphql/graphiql/commit/c645932c7973e11ad917e1d1d897fd409f8c042f) Thanks [@B2o5T](https://github.com/B2o5T)! - avoid unecessary renders by using useMemo or useCallback
- [#3124](https://github.com/graphql/graphiql/pull/3124) [`c645932c`](https://github.com/graphql/graphiql/commit/c645932c7973e11ad917e1d1d897fd409f8c042f) Thanks [@B2o5T](https://github.com/B2o5T)! - avoid unnecessary renders by using useMemo or useCallback

- Updated dependencies [[`911cf3e0`](https://github.com/graphql/graphiql/commit/911cf3e0b0fa13268245463c8db8299279e5c461), [`c645932c`](https://github.com/graphql/graphiql/commit/c645932c7973e11ad917e1d1d897fd409f8c042f), [`2ca4841b`](https://github.com/graphql/graphiql/commit/2ca4841baf74e87a3f067b3415f8da3347ee3898), [`7bf90929`](https://github.com/graphql/graphiql/commit/7bf90929f62ba812c0946e0424f9f843f7b6b0ff), [`431b7fe1`](https://github.com/graphql/graphiql/commit/431b7fe1efefa4867f0ea617adc436b1117052e8)]:
- @graphiql/[email protected]
Expand Down
2 changes: 1 addition & 1 deletion packages/graphiql-react/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@

- [#3194](https://github.com/graphql/graphiql/pull/3194) [`911cf3e0`](https://github.com/graphql/graphiql/commit/911cf3e0b0fa13268245463c8db8299279e5c461) Thanks [@dwwoelfel](https://github.com/dwwoelfel)! - fix tab content getting replaced on `changeTab`

- [#3124](https://github.com/graphql/graphiql/pull/3124) [`c645932c`](https://github.com/graphql/graphiql/commit/c645932c7973e11ad917e1d1d897fd409f8c042f) Thanks [@B2o5T](https://github.com/B2o5T)! - avoid unecessary renders by using useMemo or useCallback
- [#3124](https://github.com/graphql/graphiql/pull/3124) [`c645932c`](https://github.com/graphql/graphiql/commit/c645932c7973e11ad917e1d1d897fd409f8c042f) Thanks [@B2o5T](https://github.com/B2o5T)! - avoid unnecessary renders by using useMemo or useCallback

- [#3197](https://github.com/graphql/graphiql/pull/3197) [`2ca4841b`](https://github.com/graphql/graphiql/commit/2ca4841baf74e87a3f067b3415f8da3347ee3898) Thanks [@B2o5T](https://github.com/B2o5T)! - remove confusing ligatures, set `font-variant-ligatures: none`

Expand Down
4 changes: 2 additions & 2 deletions packages/graphiql-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"react-dom": "^16.8.0 || ^17 || ^18"
},
"dependencies": {
"react-compiler-runtime": "19.0.0-beta-37ed2a7-20241206",
"react-compiler-runtime": "0.0.0-experimental-22c6e49-20241219",
"@graphiql/toolkit": "^0.11.0",
"@headlessui/react": "^1.7.15",
"@radix-ui/react-dialog": "^1.0.4",
Expand All @@ -68,7 +68,7 @@
"set-value": "^4.1.0"
},
"devDependencies": {
"babel-plugin-react-compiler": "19.0.0-beta-37ed2a7-20241206",
"babel-plugin-react-compiler": "0.0.0-experimental-22c6e49-20241219",
"@types/react-dom": "^18.3.1",
"@babel/helper-string-parser": "^7.19.4",
"@testing-library/dom": "^10.4.0",
Expand Down
2 changes: 0 additions & 2 deletions packages/graphiql-react/src/editor/__tests__/common.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
'use no memo';

import { importCodeMirror } from '../common';

describe('importCodeMirror', () => {
Expand Down
2 changes: 0 additions & 2 deletions packages/graphiql-react/src/editor/__tests__/tabs.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
'use no memo';

import { StorageAPI } from '@graphiql/toolkit';
import {
createTab,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
'use no memo';

import { invalidCharacters, normalizeWhitespace } from '../whitespace';

describe('normalizeWhitespace', () => {
Expand Down
2 changes: 0 additions & 2 deletions packages/graphiql-react/src/editor/components/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
'use no memo';

export { HeaderEditor } from './header-editor';
export { ImagePreview } from './image-preview';
export { QueryEditor } from './query-editor';
Expand Down
2 changes: 0 additions & 2 deletions packages/graphiql-react/src/editor/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
'use no memo';

export {
HeaderEditor,
ImagePreview,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
'use no memo';

import { render } from '@testing-library/react';
import { GraphQLInt, GraphQLObjectType, GraphQLSchema } from 'graphql';
import { useContext, useEffect } from 'react';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
'use no memo';

import { fireEvent, render } from '@testing-library/react';
import { GraphQLString, GraphQLObjectType, Kind } from 'graphql';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
'use no memo';

import { fireEvent, render } from '@testing-library/react';
import {
GraphQLBoolean,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
'use no memo';

import { fireEvent, render } from '@testing-library/react';
import { GraphQLNonNull, GraphQLList, GraphQLString } from 'graphql';
import { ComponentProps } from 'react';
Expand Down
63 changes: 24 additions & 39 deletions packages/graphiql-react/src/explorer/components/search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,7 @@ import {
isInterfaceType,
isObjectType,
} from 'graphql';
import {
FocusEventHandler,
// eslint-disable-next-line @typescript-eslint/no-restricted-imports
useCallback,
useEffect,
// eslint-disable-next-line @typescript-eslint/no-restricted-imports
useMemo,
useRef,
useState,
} from 'react';
import { FocusEventHandler, useEffect, useRef, useState } from 'react';
import { Combobox } from '@headlessui/react';
import { MagnifyingGlassIcon } from '../../icons';
import { useSchemaContext } from '../../schema';
Expand All @@ -29,31 +20,26 @@ import { renderType } from './utils';
import { isMacOs } from '../../utility/is-macos';

export function Search() {
'use no memo'; // TODO: add test https://github.com/graphql/graphiql/issues/3842
const { explorerNavStack, push } = useExplorerContext({
nonNull: true,
caller: Search,
});

const inputRef = useRef<HTMLInputElement>(null);
const inputRef = useRef<HTMLInputElement>(null!);
const getSearchResults = useSearchResults();
const [searchValue, setSearchValue] = useState('');
const [results, setResults] = useState(getSearchResults(searchValue));
const debouncedGetSearchResults = useMemo(
() =>
debounce(200, (search: string) => {
setResults(getSearchResults(search));
}),
[getSearchResults],
);
const [results, setResults] = useState(() => getSearchResults(searchValue));
const debouncedGetSearchResults = debounce(200, (search: string) => {
setResults(getSearchResults(search));
});
useEffect(() => {
debouncedGetSearchResults(searchValue);
}, [debouncedGetSearchResults, searchValue]);

useEffect(() => {
function handleKeyDown(event: KeyboardEvent) {
if (event.metaKey && event.key === 'k') {
inputRef.current?.focus();
inputRef.current.focus();
}
}

Expand All @@ -63,20 +49,20 @@ export function Search() {

const navItem = explorerNavStack.at(-1)!;

const onSelect = useCallback(
(def: TypeMatch | FieldMatch) => {
push(
'field' in def
? { name: def.field.name, def: def.field }
: { name: def.type.name, def: def.type },
);
},
[push],
);
const isFocused = useRef(false);
const handleFocus: FocusEventHandler = useCallback(e => {
isFocused.current = e.type === 'focus';
}, []);
const onSelect = (def: TypeMatch | FieldMatch) => {
push(
'field' in def
? { name: def.field.name, def: def.field }
: { name: def.type.name, def: def.type },
);
};
const [isFocused, setIsFocused] = useState(false);
const handleFocus: FocusEventHandler = e => {
// Fix https://github.com/graphql/graphiql/issues/3842
setTimeout(() => {
setIsFocused(e.type === 'focus');
}, 0);
};

const shouldSearchBoxAppear =
explorerNavStack.length === 1 ||
Expand All @@ -98,7 +84,7 @@ export function Search() {
<div
className="graphiql-doc-explorer-search-input"
onClick={() => {
inputRef.current?.focus();
inputRef.current.focus();
}}
>
<MagnifyingGlassIcon />
Expand All @@ -115,8 +101,7 @@ export function Search() {
</div>

{/* display on focus */}
{/* eslint-disable-next-line react-compiler/react-compiler */}
{isFocused.current && (
{isFocused && (
<Combobox.Options data-cy="doc-explorer-list">
{results.within.length +
results.types.length +
Expand Down Expand Up @@ -269,7 +254,7 @@ export function useSearchResults(caller?: Function) {
function isMatch(sourceText: string, searchValue: string): boolean {
try {
const escaped = searchValue.replaceAll(/[^_0-9A-Za-z]/g, ch => '\\' + ch);
return sourceText.search(new RegExp(escaped, 'i')) !== -1;
return new RegExp(escaped, 'i').test(sourceText);
} catch {
return sourceText.toLowerCase().includes(searchValue.toLowerCase());
}
Expand Down
2 changes: 0 additions & 2 deletions packages/graphiql-react/src/explorer/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
'use no memo';

export { Argument } from './components/argument';
export { DefaultValue } from './components/default-value';
export { DeprecationReason } from './components/deprecation-reason';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
'use no memo';

import { Mock } from 'vitest';
import { fireEvent, render } from '@testing-library/react';
import { ComponentProps } from 'react';
Expand Down
17 changes: 13 additions & 4 deletions packages/graphiql-react/src/history/components.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,21 @@ import {
TrashIcon,
} from '../icons';
import { Button, Tooltip, UnStyledButton } from '../ui';
import { useHistoryContext } from './context';
import { HistoryContextType, useHistoryContext } from './context';

import './style.css';

// Fix error from react-compiler
// Support value blocks (conditional, logical, optional chaining, etc) within a try/catch statement
function handleDelete(
items: QueryStoreItem[],
deleteFromHistory: HistoryContextType['deleteFromHistory'],
) {
for (const item of items) {
deleteFromHistory(item, true);
}
}

export function History() {
const { items: all, deleteFromHistory } = useHistoryContext({
nonNull: true,
Expand Down Expand Up @@ -45,9 +56,7 @@ export function History() {

const handleClearStatus = () => {
try {
for (const item of items) {
deleteFromHistory(item, true);
}
handleDelete(items, deleteFromHistory);
setClearStatus('success');
} catch {
setClearStatus('error');
Expand Down
2 changes: 0 additions & 2 deletions packages/graphiql-react/src/history/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
'use no memo';

export { History } from './components';
export {
HistoryContext,
Expand Down
2 changes: 0 additions & 2 deletions packages/graphiql-react/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
'use no memo';

import './style/root.css';

export {
Expand Down
2 changes: 0 additions & 2 deletions packages/graphiql-react/src/toolbar/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
'use no memo';

export * from './button';
export * from './execute';
export * from './menu';
2 changes: 0 additions & 2 deletions packages/graphiql-react/src/ui/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
'use no memo';

export * from './button';
export * from './button-group';
export * from './dialog';
Expand Down
Loading
Loading