mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-13 12:55:00 +00:00
feat(server): auth server (#2773)
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
/**
|
||||
* @vitest-environment happy-dom
|
||||
*/
|
||||
import { uploadAvatarMutation } from '@affine/graphql';
|
||||
import { render } from '@testing-library/react';
|
||||
import type { Mock } from 'vitest';
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
@@ -60,11 +61,11 @@ describe('GraphQL wrapper for SWR', () => {
|
||||
const renderer = render(component);
|
||||
const el = await renderer.findByText('number: 1');
|
||||
expect(el).toMatchInlineSnapshot(`
|
||||
<div>
|
||||
number:
|
||||
1
|
||||
</div>
|
||||
`);
|
||||
<div>
|
||||
number:
|
||||
1
|
||||
</div>
|
||||
`);
|
||||
});
|
||||
|
||||
it('should not send request if cache hit', async () => {
|
||||
@@ -135,5 +136,18 @@ describe('GraphQL wrapper for SWR', () => {
|
||||
</DocumentFragment>
|
||||
`);
|
||||
});
|
||||
|
||||
it('should get rid of generated types', async () => {
|
||||
function _NotActuallyRunDefinedForTypeTesting() {
|
||||
const { trigger } = useMutation({
|
||||
mutation: uploadAvatarMutation,
|
||||
});
|
||||
trigger({
|
||||
id: '1',
|
||||
avatar: new File([''], 'avatar.png'),
|
||||
});
|
||||
}
|
||||
expect(_NotActuallyRunDefinedForTypeTesting).toBeTypeOf('function');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -50,7 +50,10 @@ export function useQuery<Query extends GraphQLQuery>(
|
||||
'fetcher'
|
||||
>
|
||||
): SWRResponse<QueryResponse<Query>, GraphQLError | GraphQLError[]>;
|
||||
export function useQuery(options: QueryOptions<GraphQLQuery>, config?: any) {
|
||||
export function useQuery<Query extends GraphQLQuery>(
|
||||
options: QueryOptions<Query>,
|
||||
config?: any
|
||||
) {
|
||||
return useSWR(
|
||||
() => [options.query.id, options.variables],
|
||||
() => fetcher(options),
|
||||
@@ -73,14 +76,14 @@ export function useQuery(options: QueryOptions<GraphQLQuery>, config?: any) {
|
||||
* trigger({ name: 'John Doe' })
|
||||
*/
|
||||
export function useMutation<Mutation extends GraphQLQuery>(
|
||||
options: Omit<MutationOptions<GraphQLQuery>, 'variables'>
|
||||
options: Omit<MutationOptions<Mutation>, 'variables'>
|
||||
): SWRMutationResponse<
|
||||
QueryResponse<Mutation>,
|
||||
GraphQLError | GraphQLError[],
|
||||
QueryVariables<Mutation>
|
||||
>;
|
||||
export function useMutation<Mutation extends GraphQLQuery>(
|
||||
options: Omit<MutationOptions<GraphQLQuery>, 'variables'>,
|
||||
options: Omit<MutationOptions<Mutation>, 'variables'>,
|
||||
config: Omit<
|
||||
SWRMutationConfiguration<
|
||||
QueryResponse<Mutation>,
|
||||
@@ -100,7 +103,7 @@ export function useMutation(
|
||||
) {
|
||||
return useSWRMutation(
|
||||
options.mutation.id,
|
||||
(_: string, { arg }: { arg: QueryVariables<any> }) =>
|
||||
(_: string, { arg }: { arg: any }) =>
|
||||
fetcher({ ...options, query: options.mutation, variables: arg }),
|
||||
config
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user