A plugin for creating fields with a single input object. This plugin adds a new t.fieldWithInput
method that allows you to more easily define fields with a single input type without having to
define it separately.
import WithInputPlugin from '@pothos/plugin-with-input';const builder = new SchemaBuilder({ plugins: [WithInputPlugin], // optional withInput: { typeOptions: { // default options for Input object types created by this plugin }, argOptions: { // set required: false to override default behavior }, },});
You can customize the name of your Input object, and the name of the input argument:
builder.queryType({ fields: (t) => ({ example: t.fieldWithInput({ typeOptions: { name: 'CustomInputTypeName', // Additional options for the input type can be added here }, argOptions: { name: 'customArgName', // Additional options for the input argument can be added here }, input: { id: t.input.id({ required: true }), }, type: 'ID', // inputs are now under `customArgName` resolve: (root, args) => args.customArgName.id, }), }),});
You can configure the global default for input args when creating the builder by providing
WithInputArgRequired in the builders SchemaTypes, and setting withInput.argOptions.required.