Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/ts resolvers type #5437

Merged
merged 6 commits into from
May 9, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 }}

Copy link
Contributor

Choose a reason for hiding this comment

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

Depending on how thorough you want to be here, you could switch strict to be true in the tsconfig to really ensure things are valid for all consumers

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmmm good point! I don’t think I’ve ever tried it in strict mode 😂

- 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
5 changes: 3 additions & 2 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 @@ -154,8 +155,8 @@ function getPluginConfig() {
omitOperationSuffix: true,

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