Skip to content

Commit

Permalink
upd
Browse files Browse the repository at this point in the history
  • Loading branch information
dimaMachina committed Dec 13, 2024
1 parent 3ecae05 commit 8092f10
Show file tree
Hide file tree
Showing 4 changed files with 126 additions and 126 deletions.
22 changes: 11 additions & 11 deletions packages/graphiql-react/src/editor/context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -324,17 +324,17 @@ export function EditorContextProvider(props: EditorContextProviderProps) {

const setShouldPersistHeaders = // eslint-disable-line react-hooks/exhaustive-deps -- false positive, function is optimized by react-compiler, no need to wrap with useCallback
(persist: boolean) => {
if (persist) {
storage?.set(STORAGE_KEY_HEADERS, headerEditor?.getValue() ?? '');
const serializedTabs = serializeTabState(tabState, true);
storage?.set(STORAGE_KEY_TABS, serializedTabs);
} else {
storage?.set(STORAGE_KEY_HEADERS, '');
clearHeadersFromTabs(storage);
}
setShouldPersistHeadersInternal(persist);
storage?.set(PERSIST_HEADERS_STORAGE_KEY, persist.toString());
};
if (persist) {
storage?.set(STORAGE_KEY_HEADERS, headerEditor?.getValue() ?? '');
const serializedTabs = serializeTabState(tabState, true);
storage?.set(STORAGE_KEY_TABS, serializedTabs);
} else {
storage?.set(STORAGE_KEY_HEADERS, '');
clearHeadersFromTabs(storage);
}
setShouldPersistHeadersInternal(persist);
storage?.set(PERSIST_HEADERS_STORAGE_KEY, persist.toString());
};

