Skip to content

Commit eb18ba4

Browse files
committed
Fix resolve return types
1 parent 054b723 commit eb18ba4

File tree

3 files changed

+24
-14
lines changed

3 files changed

+24
-14
lines changed

packages/plugin-edgedb/src/global-types.ts

+13-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,19 @@ declare global {
102102
Type extends TypeParam extends [unknown]
103103
? [ObjectRef<Model['Shape']>]
104104
: ObjectRef<Model['Shape']>,
105-
Model extends EdgeDBModelTypes = EdgeDBModelTypes &
105+
Model extends EdgeDBModelTypes = EdgeDBModelShape<
106+
Types,
107+
// @ts-expect-error -> string | number | symbol not assignable to ..
108+
TypeParam extends [keyof Types['EdgeDBTypes']['default']]
109+
? keyof Types['EdgeDBTypes']['default'][TypeParam[0]]
110+
: TypeParam extends [EdgeDBObjectRef<EdgeDBModelTypes>]
111+
? TypeParam[0][typeof edgeDBModelKey]
112+
: TypeParam extends EdgeDBObjectRef<EdgeDBModelTypes>
113+
? TypeParam[typeof edgeDBModelKey]
114+
: TypeParam extends keyof Types['EdgeDBTypes']['default']
115+
? TypeParam
116+
: never
117+
> &
106118
(TypeParam extends [keyof Types['EdgeDBTypes']['default']]
107119
? Types['EdgeDBTypes']['default'][TypeParam[0]]
108120
: TypeParam extends [EdgeDBObjectRef<EdgeDBModelTypes>]

packages/plugin-edgedb/src/types.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export type EdgeDBDefaultExportKeyTypes<DefaultExports> = {
4242
: never;
4343
}[keyof DefaultExports];
4444

45-
type EdgeDBDefaultExportKey<
45+
type EdgeDBModelKeyAsString<
4646
DefaultExports,
4747
KeyType extends string | number | symbol = EdgeDBDefaultExportKeyTypes<DefaultExports>,
4848
> = Extract<keyof DefaultExports, KeyType>;
@@ -394,17 +394,17 @@ export type EdgeDBFieldResolver<
394394
info: GraphQLResolveInfo,
395395
) => ShapeFromTypeParam<Types, Param, Nullable> extends infer Shape
396396
? [Shape] extends [[readonly (infer Item)[] | null | undefined]]
397-
? ListResolveValue<Shape, Item, ResolveReturnShape>
398-
: MaybePromise<Shape>
397+
? ListResolveValue<Partial<Shape>, Item, ResolveReturnShape>
398+
: MaybePromise<Partial<Shape>>
399399
: never;
400400

401401
export type EdgeDBFieldOptions<
402402
Types extends SchemaTypes,
403403
ParentShape,
404404
Type extends
405405
| EdgeDBObjectRef<EdgeDBModelTypes>
406-
| keyof Types['EdgeDBTypes']
407-
| [keyof Types['EdgeDBTypes']]
406+
| keyof Types['EdgeDBTypes']['default']
407+
| [keyof Types['EdgeDBTypes']['default']]
408408
| [EdgeDBObjectRef<EdgeDBModelTypes>],
409409
Model extends EdgeDBModelTypes,
410410
Param extends TypeParam<Types>,

packages/plugin-edgedb/tests/example/schema/index.ts

+6-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import e, { Post, User } from '../../client';
22
import { db } from '../db';
33
import builder from '../builder';
4-
import { getNamedType } from 'graphql';
54

65
const PostPreview = builder.objectRef<Post>('PostPreview');
76
PostPreview.implement({
@@ -51,9 +50,6 @@ builder.queryType({
5150
// Temporarily since `User` doesnt have the links defined yet.
5251
// @ts-ignore
5352
resolve: async (root, args, ctx, info) => {
54-
console.log(info.returnType);
55-
console.log(getNamedType(info.returnType));
56-
5753
const user = await e
5854
.select(e.User, (user) => ({
5955
id: true,
@@ -67,13 +63,15 @@ builder.queryType({
6763
},
6864
}),
6965
users: t.edgeDBField({
70-
type: ['User'],
66+
type: 'User',
7167
nullable: true,
72-
resolve: async (_query, _, __, ctx) => {
68+
resolve: async (_query, _parent, _args, ctx) => {
7369
const user = await e
74-
.select(e.User, () => ({
70+
.select(e.User, (user) => ({
71+
id: true,
7572
email: true,
76-
title: true,
73+
name: true,
74+
filter: e.op(user.id, '=', e.uuid(ctx.user.id)),
7775
}))
7876
.run(db);
7977

0 commit comments

Comments
 (0)