Skip to content

Commit

Permalink
breaking(types,urql): update @urql/core v6 (#1382)
Browse files Browse the repository at this point in the history
  • Loading branch information
dai-shi authored Aug 30, 2022
1 parent 5d14562 commit 2cfdf0f
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 29 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@
"@types/react-dom": "^18.0.6",
"@typescript-eslint/eslint-plugin": "^5.35.1",
"@typescript-eslint/parser": "^5.35.1",
"@urql/core": "2.6.1",
"@urql/core": "^3.0.2",
"benny": "^3.7.1",
"concurrently": "^7.3.0",
"downlevel-dts": "^0.10.0",
Expand Down
7 changes: 4 additions & 3 deletions src/urql/atomWithMutation.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type {
AnyVariables,
Client,
OperationContext,
OperationResult,
Expand All @@ -8,13 +9,13 @@ import { atom } from 'jotai'
import type { Getter } from 'jotai'
import { clientAtom } from './clientAtom'

type MutationAction<Data, Variables extends object> = {
variables?: Variables
type MutationAction<Data, Variables extends AnyVariables> = {
variables: Variables
context?: Partial<OperationContext>
callback?: (result: OperationResult<Data, Variables>) => void
}

export function atomWithMutation<Data, Variables extends object>(
export function atomWithMutation<Data, Variables extends AnyVariables>(
createQuery: (get: Getter) => TypedDocumentNode<Data, Variables> | string,
getClient: (get: Getter) => Client = (get) => get(clientAtom)
) {
Expand Down
17 changes: 9 additions & 8 deletions src/urql/atomWithQuery.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type {
AnyVariables,
Client,
OperationContext,
OperationResult,
Expand Down Expand Up @@ -28,34 +29,34 @@ const isOperationResultWithData = <Data, Variables>(
): result is OperationResultWithData<Data, Variables> =>
'data' in result && !result.error

type QueryArgs<Data, Variables extends object> = {
type QueryArgs<Data, Variables extends AnyVariables> = {
query: TypedDocumentNode<Data, Variables> | string
variables?: Variables
variables: Variables
requestPolicy?: RequestPolicy
context?: Partial<OperationContext>
}

type QueryArgsWithPause<Data, Variables extends object> = QueryArgs<
type QueryArgsWithPause<Data, Variables extends AnyVariables> = QueryArgs<
Data,
Variables
> & {
pause: boolean
}

export function atomWithQuery<Data, Variables extends object>(
export function atomWithQuery<Data, Variables extends AnyVariables>(
createQueryArgs: (get: Getter) => QueryArgs<Data, Variables>,
getClient?: (get: Getter) => Client
): WritableAtom<OperationResultWithData<Data, Variables>, AtomWithQueryAction>

export function atomWithQuery<Data, Variables extends object>(
export function atomWithQuery<Data, Variables extends AnyVariables>(
createQueryArgs: (get: Getter) => QueryArgsWithPause<Data, Variables>,
getClient?: (get: Getter) => Client
): WritableAtom<
OperationResultWithData<Data, Variables> | null,
AtomWithQueryAction
>

export function atomWithQuery<Data, Variables extends object>(
export function atomWithQuery<Data, Variables extends AnyVariables>(
createQueryArgs: (get: Getter) => QueryArgs<Data, Variables>,
getClient: (get: Getter) => Client = (get) => get(clientAtom)
) {
Expand Down Expand Up @@ -128,7 +129,7 @@ export function atomWithQuery<Data, Variables extends object>(
client.query(args.query, args.variables, {
...(args.requestPolicy && { requestPolicy: args.requestPolicy }),
...args.context,
}) as any, // FIXME can anyone fix typing without any?
}),
subscribe(listener)
)
set(subscriptionAtom, subscription)
Expand Down Expand Up @@ -167,7 +168,7 @@ export function atomWithQuery<Data, Variables extends object>(
...(args.requestPolicy && { requestPolicy: args.requestPolicy }),
...args.context,
...action.opts,
}) as any, // FIXME can anyone fix typing without any?
}),
subscribe(listener)
)
const oldSubscription = get(subscriptionAtom)
Expand Down
13 changes: 7 additions & 6 deletions src/urql/atomWithSubscription.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type {
AnyVariables,
Client,
OperationContext,
OperationResult,
Expand All @@ -21,32 +22,32 @@ const isOperationResultWithData = <Data, Variables>(
result: OperationResult<Data, Variables>
): result is OperationResultWithData<Data, Variables> => 'data' in result

type SubscriptionArgs<Data, Variables extends object> = {
type SubscriptionArgs<Data, Variables extends AnyVariables> = {
query: TypedDocumentNode<Data, Variables> | string
variables?: Variables
variables: Variables
context?: Partial<OperationContext>
}

type SubscriptionArgsWithPause<
Data,
Variables extends object
Variables extends AnyVariables
> = SubscriptionArgs<Data, Variables> & {
pause: boolean
}

export function atomWithSubscription<Data, Variables extends object>(
export function atomWithSubscription<Data, Variables extends AnyVariables>(
createSubscriptionArgs: (get: Getter) => SubscriptionArgs<Data, Variables>,
getClient?: (get: Getter) => Client
): Atom<OperationResultWithData<Data, Variables>>

export function atomWithSubscription<Data, Variables extends object>(
export function atomWithSubscription<Data, Variables extends AnyVariables>(
createSubscriptionArgs: (
get: Getter
) => SubscriptionArgsWithPause<Data, Variables>,
getClient?: (get: Getter) => Client
): Atom<OperationResultWithData<Data, Variables> | null>

export function atomWithSubscription<Data, Variables extends object>(
export function atomWithSubscription<Data, Variables extends AnyVariables>(
createSubscriptionArgs: (get: Getter) => SubscriptionArgs<Data, Variables>,
getClient: (get: Getter) => Client = (get) => get(clientAtom)
) {
Expand Down
2 changes: 1 addition & 1 deletion tests/urql/atomWithMutation.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ it('mutation basic test', async () => {
() => clientMock
)
const mutateAtom = atom(null, (_get, set) => {
set(countAtom, {})
set(countAtom, { variables: {} })
})

const Counter = () => {
Expand Down
5 changes: 5 additions & 0 deletions tests/urql/atomWithQuery.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ it('query basic test', async () => {
const countAtom = atomWithQuery<{ count: number }, Record<string, never>>(
() => ({
query: '{ count }',
variables: {},
}),
() => generateContinuousClient()
)
Expand Down Expand Up @@ -118,6 +119,7 @@ it('query change client at runtime', async () => {
const idAtom = atomWithQuery<{ id: string }, Record<string, never>>(
() => ({
query: '{ id }',
variables: {},
}),
(get) => get(clientAtom)
)
Expand Down Expand Up @@ -169,6 +171,7 @@ it('pause test', async () => {
const countAtom = atomWithQuery<{ count: number }, Record<string, never>>(
(get) => ({
query: '{ count }',
variables: {},
pause: !get(enabledAtom),
}),
() => generateContinuousClient()
Expand Down Expand Up @@ -209,6 +212,7 @@ it('reexecute test', async () => {
const countAtom = atomWithQuery<{ count: number }, Record<string, never>>(
() => ({
query: '{ count }',
variables: {},
}),
() => generateContinuousClient()
)
Expand Down Expand Up @@ -250,6 +254,7 @@ it('query null client suspense', async () => {
const idAtom = atomWithQuery<{ id: string }, Record<string, never>>(
() => ({
query: '{ id }',
variables: {},
}),
(get) => get(clientAtom) as Client
)
Expand Down
4 changes: 4 additions & 0 deletions tests/urql/atomWithSubscription.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ it('subscription basic test', async () => {
query: 'subscription Test { count }' as unknown as TypedDocumentNode<{
count: number
}>,
variables: {},
}),
() => clientMock
)
Expand Down Expand Up @@ -60,6 +61,7 @@ it('subscription change client at runtime', async () => {
id: string
count: number
}>,
variables: {},
}),
(get) => get(clientAtom)
)
Expand Down Expand Up @@ -123,6 +125,7 @@ it('pause test', async () => {
query: 'subscription Test { count }' as unknown as TypedDocumentNode<{
count: number
}>,
variables: {},
pause: !get(enabledAtom),
}),
() => clientMock
Expand Down Expand Up @@ -168,6 +171,7 @@ it('null client suspense', async () => {
id: string
count: number
}>,
variables: {},
}),
(get) => get(clientAtom) as Client
)
Expand Down
15 changes: 5 additions & 10 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1864,13 +1864,13 @@
"@typescript-eslint/types" "5.35.1"
eslint-visitor-keys "^3.3.0"

"@urql/core@2.6.1":
version "2.6.1"
resolved "https://registry.yarnpkg.com/@urql/core/-/core-2.6.1.tgz#c10ee972c5e81df6d7bf1e778ef1b5d30e2906e5"
integrity sha512-gYrEHy3tViJhwIhauK6MIf2Qp09QTsgNHZRd0n71rS+hF6gdwjspf1oKljl4m25+272cJF7fPjBUGmjaiEr7Kg==
"@urql/core@^3.0.2":
version "3.0.2"
resolved "https://registry.yarnpkg.com/@urql/core/-/core-3.0.2.tgz#91008bc112000dd42c5260142e4eed7901def6bd"
integrity sha512-TRpQOdt1Mtpt/EgPlFCx9Aqc3TbHtzH3yj8pJ9yjSUKT4slRyy+ofMQ8yx50oZzZjAOswF02zBRwnxsZANb35A==
dependencies:
"@graphql-typed-document-node/core" "^3.1.1"
wonka "^4.0.14"
wonka "^6.0.0"

abab@^2.0.6:
version "2.0.6"
Expand Down Expand Up @@ -5520,11 +5520,6 @@ which@^2.0.1:
dependencies:
isexe "^2.0.0"

wonka@^4.0.14:
version "4.0.15"
resolved "https://registry.yarnpkg.com/wonka/-/wonka-4.0.15.tgz#9aa42046efa424565ab8f8f451fcca955bf80b89"
integrity sha512-U0IUQHKXXn6PFo9nqsHphVCE5m3IntqZNB9Jjn7EB1lrR7YTDY3YWgFvEvwniTzXSvOH/XMzAZaIfJF/LvHYXg==

wonka@^6.0.0:
version "6.0.0"
resolved "https://registry.yarnpkg.com/wonka/-/wonka-6.0.0.tgz#38cd39a517fc3ff721ea3bf353642b353bf48860"
Expand Down

1 comment on commit 2cfdf0f

@vercel
Copy link

@vercel vercel bot commented on 2cfdf0f Aug 30, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.