const lastShouldPersistHeadersProp = useRef<boolean | undefined>();
useEffect(() => {
Expand Down
26 changes: 13 additions & 13 deletions packages/graphiql-react/src/plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -152,19 +152,19 @@ export function PluginContextProvider(props: PluginContextProviderProps) {
const { onTogglePluginVisibility, children } = props;
const setVisiblePlugin: PluginContextType['setVisiblePlugin'] = // eslint-disable-line react-hooks/exhaustive-deps -- false positive, function is optimized by react-compiler, no need to wrap with useCallback
plugin => {
const newVisiblePlugin = plugin
? plugins.find(
p => (typeof plugin === 'string' ? p.title : p) === plugin,
) || null
: null;
internalSetVisiblePlugin(current => {
if (newVisiblePlugin === current) {
return current;
}
onTogglePluginVisibility?.(newVisiblePlugin);
return newVisiblePlugin;
});
};
const newVisiblePlugin = plugin
? plugins.find(
p => (typeof plugin === 'string' ? p.title : p) === plugin,
) || null
: null;
internalSetVisiblePlugin(current => {
if (newVisiblePlugin === current) {
return current;
}
onTogglePluginVisibility?.(newVisiblePlugin);
return newVisiblePlugin;
});
};

useEffect(() => {
if (props.visiblePlugin) {
Expand Down
194 changes: 97 additions & 97 deletions packages/graphiql-react/src/schema.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -174,125 +174,125 @@ export function SchemaContextProvider({
*/
const introspect = // eslint-disable-line react-hooks/exhaustive-deps -- false positive, function is optimized by react-compiler no need to wrap with useCallback
() => {

Check warning on line 176 in packages/graphiql-react/src/schema.tsx

View check run for this annotation

Codecov / codecov/patch

packages/graphiql-react/src/schema.tsx#L176

Added line #L176 was not covered by tests
/**
* Only introspect if there is no schema provided via props. If the
* prop is passed an introspection result, we do continue but skip the
* introspection request.
*/
if (isSchema(props.schema) || props.schema === null) {
return;
}

const counter = ++counterRef.current;

const maybeIntrospectionData = props.schema;

async function fetchIntrospectionData() {
if (maybeIntrospectionData) {
// No need to introspect if we already have the data
return maybeIntrospectionData;
}

const parsedHeaders = parseHeaderString(headersRef.current);
if (!parsedHeaders.isValidJSON) {
setFetchError('Introspection failed as headers are invalid.');
/**
* Only introspect if there is no schema provided via props. If the
* prop is passed an introspection result, we do continue but skip the
* introspection request.
*/
if (isSchema(props.schema) || props.schema === null) {
return;
}

const fetcherOpts: FetcherOpts = parsedHeaders.headers
? { headers: parsedHeaders.headers }
: {};

const fetch = fetcherReturnToPromise(
fetcher(
{
query: introspectionQuery,
operationName: introspectionQueryName,
},
fetcherOpts,
),
);

if (!isPromise(fetch)) {
setFetchError('Fetcher did not return a Promise for introspection.');
return;
}
const counter = ++counterRef.current;

Check warning on line 186 in packages/graphiql-react/src/schema.tsx

View check run for this annotation

Codecov / codecov/patch

packages/graphiql-react/src/schema.tsx#L186

Added line #L186 was not covered by tests

setIsFetching(true);
setFetchError(null);
const maybeIntrospectionData = props.schema;

Check warning on line 188 in packages/graphiql-react/src/schema.tsx

View check run for this annotation

Codecov / codecov/patch

packages/graphiql-react/src/schema.tsx#L188

Added line #L188 was not covered by tests

let result = await fetch;
async function fetchIntrospectionData() {

Check warning on line 190 in packages/graphiql-react/src/schema.tsx

View check run for this annotation

Codecov / codecov/patch

packages/graphiql-react/src/schema.tsx#L190

Added line #L190 was not covered by tests
if (maybeIntrospectionData) {
// No need to introspect if we already have the data
return maybeIntrospectionData;

Check warning on line 193 in packages/graphiql-react/src/schema.tsx

View check run for this annotation

Codecov / codecov/patch

packages/graphiql-react/src/schema.tsx#L193

Added line #L193 was not covered by tests
}

const parsedHeaders = parseHeaderString(headersRef.current);

Check warning on line 196 in packages/graphiql-react/src/schema.tsx

View check run for this annotation

Codecov / codecov/patch

packages/graphiql-react/src/schema.tsx#L196

Added line #L196 was not covered by tests
if (!parsedHeaders.isValidJSON) {
setFetchError('Introspection failed as headers are invalid.');
return;

Check warning on line 199 in packages/graphiql-react/src/schema.tsx

View check run for this annotation

Codecov / codecov/patch

packages/graphiql-react/src/schema.tsx#L198-L199

Added lines #L198 - L199 were not covered by tests
}

const fetcherOpts: FetcherOpts = parsedHeaders.headers
? { headers: parsedHeaders.headers }
: {};

Check warning on line 204 in packages/graphiql-react/src/schema.tsx

View check run for this annotation

Codecov / codecov/patch

packages/graphiql-react/src/schema.tsx#L203-L204

Added lines #L203 - L204 were not covered by tests

if (
typeof result !== 'object' ||
result === null ||
!('data' in result)
) {
// Try the stock introspection query first, falling back on the
// sans-subscriptions query for services which do not yet support it.
const fetch2 = fetcherReturnToPromise(
const fetch = fetcherReturnToPromise(

Check warning on line 206 in packages/graphiql-react/src/schema.tsx

View check run for this annotation

Codecov / codecov/patch

packages/graphiql-react/src/schema.tsx#L206

Added line #L206 was not covered by tests
fetcher(
{
query: introspectionQuerySansSubscriptions,
query: introspectionQuery,
operationName: introspectionQueryName,
},
fetcherOpts,
),
);
if (!isPromise(fetch2)) {
throw new Error(
'Fetcher did not return a Promise for introspection.',

if (!isPromise(fetch)) {
setFetchError('Fetcher did not return a Promise for introspection.');
return;

Check warning on line 218 in packages/graphiql-react/src/schema.tsx

View check run for this annotation

Codecov / codecov/patch

packages/graphiql-react/src/schema.tsx#L217-L218

Added lines #L217 - L218 were not covered by tests
}

setIsFetching(true);
setFetchError(null);

Check warning on line 222 in packages/graphiql-react/src/schema.tsx

View check run for this annotation

Codecov / codecov/patch

packages/graphiql-react/src/schema.tsx#L221-L222

Added lines #L221 - L222 were not covered by tests

let result = await fetch;

Check warning on line 224 in packages/graphiql-react/src/schema.tsx

View check run for this annotation

Codecov / codecov/patch

packages/graphiql-react/src/schema.tsx#L224

Added line #L224 was not covered by tests

if (
typeof result !== 'object' ||
result === null ||
!('data' in result)

Check warning on line 229 in packages/graphiql-react/src/schema.tsx

View check run for this annotation

Codecov / codecov/patch

packages/graphiql-react/src/schema.tsx#L228-L229

Added lines #L228 - L229 were not covered by tests
) {
// Try the stock introspection query first, falling back on the
// sans-subscriptions query for services which do not yet support it.
const fetch2 = fetcherReturnToPromise(

Check warning on line 233 in packages/graphiql-react/src/schema.tsx

View check run for this annotation

Codecov / codecov/patch

packages/graphiql-react/src/schema.tsx#L233

Added line #L233 was not covered by tests
fetcher(
{
query: introspectionQuerySansSubscriptions,
operationName: introspectionQueryName,
},
fetcherOpts,
),
);
if (!isPromise(fetch2)) {
throw new Error(

Check warning on line 243 in packages/graphiql-react/src/schema.tsx

View check run for this annotation

Codecov / codecov/patch

packages/graphiql-react/src/schema.tsx#L243

Added line #L243 was not covered by tests
'Fetcher did not return a Promise for introspection.',
);
}
result = await fetch2;

Check warning on line 247 in packages/graphiql-react/src/schema.tsx

View check run for this annotation

Codecov / codecov/patch

packages/graphiql-react/src/schema.tsx#L247

Added line #L247 was not covered by tests
}
result = await fetch2;
}

setIsFetching(false);
setIsFetching(false);

Check warning on line 250 in packages/graphiql-react/src/schema.tsx

View check run for this annotation

Codecov / codecov/patch

packages/graphiql-react/src/schema.tsx#L250

Added line #L250 was not covered by tests

if (result?.data && '__schema' in result.data) {
return result.data as IntrospectionQuery;
}
if (result?.data && '__schema' in result.data) {
return result.data as IntrospectionQuery;

Check warning on line 253 in packages/graphiql-react/src/schema.tsx

View check run for this annotation

Codecov / codecov/patch

packages/graphiql-react/src/schema.tsx#L253

Added line #L253 was not covered by tests
}

// handle as if it were an error if the fetcher response is not a string or response.data is not present
const responseString =
typeof result === 'string' ? result : formatResult(result);
setFetchError(responseString);
}
// handle as if it were an error if the fetcher response is not a string or response.data is not present
const responseString =
typeof result === 'string' ? result : formatResult(result);
setFetchError(responseString);

Check warning on line 259 in packages/graphiql-react/src/schema.tsx

View check run for this annotation

Codecov / codecov/patch

packages/graphiql-react/src/schema.tsx#L259

Added line #L259 was not covered by tests
}

fetchIntrospectionData()
.then(introspectionData => {
/**
* Don't continue if another introspection request has been started in
* the meantime or if there is no introspection data.
*/
if (counter !== counterRef.current || !introspectionData) {
return;
}
fetchIntrospectionData()
.then(introspectionData => {

Check warning on line 263 in packages/graphiql-react/src/schema.tsx

View check run for this annotation

Codecov / codecov/patch

packages/graphiql-react/src/schema.tsx#L262-L263

Added lines #L262 - L263 were not covered by tests
/**
* Don't continue if another introspection request has been started in
* the meantime or if there is no introspection data.
*/
if (counter !== counterRef.current || !introspectionData) {
return;

Check warning on line 269 in packages/graphiql-react/src/schema.tsx

View check run for this annotation

Codecov / codecov/patch

packages/graphiql-react/src/schema.tsx#L269

Added line #L269 was not covered by tests
}

try {
const newSchema = buildClientSchema(introspectionData);
setSchema(newSchema);
// Optional chaining inside try-catch isn't supported yet by react-compiler
if (onSchemaChange) {
onSchemaChange(newSchema);
try {
const newSchema = buildClientSchema(introspectionData);
setSchema(newSchema);

Check warning on line 274 in packages/graphiql-react/src/schema.tsx

View check run for this annotation

Codecov / codecov/patch

packages/graphiql-react/src/schema.tsx#L272-L274

Added lines #L272 - L274 were not covered by tests
// Optional chaining inside try-catch isn't supported yet by react-compiler
if (onSchemaChange) {
onSchemaChange(newSchema);

Check warning on line 277 in packages/graphiql-react/src/schema.tsx

View check run for this annotation

Codecov / codecov/patch

packages/graphiql-react/src/schema.tsx#L277

Added line #L277 was not covered by tests
}
} catch (error) {
setFetchError(formatError(error));

Check warning on line 280 in packages/graphiql-react/src/schema.tsx

View check run for this annotation

Codecov / codecov/patch

packages/graphiql-react/src/schema.tsx#L280

Added line #L280 was not covered by tests
}
})
.catch(error => {

Check warning on line 283 in packages/graphiql-react/src/schema.tsx

View check run for this annotation

Codecov / codecov/patch

packages/graphiql-react/src/schema.tsx#L283

Added line #L283 was not covered by tests
/**
* Don't continue if another introspection request has been started in
* the meantime.
*/
if (counter !== counterRef.current) {
return;

Check warning on line 289 in packages/graphiql-react/src/schema.tsx

View check run for this annotation

Codecov / codecov/patch

packages/graphiql-react/src/schema.tsx#L289

Added line #L289 was not covered by tests
}
} catch (error) {
setFetchError(formatError(error));
}
})
.catch(error => {
/**
* Don't continue if another introspection request has been started in
* the meantime.
*/
if (counter !== counterRef.current) {
return;
}

setFetchError(formatError(error));
setIsFetching(false);
});
};
setFetchError(formatError(error));
setIsFetching(false);

Check warning on line 293 in packages/graphiql-react/src/schema.tsx

View check run for this annotation

Codecov / codecov/patch

packages/graphiql-react/src/schema.tsx#L293

Added line #L293 was not covered by tests
});
};

/**
* Trigger introspection automatically
Expand Down
10 changes: 5 additions & 5 deletions packages/graphiql-react/src/utility/resize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,11 @@ export function useDragResize({

const setHiddenElementWithCallback = // eslint-disable-line react-hooks/exhaustive-deps -- false positive, function is optimized by react-compiler, no need to wrap with useCallback
(element: ResizableElement | null) => {
if (element !== hiddenElement) {
setHiddenElement(element);
onHiddenElementChange?.(element);
}
};
if (element !== hiddenElement) {
setHiddenElement(element);
onHiddenElementChange?.(element);
}
};

const firstRef = useRef<HTMLDivElement>(null);
const dragBarRef = useRef<HTMLDivElement>(null);
Expand Down

0 comments on commit 8092f10

Please sign in to comment.