Skip to content

Commit

Permalink
persist still not working
Browse files Browse the repository at this point in the history
  • Loading branch information
acao committed Sep 3, 2024
1 parent 4194a3d commit b213ceb
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 31 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"build-docs": "rimraf packages/graphiql/typedoc && typedoc packages",
"build:nontsc": "yarn wsrun:noexamples --exclude-missing --serial build",
"build:clean": "yarn tsc --clean",
"build:watch": "yarn tsc --watch",
"build:watch": "yarn wsrun:noexamples --done-criteria '\"Build success in|built in\"' -t dev",
"build-demo": "wsrun -m build-demo",
"watch": "yarn build:watch",
"watch-vscode": "yarn tsc && yarn workspace vscode-graphql compile",
Expand Down
48 changes: 23 additions & 25 deletions packages/graphiql-react/src/provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,36 +80,34 @@ export function GraphiQLProvider({
variables,
visiblePlugin,
}: GraphiQLProviderProps) {
const store = useMemo(
() =>
createGraphiQLStore({
defaultQuery,
defaultHeaders,
defaultTabs,
externalFragments,
fetcher,
getDefaultFieldNames,
headers,
inputValueDeprecation,
introspectionQueryName,
onEditOperationName,
onSchemaChange,
onTabChange,
schema,
schemaDescription,
shouldPersistHeaders,
validationRules,
dangerouslyAssumeSchemaIsValid,
fetchOptions,
}),
[defaultQuery],
);
const store = useRef(
createGraphiQLStore({
defaultQuery,
defaultHeaders,
defaultTabs,
externalFragments,
fetcher,
getDefaultFieldNames,
headers,
inputValueDeprecation,
introspectionQueryName,
onEditOperationName,
onSchemaChange,
onTabChange,
schema,
schemaDescription,
shouldPersistHeaders,
validationRules,
dangerouslyAssumeSchemaIsValid,
fetchOptions,
}),
).current;

const state = useStore(store);

useEffect(() => {
state.schema.introspect();
}, [state.execution.fetcher]);
}, [fetcher]);

Check warning on line 110 in packages/graphiql-react/src/provider.tsx

View workflow job for this annotation

GitHub Actions / ESLint

React Hook useEffect has a missing dependency: 'state.schema'. Either include it or remove the dependency array
return (
<GraphiQLStoreContext.Provider value={store}>
<StorageContextProvider storage={storage}>
Expand Down
34 changes: 29 additions & 5 deletions packages/graphiql-toolkit/src/zustand/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,35 @@ const middlewares = (
return createStore<GraphiQLState>()(
immer(
devtools(
// fn,
persist(fn, {
storage: createJSONStorage(() => storage),
name: 'graphiql',
}),
fn,
// TODO: more issues with persist middleware
// persist(fn, {
// storage: createJSONStorage(() => storage),
// name: 'graphiql',
// onRehydrateStorage: state => {
// return {
// ...state,
// editor: {
// ...state,

// }
// }
// // partialize: state => {
// // const {
// // editor: {
// // queryEditor,
// // variableEditor,
// // headerEditor,
// // responseEditor,
// // ...editorState
// // },
// // } = state;
// // console.log(state);
// // return {
// // editor: editorState,
// // };
// // },
// }),
),
),
);
Expand Down

0 comments on commit b213ceb

Please sign in to comment.