Skip to content
This repository has been archived by the owner on Jan 6, 2025. It is now read-only.

Commit

Permalink
Fix type error
Browse files Browse the repository at this point in the history
  • Loading branch information
iamchanii committed Jul 19, 2024
1 parent 51022de commit dd00bf5
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 22 deletions.
5 changes: 5 additions & 0 deletions .changeset/real-colts-doubt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"pothos-plugin-effect": patch
---

Fix type
4 changes: 2 additions & 2 deletions packages/pothos-plugin-effect/src/global-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ declare global {
Nullable extends FieldNullability<Type>,
Args extends InputFieldMap,
ResolveShape,
ResolveReturnShape extends Effect.Effect<any>,
ResolveReturnShape extends Effect.Effect<unknown, unknown, unknown>,
>(
options: PluginTypes.EffectFieldOptions<
Types,
Expand All @@ -65,7 +65,7 @@ declare global {
Nullable extends FieldNullability<Type>,
Args extends InputFieldMap,
ResolveShape,
ResolveReturnShape extends Effect.Effect<any>,
ResolveReturnShape extends Effect.Effect<unknown, unknown, unknown>,
Fields extends InputFieldMap,
InputName extends string,
ArgRequired extends boolean,
Expand Down
30 changes: 14 additions & 16 deletions packages/pothos-plugin-effect/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,37 +31,35 @@ type Resolver<
Args,
Context,
Type,
Return extends Effect.Effect<any>,
Return extends Effect.Effect<unknown, unknown, unknown>,
> = (
parent: Parent,
args: Args,
context: Context,
info: GraphQLResolveInfo,
) => [Effect.Effect.Success<Return>] extends [Type]
? [Type] extends [readonly (infer Item)[] | null | undefined]
? ListResolveValue<R, Type, Item, Return>
: Effect.Effect<
MaybePromise<MaybeOption<Type>>,
unknown,
InferRequirements<R>
>
: `Error: The resolved Effect is an invalid type.`;
) => [Type] extends [readonly (infer Item)[] | null | undefined]
? ListResolveValue<R, Type, Item, Return>
: Effect.Effect<
MaybePromise<MaybeOption<Type>>,
unknown,
InferRequirements<R>
>;

type ListResolveValue<
R extends Runtime.Runtime<never>,
Type,
Item,
Return extends Effect.Effect<any>,
Return extends Effect.Effect<unknown, unknown, unknown>,
> = [Return] extends [Stream.Stream<unknown>]
? GeneratorResolver<Type, Item> | Return
: null extends Type
? Effect.Effect<
MaybeOption<readonly MaybeOption<Item>[]>,
MaybePromise<MaybeOption<readonly MaybeOption<Item>[]>>,
unknown,
InferRequirements<R>
>
: Effect.Effect<
readonly MaybeOption<Item>[],
MaybePromise<readonly MaybeOption<Item>[]>,
unknown,
InferRequirements<R>
>;
Expand Down Expand Up @@ -90,7 +88,7 @@ interface FieldOptionsByKind<
Nullable extends FieldNullability<Type>,
Args extends InputFieldMap,
ResolveShape,
ResolveReturnShape extends Effect.Effect<any>,
ResolveReturnShape extends Effect.Effect<unknown, unknown, unknown>,
> {
Query: Omit<
PothosSchemaTypes.QueryFieldOptions<
Expand Down Expand Up @@ -213,7 +211,7 @@ export type EffectFieldOptions<
Args extends InputFieldMap,
Kind extends FieldKind,
ResolveShape,
ResolveReturnShape extends Effect.Effect<any>,
ResolveReturnShape extends Effect.Effect<unknown, unknown, unknown>,
> = FieldOptionsByKind<
Types,
ParentShape,
Expand All @@ -232,7 +230,7 @@ export type EffectFieldWithInputOptions<
Args extends InputFieldMap,
Kind extends FieldKind,
ResolveShape,
ResolveReturnShape extends Effect.Effect<any>,
ResolveReturnShape extends Effect.Effect<unknown, unknown, unknown>,
Fields extends InputFieldMap,
InputName extends string,
ArgRequired extends boolean,
Expand Down
3 changes: 2 additions & 1 deletion packages/pothos-plugin-effect/tests/schema/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ builder.queryFields((t) => ({
}),
intList: t.effect({
type: ['Int'],
resolve: () => Effect.succeed([1, 2, 3]),
nullable: false,
resolve: () => Effect.succeed([1, 2, '3']),
}),
string: t.effect({
type: 'String',
Expand Down
4 changes: 2 additions & 2 deletions packages/pothos-plugin-effect/tests/schema/drizzle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ export const PostSchema = builder

builder.queryFields((t) => ({
posts: t.effect({
type: PostSchema,
type: [PostSchema],
nullable: true,
resolve: () =>
Effect.gen(function* () {
const postService = yield* PostService;
return postService.getPost();
return postService.getPosts();
}),
}),
}));
2 changes: 1 addition & 1 deletion packages/pothos-plugin-effect/tests/setupTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const makePostService = Effect.gen(function* () {
const drizzle = yield* Drizzle;

return {
getPost: () => drizzle.query.posts.findFirst(),
getPosts: () => drizzle.query.posts.findMany(),
};
});

Expand Down

0 comments on commit dd00bf5

Please sign in to comment.