Skip to content

Commit a727e1c

Browse files
committed
🎨 Maybe fixed allowed invalid keys
1 parent 65a87c4 commit a727e1c

File tree

12 files changed

+551
-579
lines changed

12 files changed

+551
-579
lines changed

examples/typescript-node-big-schema/src/zeus/apollo.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,31 @@ import { gql, useMutation, useQuery, useLazyQuery, useSubscription } from '@apol
55
import type { MutationHookOptions, QueryHookOptions, LazyQueryHookOptions, SubscriptionHookOptions } from '@apollo/client';
66

77

8-
export function useTypedMutation<Z, O extends "mutation_root">(
8+
export function useTypedMutation<Z extends ValueTypes[O], O extends "mutation_root">(
99
mutation: Z | ValueTypes[O],
1010
options?: MutationHookOptions<InputType<GraphQLTypes[O], Z>>,
11+
operationName?: string,
1112
) {
12-
return useMutation<InputType<GraphQLTypes[O], Z>>(gql(Zeus("mutation",mutation)), options);
13+
return useMutation<InputType<GraphQLTypes[O], Z>>(gql(Zeus("mutation",mutation, operationName)), options);
1314
}
14-
export function useTypedQuery<Z, O extends "query_root">(
15+
export function useTypedQuery<Z extends ValueTypes[O], O extends "query_root">(
1516
query: Z | ValueTypes[O],
1617
options?: QueryHookOptions<InputType<GraphQLTypes[O], Z>>,
18+
operationName?: string,
1719
) {
18-
return useQuery<InputType<GraphQLTypes[O], Z>>(gql(Zeus("query",query)), options);
20+
return useQuery<InputType<GraphQLTypes[O], Z>>(gql(Zeus("query",query, operationName)), options);
1921
}
20-
export function useTypedLazyQuery<Z, O extends "query_root">(
22+
export function useTypedLazyQuery<Z extends ValueTypes[O], O extends "query_root">(
2123
LazyQuery: Z | ValueTypes[O],
2224
options?: LazyQueryHookOptions<InputType<GraphQLTypes[O], Z>>,
25+
operationName?: string,
2326
) {
24-
return useLazyQuery<InputType<GraphQLTypes[O], Z>>(gql(Zeus("query",LazyQuery)), options);
27+
return useLazyQuery<InputType<GraphQLTypes[O], Z>>(gql(Zeus("query",LazyQuery, operationName)), options);
2528
}
26-
export function useTypedSubscription<Z, O extends "subscription_root">(
29+
export function useTypedSubscription<Z extends ValueTypes[O], O extends "subscription_root">(
2730
subscription: Z | ValueTypes[O],
2831
options?: SubscriptionHookOptions<InputType<GraphQLTypes[O], Z>>,
32+
operationName?: string,
2933
) {
30-
return useSubscription<InputType<GraphQLTypes[O], Z>>(gql(Zeus("subscription",subscription)), options);
34+
return useSubscription<InputType<GraphQLTypes[O], Z>>(gql(Zeus("subscription",subscription, operationName)), options);
3135
}

examples/typescript-node-big-schema/src/zeus/reactQuery.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { useMutation, useQuery } from 'react-query';
55
import type { UseMutationOptions, UseQueryOptions } from 'react-query';
66

77

8-
export function useTypedMutation<O extends "mutation_root", TData, TResult = InputType<GraphQLTypes[O], TData>>(
8+
export function useTypedMutation<O extends "mutation_root", TData extends ValueTypes[O], TResult = InputType<GraphQLTypes[O], TData>>(
99
mutationKey: string,
1010
mutation: TData | ValueTypes[O],
1111
options?: Omit<UseMutationOptions<TResult>, 'mutationKey' | 'mutationFn'>,
@@ -14,7 +14,7 @@ export function useTypedMutation<O extends "mutation_root", TData, TResult = Inp
1414
) {
1515
return useMutation<TResult>(mutationKey, () => Chain(host)("mutation")(mutation, zeusOptions) as Promise<TResult>, options);
1616
}
17-
export function useTypedQuery<O extends "query_root", TData, TResult = InputType<GraphQLTypes[O], TData>>(
17+
export function useTypedQuery<O extends "query_root", TData extends ValueTypes[O], TResult = InputType<GraphQLTypes[O], TData>>(
1818
queryKey: string,
1919
query: TData | ValueTypes[O],
2020
options?: Omit<UseQueryOptions<TResult>, 'queryKey' | 'queryFn'>,

examples/typescript-node/src/zeus/apollo.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,31 @@ import { gql, useQuery, useLazyQuery, useSubscription, useMutation } from '@apol
55
import type { QueryHookOptions, LazyQueryHookOptions, SubscriptionHookOptions, MutationHookOptions } from '@apollo/client';
66

77

8-
export function useTypedQuery<Z, O extends "Query">(
8+
export function useTypedQuery<Z extends ValueTypes[O], O extends "Query">(
99
query: Z | ValueTypes[O],
1010
options?: QueryHookOptions<InputType<GraphQLTypes[O], Z>>,
11+
operationName?: string,
1112
) {
12-
return useQuery<InputType<GraphQLTypes[O], Z>>(gql(Zeus("query",query)), options);
13+
return useQuery<InputType<GraphQLTypes[O], Z>>(gql(Zeus("query",query, operationName)), options);
1314
}
14-
export function useTypedLazyQuery<Z, O extends "Query">(
15+
export function useTypedLazyQuery<Z extends ValueTypes[O], O extends "Query">(
1516
LazyQuery: Z | ValueTypes[O],
1617
options?: LazyQueryHookOptions<InputType<GraphQLTypes[O], Z>>,
18+
operationName?: string,
1719
) {
18-
return useLazyQuery<InputType<GraphQLTypes[O], Z>>(gql(Zeus("query",LazyQuery)), options);
20+
return useLazyQuery<InputType<GraphQLTypes[O], Z>>(gql(Zeus("query",LazyQuery, operationName)), options);
1921
}
20-
export function useTypedSubscription<Z, O extends "Subscription">(
22+
export function useTypedSubscription<Z extends ValueTypes[O], O extends "Subscription">(
2123
subscription: Z | ValueTypes[O],
2224
options?: SubscriptionHookOptions<InputType<GraphQLTypes[O], Z>>,
25+
operationName?: string,
2326
) {
24-
return useSubscription<InputType<GraphQLTypes[O], Z>>(gql(Zeus("subscription",subscription)), options);
27+
return useSubscription<InputType<GraphQLTypes[O], Z>>(gql(Zeus("subscription",subscription, operationName)), options);
2528
}
26-
export function useTypedMutation<Z, O extends "Mutation">(
29+
export function useTypedMutation<Z extends ValueTypes[O], O extends "Mutation">(
2730
mutation: Z | ValueTypes[O],
2831
options?: MutationHookOptions<InputType<GraphQLTypes[O], Z>>,
32+
operationName?: string,
2933
) {
30-
return useMutation<InputType<GraphQLTypes[O], Z>>(gql(Zeus("mutation",mutation)), options);
34+
return useMutation<InputType<GraphQLTypes[O], Z>>(gql(Zeus("mutation",mutation, operationName)), options);
3135
}

examples/typescript-node/src/zeus/const.ts

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ export const AllTypesProps: Record<string,any> = {
7373
}
7474

7575
export const ReturnTypes: Record<string,any> = {
76+
ChangeCard:{
77+
"...on SpecialCard":"SpecialCard",
78+
"...on EffectCard":"EffectCard"
79+
},
7680
CardStack:{
7781
cards:"Card",
7882
name:"String"
@@ -85,9 +89,6 @@ export const ReturnTypes: Record<string,any> = {
8589
myStacks:"CardStack",
8690
nameables:"Nameable"
8791
},
88-
Subscription:{
89-
deck:"Card"
90-
},
9192
Card:{
9293
Attack:"Int",
9394
Children:"Int",
@@ -100,12 +101,13 @@ export const ReturnTypes: Record<string,any> = {
100101
name:"String",
101102
skills:"SpecialSkills"
102103
},
103-
Mutation:{
104-
addCard:"Card"
104+
S3Object:{
105+
bucket:"String",
106+
key:"String",
107+
region:"String"
105108
},
106-
SpecialCard:{
107-
effect:"String",
108-
name:"String"
109+
Subscription:{
110+
deck:"Card"
109111
},
110112
Nameable:{
111113
"...on CardStack": "CardStack",
@@ -114,17 +116,15 @@ export const ReturnTypes: Record<string,any> = {
114116
"...on EffectCard": "EffectCard",
115117
name:"String"
116118
},
117-
EffectCard:{
118-
effectSize:"Float",
119+
SpecialCard:{
120+
effect:"String",
119121
name:"String"
120122
},
121-
S3Object:{
122-
bucket:"String",
123-
key:"String",
124-
region:"String"
123+
Mutation:{
124+
addCard:"Card"
125125
},
126-
ChangeCard:{
127-
"...on SpecialCard":"SpecialCard",
128-
"...on EffectCard":"EffectCard"
126+
EffectCard:{
127+
effectSize:"Float",
128+
name:"String"
129129
}
130130
}

0 commit comments

Comments
 (0)