Skip to content

Commit

Permalink
✨ ResolverInputTypes generation
Browse files Browse the repository at this point in the history
  • Loading branch information
aexol committed Jul 1, 2022
1 parent 1ce87e8 commit b6066c9
Show file tree
Hide file tree
Showing 12 changed files with 568 additions and 251 deletions.
28 changes: 14 additions & 14 deletions examples/typescript-node/src/zeus/apollo.ts
Original file line number Diff line number Diff line change
@@ -1,45 +1,45 @@
/* eslint-disable */

import { Zeus, GraphQLTypes, InputType, ValueTypes, OperationOptions, ScalarDefinition } from './index';
import { gql, useQuery, useLazyQuery, useMutation, useSubscription } from '@apollo/client';
import type { QueryHookOptions, LazyQueryHookOptions, MutationHookOptions, SubscriptionHookOptions } from '@apollo/client';
import { gql, useMutation, useQuery, useLazyQuery, useSubscription } from '@apollo/client';
import type { MutationHookOptions, QueryHookOptions, LazyQueryHookOptions, SubscriptionHookOptions } from '@apollo/client';


export function useTypedQuery<Z extends ValueTypes[O], O extends "Query", SCLR extends ScalarDefinition>(
query: Z | ValueTypes[O],
export function useTypedMutation<Z extends ValueTypes[O], O extends "Mutation", SCLR extends ScalarDefinition>(
mutation: Z | ValueTypes[O],
options?:{
apolloOptions?: QueryHookOptions<InputType<GraphQLTypes[O], Z, SCLR>>,
apolloOptions?: MutationHookOptions<InputType<GraphQLTypes[O], Z, SCLR>>,
operationOptions?: OperationOptions,
scalars?: SCLR
}
) {
return useQuery<InputType<GraphQLTypes[O], Z, SCLR>>(gql(Zeus("query",query, {
return useMutation<InputType<GraphQLTypes[O], Z, SCLR>>(gql(Zeus("mutation",mutation, {
operationOptions: options?.operationOptions,
scalars: options?.scalars
})), options?.apolloOptions);
}
export function useTypedLazyQuery<Z extends ValueTypes[O], O extends "Query", SCLR extends ScalarDefinition>(
LazyQuery: Z | ValueTypes[O],
export function useTypedQuery<Z extends ValueTypes[O], O extends "Query", SCLR extends ScalarDefinition>(
query: Z | ValueTypes[O],
options?:{
apolloOptions?: LazyQueryHookOptions<InputType<GraphQLTypes[O], Z, SCLR>>,
apolloOptions?: QueryHookOptions<InputType<GraphQLTypes[O], Z, SCLR>>,
operationOptions?: OperationOptions,
scalars?: SCLR
}
) {
return useLazyQuery<InputType<GraphQLTypes[O], Z, SCLR>>(gql(Zeus("query",LazyQuery, {
return useQuery<InputType<GraphQLTypes[O], Z, SCLR>>(gql(Zeus("query",query, {
operationOptions: options?.operationOptions,
scalars: options?.scalars
})), options?.apolloOptions);
}
export function useTypedMutation<Z extends ValueTypes[O], O extends "Mutation", SCLR extends ScalarDefinition>(
mutation: Z | ValueTypes[O],
export function useTypedLazyQuery<Z extends ValueTypes[O], O extends "Query", SCLR extends ScalarDefinition>(
LazyQuery: Z | ValueTypes[O],
options?:{
apolloOptions?: MutationHookOptions<InputType<GraphQLTypes[O], Z, SCLR>>,
apolloOptions?: LazyQueryHookOptions<InputType<GraphQLTypes[O], Z, SCLR>>,
operationOptions?: OperationOptions,
scalars?: SCLR
}
) {
return useMutation<InputType<GraphQLTypes[O], Z, SCLR>>(gql(Zeus("mutation",mutation, {
return useLazyQuery<InputType<GraphQLTypes[O], Z, SCLR>>(gql(Zeus("query",LazyQuery, {
operationOptions: options?.operationOptions,
scalars: options?.scalars
})), options?.apolloOptions);
Expand Down
68 changes: 34 additions & 34 deletions examples/typescript-node/src/zeus/const.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
/* eslint-disable */

export const AllTypesProps: Record<string,any> = {
Query:{
cardById:{

}
},
JSON: `scalar.JSON` as const,
Mutation:{
addCard:{
card:"createCard"
Expand All @@ -15,15 +9,38 @@ export const AllTypesProps: Record<string,any> = {
createCard:{
skills:"SpecialSkills"
},
JSON: `scalar.JSON` as const,
Query:{
cardById:{

}
},
SpecialSkills: "enum" as const,
Card:{
attack:{

}
},
SpecialSkills: "enum" as const
}
}

export const ReturnTypes: Record<string,any> = {
CardStack:{
cards:"Card",
name:"String"
},
Mutation:{
addCard:"Card"
},
S3Object:{
bucket:"String",
key:"String",
region:"String"
},
JSON: `scalar.JSON` as const,
EffectCard:{
effectSize:"Float",
name:"String"
},
Query:{
cardById:"Card",
drawCard:"Card",
Expand All @@ -32,33 +49,15 @@ export const ReturnTypes: Record<string,any> = {
myStacks:"CardStack",
nameables:"Nameable"
},
JSON: `scalar.JSON` as const,
Nameable:{
"...on EffectCard": "EffectCard",
"...on CardStack": "CardStack",
"...on EffectCard": "EffectCard",
"...on Card": "Card",
"...on SpecialCard": "SpecialCard",
name:"String"
},
S3Object:{
bucket:"String",
key:"String",
region:"String"
},
ChangeCard:{
"...on SpecialCard":"SpecialCard",
"...on EffectCard":"EffectCard"
},
EffectCard:{
effectSize:"Float",
name:"String"
},
Mutation:{
addCard:"Card"
},
CardStack:{
cards:"Card",
name:"String"
Subscription:{
deck:"Card"
},
Card:{
Attack:"Int",
Expand All @@ -73,17 +72,18 @@ export const ReturnTypes: Record<string,any> = {
name:"String",
skills:"SpecialSkills"
},
ChangeCard:{
"...on SpecialCard":"SpecialCard",
"...on EffectCard":"EffectCard"
},
SpecialCard:{
effect:"String",
name:"String"
},
Subscription:{
deck:"Card"
}
}

export const Ops = {
query: "Query" as const,
mutation: "Mutation" as const,
mutation: "Mutation" as const,
query: "Query" as const,
subscription: "Subscription" as const
}
Loading

0 comments on commit b6066c9

Please sign in to comment.