New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@pothos/plugin-with-input

Package Overview
Dependencies
Maintainers
1
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@pothos/plugin-with-input - npm Package Compare versions

Comparing version 3.9.7 to 3.10.0

29

CHANGELOG.md
# @pothos/plugin-with-input
## 3.10.0
### Minor Changes
- 3776481e: Add `name` option to `typeOptions` of`@pothos/plugin-with-input` to customize the
default naming of input fields.
An example usage of this:
```ts
import WithInputPlugin from '@pothos/plugin-with-input';
const builder = new SchemaBuilder({
plugins: [WithInputPlugin],
withInput: {
typeOptions: {
name: ({ parentTypeName, fieldName }) => {
const capitalizedFieldName = `${fieldName[0].toUpperCase()}${fieldName.slice(1)}`;
// This will remove the default Query/Mutation prefix from the input type name
if (parentTypeName === 'Query' || parentTypeName === 'Mutation') {
return `${capitalizedFieldName}Input`;
}
return `${parentTypeName}${capitalizedFieldName}Input`;
},
},
},
});
```
## 3.9.7

@@ -4,0 +33,0 @@

15

dts/types.d.ts

@@ -6,5 +6,10 @@ import { FieldKind, FieldNullability, FieldOptionsFromKind, InputFieldMap, InputFieldRef, InputRef, InputShapeFromFields, SchemaTypes, TypeParam } from '@pothos/core';

};
typeOptions?: Omit<PothosSchemaTypes.InputObjectTypeOptions<Types, {}>, 'fields'>;
typeOptions?: Omit<PothosSchemaTypes.InputObjectTypeOptions<Types, {}>, 'fields'> & {
name?: (options: {
parentTypeName: string;
fieldName: string;
}) => string;
};
}
export declare type WithInputInputOptions<Types extends SchemaTypes, Fields extends InputFieldMap, InputName extends string> = Omit<PothosSchemaTypes.InputObjectTypeOptions<Types, Fields>, 'fields'> & {
export type WithInputInputOptions<Types extends SchemaTypes, Fields extends InputFieldMap, InputName extends string> = Omit<PothosSchemaTypes.InputObjectTypeOptions<Types, Fields>, 'fields'> & {
name?: string;

@@ -14,9 +19,9 @@ argName?: InputName;

};
export declare type WithInputTypeOptions<Types extends SchemaTypes, Fields extends InputFieldMap> = Omit<PothosSchemaTypes.InputObjectTypeOptions<Types, Fields>, 'fields'> & {
export type WithInputTypeOptions<Types extends SchemaTypes, Fields extends InputFieldMap> = Omit<PothosSchemaTypes.InputObjectTypeOptions<Types, Fields>, 'fields'> & {
name?: string;
};
export declare type WithInputArgOptions<Types extends SchemaTypes, Fields extends InputFieldMap, InputName, ArgRequired extends boolean> = Omit<PothosSchemaTypes.ArgFieldOptions<Types, InputRef<InputShapeFromFields<Fields>>, ArgRequired>, 'type'> & {
export type WithInputArgOptions<Types extends SchemaTypes, Fields extends InputFieldMap, InputName, ArgRequired extends boolean> = Omit<PothosSchemaTypes.ArgFieldOptions<Types, InputRef<InputShapeFromFields<Fields>>, ArgRequired>, 'type'> & {
name?: InputName;
};
export declare type FieldWithInputOptions<Types extends SchemaTypes, ParentShape, Kind extends FieldKind, Args extends Record<string, InputFieldRef<unknown, 'Arg'>>, Fields extends Record<string, InputFieldRef<unknown, 'InputObject'>>, Type extends TypeParam<Types>, Nullable extends FieldNullability<Type>, InputName extends string, ResolveShape, ResolveReturnShape, ArgRequired extends boolean> = Omit<FieldOptionsFromKind<Types, ParentShape, Type, Nullable, {
export type FieldWithInputOptions<Types extends SchemaTypes, ParentShape, Kind extends FieldKind, Args extends Record<string, InputFieldRef<unknown, 'Arg'>>, Fields extends Record<string, InputFieldRef<unknown, 'InputObject'>>, Type extends TypeParam<Types>, Nullable extends FieldNullability<Type>, InputName extends string, ResolveShape, ResolveReturnShape, ArgRequired extends boolean> = Omit<FieldOptionsFromKind<Types, ParentShape, Type, Nullable, {
[K in InputName]: InputFieldRef<InputShapeFromFields<Fields> | (true extends ArgRequired ? never : null | undefined)>;

@@ -23,0 +28,0 @@ } & Args, Kind, ResolveShape, ResolveReturnShape>, 'args'> & {

@@ -6,5 +6,10 @@ import { InputFieldBuilder, RootFieldBuilder } from '@pothos/core';

}
function defaultGetName({ parentTypeName, fieldName }) {
return `${parentTypeName}${capitalize(fieldName)}Input`;
}
rootBuilderProto.fieldWithInput = function fieldWithInput({ typeOptions: { name: typeName, ...typeOptions } = {}, argOptions: { name: argName = "input", ...argOptions } = {}, args, input, ...fieldOptions }) {
var ref;
var _this_builder_options_withInput, _this_builder_options_withInput1;
const inputRef = this.builder.inputRef(typeName !== null && typeName !== void 0 ? typeName : `UnnamedWithInputOn${this.typename}`);
var _this_builder_options_withInput_typeOptions;
const { name: getTypeName = defaultGetName, ...defaultTypeOptions } = (_this_builder_options_withInput_typeOptions = (_this_builder_options_withInput = this.builder.options.withInput) === null || _this_builder_options_withInput === void 0 ? void 0 : _this_builder_options_withInput.typeOptions) !== null && _this_builder_options_withInput_typeOptions !== void 0 ? _this_builder_options_withInput_typeOptions : {};
const fieldRef = this.field({

@@ -15,3 +20,3 @@ args: {

required: true,
...(ref = this.builder.options.withInput) === null || ref === void 0 ? void 0 : ref.argOptions,
...(_this_builder_options_withInput1 = this.builder.options.withInput) === null || _this_builder_options_withInput1 === void 0 ? void 0 : _this_builder_options_withInput1.argOptions,
...argOptions,

@@ -24,7 +29,9 @@ type: inputRef

this.builder.configStore.onFieldUse(fieldRef, (config) => {
var ref;
const name = typeName !== null && typeName !== void 0 ? typeName : `${this.typename}${capitalize(config.name)}Input`;
const name = typeName !== null && typeName !== void 0 ? typeName : getTypeName({
parentTypeName: this.typename,
fieldName: config.name
});
this.builder.inputType(name, {
fields: () => input,
...(ref = this.builder.options.withInput) === null || ref === void 0 ? void 0 : ref.typeOptions,
...defaultTypeOptions,
...typeOptions

@@ -31,0 +38,0 @@ });

@@ -6,5 +6,10 @@ import { FieldKind, FieldNullability, FieldOptionsFromKind, InputFieldMap, InputFieldRef, InputRef, InputShapeFromFields, SchemaTypes, TypeParam } from '@pothos/core';

};
typeOptions?: Omit<PothosSchemaTypes.InputObjectTypeOptions<Types, {}>, "fields">;
typeOptions?: Omit<PothosSchemaTypes.InputObjectTypeOptions<Types, {}>, "fields"> & {
name?: (options: {
parentTypeName: string;
fieldName: string;
}) => string;
};
}
export declare type WithInputInputOptions<Types extends SchemaTypes, Fields extends InputFieldMap, InputName extends string> = Omit<PothosSchemaTypes.InputObjectTypeOptions<Types, Fields>, "fields"> & {
export type WithInputInputOptions<Types extends SchemaTypes, Fields extends InputFieldMap, InputName extends string> = Omit<PothosSchemaTypes.InputObjectTypeOptions<Types, Fields>, "fields"> & {
name?: string;

@@ -14,9 +19,9 @@ argName?: InputName;

};
export declare type WithInputTypeOptions<Types extends SchemaTypes, Fields extends InputFieldMap> = Omit<PothosSchemaTypes.InputObjectTypeOptions<Types, Fields>, "fields"> & {
export type WithInputTypeOptions<Types extends SchemaTypes, Fields extends InputFieldMap> = Omit<PothosSchemaTypes.InputObjectTypeOptions<Types, Fields>, "fields"> & {
name?: string;
};
export declare type WithInputArgOptions<Types extends SchemaTypes, Fields extends InputFieldMap, InputName, ArgRequired extends boolean> = Omit<PothosSchemaTypes.ArgFieldOptions<Types, InputRef<InputShapeFromFields<Fields>>, ArgRequired>, "type"> & {
export type WithInputArgOptions<Types extends SchemaTypes, Fields extends InputFieldMap, InputName, ArgRequired extends boolean> = Omit<PothosSchemaTypes.ArgFieldOptions<Types, InputRef<InputShapeFromFields<Fields>>, ArgRequired>, "type"> & {
name?: InputName;
};
export declare type FieldWithInputOptions<Types extends SchemaTypes, ParentShape, Kind extends FieldKind, Args extends Record<string, InputFieldRef<unknown, "Arg">>, Fields extends Record<string, InputFieldRef<unknown, "InputObject">>, Type extends TypeParam<Types>, Nullable extends FieldNullability<Type>, InputName extends string, ResolveShape, ResolveReturnShape, ArgRequired extends boolean> = Omit<FieldOptionsFromKind<Types, ParentShape, Type, Nullable, {
export type FieldWithInputOptions<Types extends SchemaTypes, ParentShape, Kind extends FieldKind, Args extends Record<string, InputFieldRef<unknown, "Arg">>, Fields extends Record<string, InputFieldRef<unknown, "InputObject">>, Type extends TypeParam<Types>, Nullable extends FieldNullability<Type>, InputName extends string, ResolveShape, ResolveReturnShape, ArgRequired extends boolean> = Omit<FieldOptionsFromKind<Types, ParentShape, Type, Nullable, {
[K in InputName]: InputFieldRef<InputShapeFromFields<Fields> | (true extends ArgRequired ? never : null | undefined)>;

@@ -23,0 +28,0 @@ } & Args, Kind, ResolveShape, ResolveReturnShape>, "args"> & {

@@ -10,5 +10,10 @@ "use strict";

}
function defaultGetName({ parentTypeName , fieldName }) {
return `${parentTypeName}${capitalize(fieldName)}Input`;
}
rootBuilderProto.fieldWithInput = function fieldWithInput({ typeOptions: { name: typeName , ...typeOptions } = {} , argOptions: { name: argName = 'input' , ...argOptions } = {} , args , input , ...fieldOptions }) {
var ref;
var _this_builder_options_withInput, _this_builder_options_withInput1;
const inputRef = this.builder.inputRef(typeName !== null && typeName !== void 0 ? typeName : `UnnamedWithInputOn${this.typename}`);
var _this_builder_options_withInput_typeOptions;
const { name: getTypeName = defaultGetName , ...defaultTypeOptions } = (_this_builder_options_withInput_typeOptions = (_this_builder_options_withInput = this.builder.options.withInput) === null || _this_builder_options_withInput === void 0 ? void 0 : _this_builder_options_withInput.typeOptions) !== null && _this_builder_options_withInput_typeOptions !== void 0 ? _this_builder_options_withInput_typeOptions : {};
const fieldRef = this.field({

@@ -19,3 +24,3 @@ args: {

required: true,
...(ref = this.builder.options.withInput) === null || ref === void 0 ? void 0 : ref.argOptions,
...(_this_builder_options_withInput1 = this.builder.options.withInput) === null || _this_builder_options_withInput1 === void 0 ? void 0 : _this_builder_options_withInput1.argOptions,
...argOptions,

@@ -28,7 +33,9 @@ type: inputRef

this.builder.configStore.onFieldUse(fieldRef, (config)=>{
var ref;
const name = typeName !== null && typeName !== void 0 ? typeName : `${this.typename}${capitalize(config.name)}Input`;
const name = typeName !== null && typeName !== void 0 ? typeName : getTypeName({
parentTypeName: this.typename,
fieldName: config.name
});
this.builder.inputType(name, {
fields: ()=>input,
...(ref = this.builder.options.withInput) === null || ref === void 0 ? void 0 : ref.typeOptions,
...defaultTypeOptions,
...typeOptions

@@ -35,0 +42,0 @@ });

{
"name": "@pothos/plugin-with-input",
"version": "3.9.7",
"version": "3.10.0",
"description": "A Pothos plugin for defining fields with input objects",

@@ -39,10 +39,10 @@ "main": "./lib/index.js",

"devDependencies": {
"@pothos/core": "3.22.9",
"@pothos/plugin-prisma": "3.35.8",
"@pothos/plugin-validation": "3.8.7",
"@pothos/test-utils": "1.4.7",
"@prisma/client": "^4.5.0",
"@prisma/client": "^4.7.1",
"graphql": "16.6.0",
"graphql-tag": "^2.12.6",
"prisma": "^4.5.0"
"prisma": "^4.7.1",
"@pothos/core": "3.24.0",
"@pothos/plugin-validation": "3.8.7",
"@pothos/plugin-prisma": "3.40.0",
"@pothos/test-utils": "1.4.7"
},

@@ -49,0 +49,0 @@ "scripts": {

@@ -134,3 +134,3 @@ # With-Input Plugin

```typescript
builder.queryField('prismaFieldWithInput', (t) =>
builder.queryField('user', (t) =>
t.prismaFieldWithInput({

@@ -152,1 +152,26 @@ type: 'User',

```
### Customizing the default naming conventions
If you want to customize how the default input type names are generated you can provide a name
callback in `withInput.typeOptions`:
```typescript
import WithInputPlugin from '@pothos/plugin-with-input';
const builder = new SchemaBuilder({
plugins: [WithInputPlugin],
withInput: {
typeOptions: {
name: ({ parentTypeName, fieldName }) => {
const capitalizedFieldName = `${fieldName[0].toUpperCase()}${fieldName.slice(1)}`;
// This will remove the default Query/Mutation prefix from the input type name
if (parentTypeName === 'Query' || parentTypeName === 'Mutation') {
return `${capitalizedFieldName}Input`;
}
return `${parentTypeName}${capitalizedFieldName}Input`;
},
},
},
});
```

@@ -12,2 +12,12 @@ import { InputFieldBuilder, RootFieldBuilder, SchemaTypes } from '@pothos/core';

function defaultGetName({
parentTypeName,
fieldName,
}: {
parentTypeName: string;
fieldName: string;
}) {
return `${parentTypeName}${capitalize(fieldName)}Input`;
}
rootBuilderProto.fieldWithInput = function fieldWithInput({

@@ -21,2 +31,4 @@ typeOptions: { name: typeName, ...typeOptions } = {},

const inputRef = this.builder.inputRef(typeName ?? `UnnamedWithInputOn${this.typename}`);
const { name: getTypeName = defaultGetName, ...defaultTypeOptions } =
this.builder.options.withInput?.typeOptions ?? {};

@@ -37,7 +49,7 @@ const fieldRef = this.field({

this.builder.configStore.onFieldUse(fieldRef, (config) => {
const name = typeName ?? `${this.typename}${capitalize(config.name)}Input`;
const name = typeName ?? getTypeName({ parentTypeName: this.typename, fieldName: config.name });
this.builder.inputType(name, {
fields: () => input,
...this.builder.options.withInput?.typeOptions,
...defaultTypeOptions,
...typeOptions,

@@ -44,0 +56,0 @@ } as never);

@@ -20,3 +20,5 @@ import {

};
typeOptions?: Omit<PothosSchemaTypes.InputObjectTypeOptions<Types, {}>, 'fields'>;
typeOptions?: Omit<PothosSchemaTypes.InputObjectTypeOptions<Types, {}>, 'fields'> & {
name?: (options: { parentTypeName: string; fieldName: string }) => string;
};
}

@@ -23,0 +25,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc