With-Input Plugin
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.
Usage
Install
yarn add @pothos/plugin-with-input
Setup
import WithInputPlugin from '@pothos/plugin-with-input';
const builder = new SchemaBuilder({
plugins: [WithInputPlugin],
withInput: {
typeOptions: {
},
argOptions: {
},
},
});
Defining fields with inputs
builder.queryType({
fields: (t) => ({
example: t.fieldWithInput({
input: {
id: t.input.id({ required: true }),
},
type: 'ID',
resolve: (root, args) => args.input.id,
}),
}),
});
This will produce a schema like:
type Query {
example(input: QueryExampleInput!): ID!
}
input QueryExampleInput {
id: ID!
}
The input name will default to ${ParentType.name}${Field.name}Input
.
Customizing your input object
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',
},
argOptions: {
name: 'customArgName',
},
input: {
id: t.input.id({ required: true }),
},
type: 'ID',
resolve: (root, args) => args.customArgName.id,
}),
}),
});