Skip to content

Commit

Permalink
use the createRequest export instead of keyDocument
Browse files Browse the repository at this point in the history
  • Loading branch information
JoviDeCroock committed Apr 24, 2024
1 parent ea665f3 commit 85d7ed6
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions packages/react-urql/src/hooks/useFragment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import type {
FragmentDefinitionNode,
InlineFragmentNode,
SelectionSetNode,
DocumentNode,
} from '@0no-co/graphql.web';
import { Kind } from '@0no-co/graphql.web';

Expand All @@ -16,13 +15,13 @@ import type {
OperationContext,
GraphQLRequest,
} from '@urql/core';
import { createRequest } from '@urql/core';

import { useClient } from '../context';
import { useRequest } from './useRequest';
import { getFragmentCacheForClient } from './cache';

import { hasDepsChanged } from './state';
import { keyDocument } from '@urql/core/utils';

/** Input arguments for the {@link useFragment} hook. */
export type UseFragmentArgs<Data = any> = {
Expand Down Expand Up @@ -125,14 +124,9 @@ export function useFragment<Data>(
const cache = getFragmentCacheForClient(client);
const suspense = isSuspense(client, args.context);
const fragment = React.useMemo(() => {
let document: DocumentNode;
if (typeof args.query === 'string') {
document = keyDocument(args.query);
} else {
document = args.query;
}
const request = createRequest(args.query, {});

return document.definitions.find(
return request.query.definitions.find(
x =>
x.kind === Kind.FRAGMENT_DEFINITION &&
((args.name && x.name.value === args.name) || !args.name)
Expand Down

0 comments on commit 85d7ed6

Please sign in to comment.