Skip to content

Commit

Permalink
Fix/ts resolvers type (#5437)
Browse files Browse the repository at this point in the history
* Make resolvers callable, args are optional

* Add g sdl to ci, reorder type-check

* Update snapshot

* Make args optional too

* Dont print unused mappers

Co-authored-by: Dominic Saadi <32992335+jtoar@users.noreply.github.com>
  • Loading branch information
dac09 and jtoar committed May 10, 2022
1 parent 808cac6 commit 47bbdd1
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 15 deletions.
15 changes: 10 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -238,11 +238,6 @@ jobs:
yarn rw test web --no-watch
working-directory: ${{ steps.setup_test_project.outputs.test_project_path }}

- name: Run "rw type-check"
run: |
yarn rw type-check
working-directory: ${{ steps.setup_test_project.outputs.test_project_path }}

- name: Run "rw check"
run: |
yarn rw check
Expand Down Expand Up @@ -291,6 +286,16 @@ jobs:
yarn rw g page ciTest
working-directory: ${{ steps.setup_test_project.outputs.test_project_path }}

- name: Run "g sdl"
run: |
yarn rw g sdl userExample
working-directory: ${{ steps.setup_test_project.outputs.test_project_path }}

- name: Run "rw type-check"
run: |
yarn rw type-check
working-directory: ${{ steps.setup_test_project.outputs.test_project_path }}

- name: Throw Error | Run `rw g sdl <model>`
run: |
yarn rw g sdl DoesNotExist
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ export type Exact<T extends { [key: string]: unknown }> = { [K in keyof T]: T[K]
export type MakeOptional<T, K extends keyof T> = Omit<T, K> & { [SubKey in K]?: Maybe<T[SubKey]> };
export type MakeMaybe<T, K extends keyof T> = Omit<T, K> & { [SubKey in K]: Maybe<T[SubKey]> };
export type ResolverFn<TResult, TParent, TContext, TArgs> = (
args: TArgs,
obj: { root: TParent; context: TContext; info: GraphQLResolveInfo }
args?: TArgs,
obj?: { root: TParent; context: TContext; info: GraphQLResolveInfo }
) => Promise<Partial<TResult>> | Partial<TResult>;
export type RequireFields<T, K extends keyof T> = Omit<T, K> & { [P in K]-?: NonNullable<T[P]> };
/** All built-in and custom scalars, mapped to their actual values */
Expand Down Expand Up @@ -78,11 +78,7 @@ export type Todo = {
export type ResolverTypeWrapper<T> = Promise<T> | T;
export type ResolverWithResolve<TResult, TParent, TContext, TArgs> = {
resolve: ResolverFn<TResult, TParent, TContext, TArgs>;
};
export type Resolver<TResult, TParent = {}, TContext = {}, TArgs = {}> = ResolverFn<TResult, TParent, TContext, TArgs> | ResolverWithResolve<TResult, TParent, TContext, TArgs>;
export type Resolver<TResult, TParent = {}, TContext = {}, TArgs = {}> = ResolverFn<TResult, TParent, TContext, TArgs>;
export type SubscriptionSubscribeFn<TResult, TParent, TContext, TArgs> = (
parent: TParent,
Expand Down
7 changes: 4 additions & 3 deletions packages/internal/src/generate/graphqlCodeGen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ function getPluginConfig() {

const pluginConfig: CodegenTypes.PluginConfig &
typescriptResolvers.TypeScriptResolversPluginConfig = {
makeResolverTypeCallable: true,
namingConvention: 'keep', // to allow camelCased query names
scalars: {
// We need these, otherwise these scalars are mapped to any
Expand All @@ -152,10 +153,10 @@ function getPluginConfig() {
// prevent type names being PetQueryQuery, RW generators already append
// Query/Mutation/etc
omitOperationSuffix: true,

showUnusedMappers: false,
customResolverFn: `(
args: TArgs,
obj: { root: TParent; context: TContext; info: GraphQLResolveInfo }
args?: TArgs,
obj?: { root: TParent; context: TContext; info: GraphQLResolveInfo }
) => Promise<Partial<TResult>> | Partial<TResult>;`,
mappers: prismaModels,
contextType: `@redwoodjs/graphql-server/dist/functions/types#RedwoodGraphQLContext`,
Expand Down

0 comments on commit 47bbdd1

Please sign in to comment.