Skip to content

Commit

Permalink
implement input validation mapping logic
Browse files Browse the repository at this point in the history
  • Loading branch information
hayes committed Mar 8, 2025
1 parent 5d67217 commit d9efa76
Show file tree
Hide file tree
Showing 7 changed files with 404 additions and 88 deletions.
4 changes: 2 additions & 2 deletions packages/core/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,8 @@ export function unwrapInputListParam<Types extends SchemaTypes>(
*/
export function completeValue<T, R>(
valOrPromise: PromiseLike<T> | T,
onSuccess: (completedVal: T) => R,
onError?: (errVal: unknown) => R,
onSuccess: (completedVal: T) => PromiseLike<R> | R,
onError?: (errVal: unknown) => PromiseLike<R> | R,
): Promise<R> | R {
if (isThenable(valOrPromise)) {
return Promise.resolve(valOrPromise).then(onSuccess, onError);
Expand Down
4 changes: 2 additions & 2 deletions packages/plugin-add-graphql/src/schema-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ proto.addGraphQLObject = function addGraphQLObject<Shape>(
continue;
}

const args: Record<string, ArgumentRef<SchemaTypes>> = {};
const args: Record<string, ArgumentRef<SchemaTypes, unknown>> = {};

for (const { name, ...arg } of field.args) {
const input = resolveInputType(this, arg.type);
Expand Down Expand Up @@ -203,7 +203,7 @@ proto.addGraphQLInterface = function addGraphQLInterface<Shape = unknown>(
continue;
}

const args: Record<string, ArgumentRef<SchemaTypes>> = {};
const args: Record<string, ArgumentRef<SchemaTypes, unknown>> = {};

for (const { name, ...arg } of field.args) {
args[name] = t.arg({
Expand Down
4 changes: 2 additions & 2 deletions packages/plugin-drizzle/src/drizzle-field-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -452,13 +452,13 @@ export class DrizzleObjectFieldBuilder<
>,
]
>
) {
): FieldRef<Types, ShapeFromTypeParam<Types, Type, Nullable>, 'DrizzleObject'> {
const [name, options = {} as never] = args;

const typeConfig = this.builder.configStore.getTypeConfig(this.typename, 'Object');
const usingSelect = !!typeConfig.extensions?.pothosDrizzleSelect;

return this.exposeField(name as never, {
return this.exposeField<Type, Nullable, never>(name as never, {
...options,
extensions: {
...options.extensions,
Expand Down
8 changes: 4 additions & 4 deletions packages/plugin-prisma-utils/src/schema-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -665,8 +665,8 @@ schemaBuilder.prismaUpdateRelation = function prismaUpdateRelation<
data: dataType,
} = fieldOption as {
name?: string;
where: InputFieldRef<SchemaTypes> | InputRef<unknown>;
data: InputFieldRef<SchemaTypes> | InputRef<unknown>;
where: InputFieldRef<SchemaTypes, unknown> | InputRef<unknown>;
data: InputFieldRef<SchemaTypes, unknown> | InputRef<unknown>;
};

const nestedRef = this.inputType(nestedName, {
Expand All @@ -687,8 +687,8 @@ schemaBuilder.prismaUpdateRelation = function prismaUpdateRelation<
skipDuplicates,
} = fieldOption as {
name?: string;
data: InputFieldRef<SchemaTypes> | InputRef<unknown>;
skipDuplicates?: InputFieldRef<SchemaTypes> | InputRef<unknown>;
data: InputFieldRef<SchemaTypes, unknown> | InputRef<unknown>;
skipDuplicates?: InputFieldRef<SchemaTypes, unknown> | InputRef<unknown>;
};

const nestedRef = this.inputType(nestedName, {
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-prisma/src/prisma-field-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,7 @@ export class PrismaObjectFieldBuilder<
},
]
>
) {
): FieldRef<Types, ShapeFromTypeParam<Types, Type, Nullable>, 'PrismaObject'> {
const [options = {} as never] = args;

const typeConfig = this.builder.configStore.getTypeConfig(this.typename);
Expand Down
Loading

0 comments on commit d9efa76

Please sign in to comment.