@pothos/plugin-simple-objects
Advanced tools
Comparing version 3.6.8 to 3.7.0
# Change Log | ||
## 3.7.0 | ||
### Minor Changes | ||
- 740f09c6: Add fields as 3rd argument for simpleObject and simpleInterface | ||
## 3.6.8 | ||
@@ -4,0 +10,0 @@ |
@@ -1,2 +0,2 @@ | ||
import { FieldMap, FieldNullability, InputFieldMap, InterfaceParam, Normalize, ParentShape, SchemaTypes, TypeParam } from '@pothos/core'; | ||
import { FieldMap, FieldNullability, InputFieldMap, InterfaceFieldsShape, InterfaceParam, Normalize, ObjectFieldsShape, ParentShape, SchemaTypes, TypeParam } from '@pothos/core'; | ||
import { OutputShapeFromFields, SimpleObjectFieldsShape } from './types'; | ||
@@ -10,4 +10,4 @@ import type { PothosSimpleObjectsPlugin } from '.'; | ||
interface SchemaBuilder<Types extends SchemaTypes> { | ||
simpleObject: <Interfaces extends InterfaceParam<Types>[], Fields extends FieldMap, Shape extends Normalize<OutputShapeFromFields<Fields> & ParentShape<Types, Interfaces[number]>>>(name: string, options: SimpleObjectTypeOptions<Types, Interfaces, Fields, Shape>) => ObjectRef<Shape>; | ||
simpleInterface: <Fields extends FieldMap, Shape extends OutputShapeFromFields<Fields>, Interfaces extends InterfaceParam<SchemaTypes>[]>(name: string, options: SimpleInterfaceTypeOptions<Types, Fields, Shape, Interfaces>) => InterfaceRef<Shape>; | ||
simpleObject: <Interfaces extends InterfaceParam<Types>[], Fields extends FieldMap, Shape extends Normalize<OutputShapeFromFields<Fields> & ParentShape<Types, Interfaces[number]>>>(name: string, options: SimpleObjectTypeOptions<Types, Interfaces, Fields, Shape>, fields?: ObjectFieldsShape<Types, Shape>) => ObjectRef<Shape>; | ||
simpleInterface: <Fields extends FieldMap, Shape extends OutputShapeFromFields<Fields>, Interfaces extends InterfaceParam<SchemaTypes>[]>(name: string, options: SimpleInterfaceTypeOptions<Types, Fields, Shape, Interfaces>, fields?: InterfaceFieldsShape<Types, Shape>) => InterfaceRef<Shape>; | ||
} | ||
@@ -14,0 +14,0 @@ interface PothosKindToGraphQLType { |
@@ -1,2 +0,2 @@ | ||
import { FieldMap, FieldNullability, InputFieldMap, InterfaceParam, Normalize, ParentShape, SchemaTypes, TypeParam } from '@pothos/core'; | ||
import { FieldMap, FieldNullability, InputFieldMap, InterfaceFieldsShape, InterfaceParam, Normalize, ObjectFieldsShape, ParentShape, SchemaTypes, TypeParam } from '@pothos/core'; | ||
import { OutputShapeFromFields, SimpleObjectFieldsShape } from './types.js'; | ||
@@ -10,4 +10,4 @@ import type { PothosSimpleObjectsPlugin } from './index.js'; | ||
interface SchemaBuilder<Types extends SchemaTypes> { | ||
simpleObject: <Interfaces extends InterfaceParam<Types>[], Fields extends FieldMap, Shape extends Normalize<OutputShapeFromFields<Fields> & ParentShape<Types, Interfaces[number]>>>(name: string, options: SimpleObjectTypeOptions<Types, Interfaces, Fields, Shape>) => ObjectRef<Shape>; | ||
simpleInterface: <Fields extends FieldMap, Shape extends OutputShapeFromFields<Fields>, Interfaces extends InterfaceParam<SchemaTypes>[]>(name: string, options: SimpleInterfaceTypeOptions<Types, Fields, Shape, Interfaces>) => InterfaceRef<Shape>; | ||
simpleObject: <Interfaces extends InterfaceParam<Types>[], Fields extends FieldMap, Shape extends Normalize<OutputShapeFromFields<Fields> & ParentShape<Types, Interfaces[number]>>>(name: string, options: SimpleObjectTypeOptions<Types, Interfaces, Fields, Shape>, fields?: ObjectFieldsShape<Types, Shape>) => ObjectRef<Shape>; | ||
simpleInterface: <Fields extends FieldMap, Shape extends OutputShapeFromFields<Fields>, Interfaces extends InterfaceParam<SchemaTypes>[]>(name: string, options: SimpleInterfaceTypeOptions<Types, Fields, Shape, Interfaces>, fields?: InterfaceFieldsShape<Types, Shape>) => InterfaceRef<Shape>; | ||
} | ||
@@ -14,0 +14,0 @@ interface PothosKindToGraphQLType { |
@@ -9,3 +9,3 @@ import './global-types.js'; | ||
const proto = SchemaBuilder.prototype; | ||
proto.simpleObject = function simpleObject(name, options) { | ||
proto.simpleObject = function simpleObject(name, options, extraFields) { | ||
const ref = new ObjectRef(name); | ||
@@ -29,5 +29,8 @@ if (options.fields) { | ||
this.objectType(ref, options); | ||
if (extraFields) { | ||
this.objectFields(ref, extraFields); | ||
} | ||
return ref; | ||
}; | ||
proto.simpleInterface = function simpleInterface(name, options) { | ||
proto.simpleInterface = function simpleInterface(name, options, extraFields) { | ||
const ref = new InterfaceRef(name); | ||
@@ -51,4 +54,7 @@ if (options.fields) { | ||
this.interfaceType(ref, options); | ||
if (extraFields) { | ||
this.interfaceFields(ref, extraFields); | ||
} | ||
return ref; | ||
}; | ||
//# sourceMappingURL=index.js.map |
@@ -62,3 +62,3 @@ "use strict"; | ||
const proto = _core.default.prototype; | ||
proto.simpleObject = function simpleObject(name, options) { | ||
proto.simpleObject = function simpleObject(name, options, extraFields) { | ||
const ref = new _core.ObjectRef(name); | ||
@@ -82,5 +82,8 @@ if (options.fields) { | ||
this.objectType(ref, options); | ||
if (extraFields) { | ||
this.objectFields(ref, extraFields); | ||
} | ||
return ref; | ||
}; | ||
proto.simpleInterface = function simpleInterface(name, options) { | ||
proto.simpleInterface = function simpleInterface(name, options, extraFields) { | ||
const ref = new _core.InterfaceRef(name); | ||
@@ -104,2 +107,5 @@ if (options.fields) { | ||
this.interfaceType(ref, options); | ||
if (extraFields) { | ||
this.interfaceFields(ref, extraFields); | ||
} | ||
return ref; | ||
@@ -106,0 +112,0 @@ }; |
{ | ||
"name": "@pothos/plugin-simple-objects", | ||
"version": "3.6.8", | ||
"version": "3.7.0", | ||
"description": "A Pothos plugin for defining objects and interfaces without ts definitions for those types", | ||
@@ -5,0 +5,0 @@ "main": "./lib/index.js", |
@@ -62,2 +62,8 @@ # Simple Objects Plugin for Pothos | ||
}), | ||
// You can add aditional fields with resolvers with a third fields argument | ||
(t) => ({ | ||
fullName: t.string({ | ||
resolve: (user) => `${user.firstName} ${user.lastName}`, | ||
}), | ||
}) | ||
}); | ||
@@ -88,2 +94,18 @@ | ||
## Extending simple objects | ||
In some cases, you may want to add more complex fields with resolvers or args where the value isn't | ||
just passed down from the parent. | ||
In these cases, you can either add the field in the 3rd arg (fields) as shown above, or you can add | ||
additional fields to the type using methods like `builder.objectType`: | ||
```typescript | ||
builder.objectType(UserType, (t) => ({ | ||
fullName: t.string({ | ||
resolve: (user) => `${user.firstName} ${user.lastName}`, | ||
}), | ||
})); | ||
``` | ||
## Limitations | ||
@@ -90,0 +112,0 @@ |
@@ -6,4 +6,6 @@ /* eslint-disable @typescript-eslint/no-unused-vars */ | ||
InputFieldMap, | ||
InterfaceFieldsShape, | ||
InterfaceParam, | ||
Normalize, | ||
ObjectFieldsShape, | ||
ParentShape, | ||
@@ -32,2 +34,3 @@ SchemaTypes, | ||
options: SimpleObjectTypeOptions<Types, Interfaces, Fields, Shape>, | ||
fields?: ObjectFieldsShape<Types, Shape>, | ||
) => ObjectRef<Shape>; | ||
@@ -42,2 +45,3 @@ | ||
options: SimpleInterfaceTypeOptions<Types, Fields, Shape, Interfaces>, | ||
fields?: InterfaceFieldsShape<Types, Shape>, | ||
) => InterfaceRef<Shape>; | ||
@@ -44,0 +48,0 @@ } |
@@ -5,5 +5,7 @@ import './global-types'; | ||
FieldMap, | ||
InterfaceFieldsShape, | ||
InterfaceParam, | ||
InterfaceRef, | ||
Normalize, | ||
ObjectFieldsShape, | ||
ObjectRef, | ||
@@ -35,2 +37,3 @@ ParentShape, | ||
options: PothosSchemaTypes.SimpleObjectTypeOptions<SchemaTypes, Interfaces, Fields, Shape>, | ||
extraFields?: ObjectFieldsShape<SchemaTypes, Shape>, | ||
) { | ||
@@ -62,2 +65,6 @@ const ref = new ObjectRef<Shape>(name); | ||
if (extraFields) { | ||
this.objectFields(ref, extraFields); | ||
} | ||
return ref; | ||
@@ -73,2 +80,3 @@ }; | ||
options: PothosSchemaTypes.SimpleInterfaceTypeOptions<SchemaTypes, Fields, Shape, Interfaces>, | ||
extraFields?: InterfaceFieldsShape<SchemaTypes, Shape>, | ||
) { | ||
@@ -100,3 +108,7 @@ const ref = new InterfaceRef<Shape>(name); | ||
if (extraFields) { | ||
this.interfaceFields(ref, extraFields); | ||
} | ||
return ref; | ||
}; |
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
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
44641
448
114