@pothos/plugin-relay
Advanced tools
Comparing version 3.11.0 to 3.12.0
# Change Log | ||
## 3.12.0 | ||
### Minor Changes | ||
- 1735eb40: Add edgeObject method to relay plugin | ||
## 3.11.0 | ||
@@ -4,0 +10,0 @@ |
@@ -39,6 +39,17 @@ import { FieldKind, FieldNullability, FieldOptionsFromKind, FieldRef, FieldRequiredness, InputFieldMap, InputFieldRef, InputFieldsFromShape, InputShapeFromFields, InputShapeFromTypeParam, inputShapeKey, InterfaceParam, NormalizeArgs, ObjectFieldsShape, ObjectFieldThunk, ObjectParam, OutputShape, OutputType, ParentShape, Resolver, SchemaTypes, ShapeFromTypeParam } from '@pothos/core'; | ||
}, | ||
edgeOptions?: ConnectionEdgeObjectOptions<Types, Type, NodeNullability, ResolveReturnShape> & { | ||
edgeOptions?: ObjectRef<{ | ||
cursor: string; | ||
node?: ShapeFromTypeParam<Types, Type, NodeNullability>; | ||
}> | (ConnectionEdgeObjectOptions<Types, Type, NodeNullability, ResolveReturnShape> & { | ||
name?: string; | ||
} | ||
}) | ||
]>) => ObjectRef<ConnectionShapeForType<Types, Type, false, EdgeNullability, NodeNullability>>; | ||
edgeObject: <Type extends OutputType<Types>, ResolveReturnShape, NodeNullability extends boolean = Types['DefaultNodeNullability']>(edgeOptions: ConnectionEdgeObjectOptions<Types, Type, NodeNullability, ResolveReturnShape> & { | ||
type: Type; | ||
name: string; | ||
nodeNullable?: NodeNullability; | ||
}) => ObjectRef<{ | ||
cursor: string; | ||
node: ShapeFromTypeParam<Types, Type, NodeNullability>; | ||
}>; | ||
} | ||
@@ -66,4 +77,7 @@ interface InputFieldBuilder<Types extends SchemaTypes, Kind extends 'Arg' | 'InputObject'> { | ||
options: ConnectionFieldOptions<Types, ParentShape, Type, Nullable, EdgeNullability, NodeNullability, Args, ResolveReturnShape> & Omit<FieldOptionsFromKind<Types, ParentShape, Type, Nullable, Args & InputFieldsFromShape<DefaultConnectionArguments>, Kind, ParentShape, ResolveReturnShape>, 'args' | 'resolve' | 'type'>, | ||
connectionOptions?: Omit<ConnectionObjectOptions<Types, Type, EdgeNullability, NodeNullability, ResolveReturnShape>, 'edgesNullable'>, | ||
edgeOptions?: ConnectionEdgeObjectOptions<Types, Type, NodeNullability, ResolveReturnShape> | ||
connectionOptions?: ObjectRef<ConnectionShapeForType<Types, Type, false, EdgeNullability, NodeNullability>> | Omit<ConnectionObjectOptions<Types, Type, EdgeNullability, NodeNullability, ResolveReturnShape>, 'edgesNullable'>, | ||
edgeOptions?: ObjectRef<{ | ||
cursor: string; | ||
node?: ShapeFromTypeParam<Types, Type, NodeNullability>; | ||
}> | ConnectionEdgeObjectOptions<Types, Type, NodeNullability, ResolveReturnShape> | ||
]>) => FieldRef<ConnectionShapeForType<Types, Type, Nullable, EdgeNullability, NodeNullability>>; | ||
@@ -70,0 +84,0 @@ } |
@@ -1,2 +0,2 @@ | ||
import { assertArray, RootFieldBuilder } from '@pothos/core'; | ||
import { assertArray, ObjectRef, RootFieldBuilder } from '@pothos/core'; | ||
import { capitalize, resolveNodes } from './utils/index.js'; | ||
@@ -79,7 +79,7 @@ import { internalEncodeGlobalID } from './utils/internal.js'; | ||
}; | ||
fieldBuilderProto.connection = function connection({ type, edgesNullable, nodeNullable, ...fieldOptions }, { name: connectionNameFromOptions, ...connectionOptions } = {}, { name: edgeNameFromOptions, ...edgeOptions } = {}) { | ||
const placeholderRef = this.builder.objectRef("Unnamed connection"); | ||
fieldBuilderProto.connection = function connection({ type, edgesNullable, nodeNullable, ...fieldOptions }, connectionOptionsOrRef = {}, edgeOptionsOrRef = {}) { | ||
const connectionRef = connectionOptionsOrRef instanceof ObjectRef ? connectionOptionsOrRef : this.builder.objectRef("Unnamed connection"); | ||
const fieldRef = this.field({ | ||
...fieldOptions, | ||
type: placeholderRef, | ||
type: connectionRef, | ||
args: { | ||
@@ -91,19 +91,21 @@ ...fieldOptions.args, | ||
}); | ||
this.builder.configStore.onFieldUse(fieldRef, (fieldConfig) => { | ||
const connectionName = connectionNameFromOptions !== null && connectionNameFromOptions !== void 0 ? connectionNameFromOptions : `${this.typename}${capitalize(fieldConfig.name)}${fieldConfig.name.toLowerCase().endsWith("connection") ? "" : "Connection"}`; | ||
const edgeName = edgeNameFromOptions !== null && edgeNameFromOptions !== void 0 ? edgeNameFromOptions : `${connectionName}Edge`; | ||
this.builder.connectionObject({ | ||
type, | ||
edgesNullable, | ||
nodeNullable, | ||
name: connectionName, | ||
...connectionOptions | ||
}, { | ||
name: edgeName, | ||
...edgeOptions | ||
if (!(connectionOptionsOrRef instanceof ObjectRef)) { | ||
this.builder.configStore.onFieldUse(fieldRef, (fieldConfig) => { | ||
var _name; | ||
const connectionName = (_name = connectionOptionsOrRef.name) !== null && _name !== void 0 ? _name : `${this.typename}${capitalize(fieldConfig.name)}${fieldConfig.name.toLowerCase().endsWith("connection") ? "" : "Connection"}`; | ||
this.builder.connectionObject({ | ||
type, | ||
edgesNullable, | ||
nodeNullable, | ||
...connectionOptionsOrRef, | ||
name: connectionName | ||
}, edgeOptionsOrRef instanceof ObjectRef ? edgeOptionsOrRef : { | ||
name: `${connectionName}Edge`, | ||
...edgeOptionsOrRef | ||
}); | ||
this.builder.configStore.associateRefWithName(connectionRef, connectionName); | ||
}); | ||
this.builder.configStore.associateRefWithName(placeholderRef, connectionName); | ||
}); | ||
} | ||
return fieldRef; | ||
}; | ||
//# sourceMappingURL=field-builder.js.map |
@@ -1,2 +0,2 @@ | ||
import SchemaBuilder, { createContextCache, getTypeBrand, verifyRef } from '@pothos/core'; | ||
import SchemaBuilder, { createContextCache, getTypeBrand, ObjectRef, verifyRef } from '@pothos/core'; | ||
import { capitalize, resolveNodes } from './utils/index.js'; | ||
@@ -227,14 +227,17 @@ const schemaBuilderProto = SchemaBuilder.prototype; | ||
}; | ||
schemaBuilderProto.connectionObject = function connectionObject({ type, name: connectionName, edgesNullable: edgesNullableField, nodeNullable: nodeNullableField, ...connectionOptions }, { name: edgeNameFromOptions, ...edgeOptions } = {}) { | ||
schemaBuilderProto.connectionObject = function connectionObject({ type, name: connectionName, edgesNullable: edgesNullableField, nodeNullable, ...connectionOptions }, edgeOptionsOrRef) { | ||
var ref; | ||
verifyRef(type); | ||
const { cursorType = "String", edgesFieldOptions: { nullable: edgesNullable = { | ||
const { edgesFieldOptions: { nullable: edgesNullable = { | ||
items: true, | ||
list: false | ||
}, ...edgesFieldOptions } = {}, cursorFieldOptions = {}, nodeFieldOptions: { nullable: nodeNullable = false, ...nodeFieldOptions } = {}, pageInfoFieldOptions = {}, } = this.options.relayOptions; | ||
}, ...edgesFieldOptions } = {}, pageInfoFieldOptions = {}, } = this.options.relayOptions; | ||
const connectionRef = this.objectRef(connectionName); | ||
const edgeName = edgeNameFromOptions !== null && edgeNameFromOptions !== void 0 ? edgeNameFromOptions : `${connectionName.replace(/Connection$/, "")}Edge`; | ||
const edgeRef = this.objectRef(edgeName); | ||
const edgeRef = edgeOptionsOrRef instanceof ObjectRef ? edgeOptionsOrRef : this.edgeObject({ | ||
name: `${connectionName.replace(/Connection$/, "")}Edge`, | ||
...edgeOptionsOrRef, | ||
nodeNullable, | ||
type | ||
}); | ||
const connectionFields = connectionOptions.fields; | ||
const edgeFields = edgeOptions.fields; | ||
this.objectType(connectionRef, { | ||
@@ -262,2 +265,14 @@ ...connectionOptions, | ||
}); | ||
if (!connectionRefs.has(this)) { | ||
connectionRefs.set(this, []); | ||
} | ||
connectionRefs.get(this).push(connectionRef); | ||
(ref = globalConnectionFieldsMap.get(this)) === null || ref === void 0 ? void 0 : ref.forEach((fieldFn) => void fieldFn(connectionRef)); | ||
return connectionRef; | ||
}; | ||
schemaBuilderProto.edgeObject = function edgeObject({ type, name: edgeName, nodeNullable: nodeFieldNullable, ...edgeOptions }) { | ||
verifyRef(type); | ||
const { cursorType = "String", cursorFieldOptions = {}, nodeFieldOptions: { nullable: nodeNullable = false, ...nodeFieldOptions } = {}, } = this.options.relayOptions; | ||
const edgeRef = this.objectRef(edgeName); | ||
const edgeFields = edgeOptions.fields; | ||
this.objectType(edgeRef, { | ||
@@ -268,3 +283,3 @@ ...edgeOptions, | ||
node: t.field({ | ||
nullable: nodeNullableField !== null && nodeNullableField !== void 0 ? nodeNullableField : nodeNullable, | ||
nullable: nodeFieldNullable !== null && nodeFieldNullable !== void 0 ? nodeFieldNullable : nodeNullable, | ||
...nodeFieldOptions, | ||
@@ -283,9 +298,4 @@ type, | ||
}); | ||
if (!connectionRefs.has(this)) { | ||
connectionRefs.set(this, []); | ||
} | ||
connectionRefs.get(this).push(connectionRef); | ||
(ref = globalConnectionFieldsMap.get(this)) === null || ref === void 0 ? void 0 : ref.forEach((fieldFn) => void fieldFn(connectionRef)); | ||
return connectionRef; | ||
return edgeRef; | ||
}; | ||
//# sourceMappingURL=schema-builder.js.map |
@@ -82,7 +82,7 @@ "use strict"; | ||
}; | ||
fieldBuilderProto.connection = function connection({ type , edgesNullable , nodeNullable , ...fieldOptions }, { name: connectionNameFromOptions , ...connectionOptions } = {}, { name: edgeNameFromOptions , ...edgeOptions } = {}) { | ||
const placeholderRef = this.builder.objectRef('Unnamed connection'); | ||
fieldBuilderProto.connection = function connection({ type , edgesNullable , nodeNullable , ...fieldOptions }, connectionOptionsOrRef = {}, edgeOptionsOrRef = {}) { | ||
const connectionRef = connectionOptionsOrRef instanceof _core.ObjectRef ? connectionOptionsOrRef : this.builder.objectRef('Unnamed connection'); | ||
const fieldRef = this.field({ | ||
...fieldOptions, | ||
type: placeholderRef, | ||
type: connectionRef, | ||
args: { | ||
@@ -94,17 +94,19 @@ ...fieldOptions.args, | ||
}); | ||
this.builder.configStore.onFieldUse(fieldRef, (fieldConfig)=>{ | ||
const connectionName = connectionNameFromOptions !== null && connectionNameFromOptions !== void 0 ? connectionNameFromOptions : `${this.typename}${(0, _utils).capitalize(fieldConfig.name)}${fieldConfig.name.toLowerCase().endsWith('connection') ? '' : 'Connection'}`; | ||
const edgeName = edgeNameFromOptions !== null && edgeNameFromOptions !== void 0 ? edgeNameFromOptions : `${connectionName}Edge`; | ||
this.builder.connectionObject({ | ||
type, | ||
edgesNullable, | ||
nodeNullable, | ||
name: connectionName, | ||
...connectionOptions | ||
}, { | ||
name: edgeName, | ||
...edgeOptions | ||
if (!(connectionOptionsOrRef instanceof _core.ObjectRef)) { | ||
this.builder.configStore.onFieldUse(fieldRef, (fieldConfig)=>{ | ||
var _name; | ||
const connectionName = (_name = connectionOptionsOrRef.name) !== null && _name !== void 0 ? _name : `${this.typename}${(0, _utils).capitalize(fieldConfig.name)}${fieldConfig.name.toLowerCase().endsWith('connection') ? '' : 'Connection'}`; | ||
this.builder.connectionObject({ | ||
type, | ||
edgesNullable, | ||
nodeNullable, | ||
...connectionOptionsOrRef, | ||
name: connectionName | ||
}, edgeOptionsOrRef instanceof _core.ObjectRef ? edgeOptionsOrRef : { | ||
name: `${connectionName}Edge`, | ||
...edgeOptionsOrRef | ||
}); | ||
this.builder.configStore.associateRefWithName(connectionRef, connectionName); | ||
}); | ||
this.builder.configStore.associateRefWithName(placeholderRef, connectionName); | ||
}); | ||
} | ||
return fieldRef; | ||
@@ -111,0 +113,0 @@ }; |
@@ -279,14 +279,17 @@ "use strict"; | ||
}; | ||
schemaBuilderProto.connectionObject = function connectionObject({ type , name: connectionName , edgesNullable: edgesNullableField , nodeNullable: nodeNullableField , ...connectionOptions }, { name: edgeNameFromOptions , ...edgeOptions } = {}) { | ||
schemaBuilderProto.connectionObject = function connectionObject({ type , name: connectionName , edgesNullable: edgesNullableField , nodeNullable , ...connectionOptions }, edgeOptionsOrRef) { | ||
var ref; | ||
(0, _core).verifyRef(type); | ||
const { cursorType ='String' , edgesFieldOptions: { nullable: edgesNullable = { | ||
const { edgesFieldOptions: { nullable: edgesNullable = { | ||
items: true, | ||
list: false | ||
} , ...edgesFieldOptions } = {} , cursorFieldOptions ={} , nodeFieldOptions: { nullable: nodeNullable = false , ...nodeFieldOptions } = {} , pageInfoFieldOptions ={} , } = this.options.relayOptions; | ||
} , ...edgesFieldOptions } = {} , pageInfoFieldOptions ={} , } = this.options.relayOptions; | ||
const connectionRef = this.objectRef(connectionName); | ||
const edgeName = edgeNameFromOptions !== null && edgeNameFromOptions !== void 0 ? edgeNameFromOptions : `${connectionName.replace(/Connection$/, '')}Edge`; | ||
const edgeRef = this.objectRef(edgeName); | ||
const edgeRef = edgeOptionsOrRef instanceof _core.ObjectRef ? edgeOptionsOrRef : this.edgeObject({ | ||
name: `${connectionName.replace(/Connection$/, '')}Edge`, | ||
...edgeOptionsOrRef, | ||
nodeNullable, | ||
type | ||
}); | ||
const connectionFields = connectionOptions.fields; | ||
const edgeFields = edgeOptions.fields; | ||
this.objectType(connectionRef, { | ||
@@ -314,2 +317,15 @@ ...connectionOptions, | ||
}); | ||
if (!connectionRefs.has(this)) { | ||
connectionRefs.set(this, []); | ||
} | ||
connectionRefs.get(this).push(connectionRef); | ||
(ref = globalConnectionFieldsMap.get(this)) === null || ref === void 0 ? void 0 : ref.forEach((fieldFn)=>void fieldFn(connectionRef) | ||
); | ||
return connectionRef; | ||
}; | ||
schemaBuilderProto.edgeObject = function edgeObject({ type , name: edgeName , nodeNullable: nodeFieldNullable , ...edgeOptions }) { | ||
(0, _core).verifyRef(type); | ||
const { cursorType ='String' , cursorFieldOptions ={} , nodeFieldOptions: { nullable: nodeNullable = false , ...nodeFieldOptions } = {} , } = this.options.relayOptions; | ||
const edgeRef = this.objectRef(edgeName); | ||
const edgeFields = edgeOptions.fields; | ||
this.objectType(edgeRef, { | ||
@@ -320,3 +336,3 @@ ...edgeOptions, | ||
node: t.field({ | ||
nullable: nodeNullableField !== null && nodeNullableField !== void 0 ? nodeNullableField : nodeNullable, | ||
nullable: nodeFieldNullable !== null && nodeFieldNullable !== void 0 ? nodeFieldNullable : nodeNullable, | ||
...nodeFieldOptions, | ||
@@ -335,11 +351,5 @@ type, | ||
}); | ||
if (!connectionRefs.has(this)) { | ||
connectionRefs.set(this, []); | ||
} | ||
connectionRefs.get(this).push(connectionRef); | ||
(ref = globalConnectionFieldsMap.get(this)) === null || ref === void 0 ? void 0 : ref.forEach((fieldFn)=>void fieldFn(connectionRef) | ||
); | ||
return connectionRef; | ||
return edgeRef; | ||
}; | ||
//# sourceMappingURL=schema-builder.js.map |
{ | ||
"name": "@pothos/plugin-relay", | ||
"version": "3.11.0", | ||
"version": "3.12.0", | ||
"description": "A Pothos plugin for adding relay style connections, nodes, and cursor based pagination to your GraphQL schema", | ||
@@ -41,3 +41,3 @@ "main": "./lib/index.js", | ||
"@pothos/core": "3.11.0", | ||
"@pothos/test-utils": "1.2.0", | ||
"@pothos/test-utils": "1.2.1", | ||
"graphql": "16.5.0", | ||
@@ -44,0 +44,0 @@ "graphql-subscriptions": "^2.0.0", |
@@ -32,7 +32,7 @@ # Relay Plugin | ||
- `clientMutationId`: `required` (default) | `omit` | `optional`. Determins if clientMutationId | ||
- `clientMutationId`: `required` (default) | `omit` | `optional`. Determines if clientMutationId | ||
fields are created on `relayMutationFields`, and if they are required. | ||
- `cursorType`: `String` | `ID`. Determines type used for cursor fields. Defaults behavior due to | ||
legacy reasons is `String` for everything except for connection arguments which use `ID`. | ||
Overwritting this default is hightly encouraged. | ||
Overwriting this default is highly encouraged. | ||
- `nodeQueryOptions`: Options for the `node` field on the query object | ||
@@ -127,3 +127,3 @@ - `nodesQueryOptions`: Options for the `nodes` field on the query object | ||
builder.node(NumberThing, { | ||
// defiine an id field | ||
// define an id field | ||
id: { | ||
@@ -367,4 +367,5 @@ resolve: (num) => num.id, | ||
// You can use connection object with normal fields | ||
builder.queryFields((t) => ({ | ||
things: t.connection({ | ||
things: t.field({ | ||
type: ThingsConnection, | ||
@@ -381,2 +382,14 @@ args: { | ||
})); | ||
// Or by providing the connection type when creating a connection field | ||
builder.queryFields((t) => ({ | ||
things: t.connection({ | ||
resolve: (parent, args) => { | ||
return resolveOffsetConnection({ args }, ({ limit, offset }) => { | ||
return getThings(offset, limit); | ||
}); | ||
}, | ||
}), | ||
ThingsConnection, | ||
})); | ||
``` | ||
@@ -387,2 +400,46 @@ | ||
### Reusing edge objects | ||
Similarly you can directly create and re-use edge objects | ||
```typescript | ||
import { resolveOffsetConnection } from '@pothos/plugin-relay'; | ||
const ThingsEdge = builder.edgeObject( | ||
{ | ||
name: 'ThingsEdge', | ||
type: SomeThing, | ||
}, | ||
); | ||
// The edge object can be used when creating a connection object | ||
const ThingsConnection = builder.connectionObject( | ||
{ | ||
type: SomeThing, | ||
name: 'ThingsConnection', | ||
}, | ||
ThingsEdge, | ||
); | ||
// Or when creating a connection field | ||
builder.queryFields((t) => ({ | ||
things: t.connection({ | ||
resolve: (parent, args) => { | ||
return resolveOffsetConnection({ args }, ({ limit, offset }) => { | ||
return getThings(offset, limit); | ||
}); | ||
}, | ||
}), | ||
{ | ||
// connection options | ||
}, | ||
ThingsEdge, | ||
})); | ||
``` | ||
`builder.connectionObject` creates the connect object type and the associated Edge type. | ||
`t.arg.connectionArgs()` will create the default connection args. | ||
### Expose nodes | ||
@@ -477,5 +534,5 @@ | ||
In the above example, we are just returning a static nubmer for our `totalCount` field. To make this | ||
In the above example, we are just returning a static number for our `totalCount` field. To make this | ||
more useful, we need to have our resolvers for each connection actually return an object that | ||
contains a totalCount for us. To guarantee that resolvers correclty implement this behavior, we can | ||
contains a totalCount for us. To guarantee that resolvers correctly implement this behavior, we can | ||
define custom properties that must be returned from connection resolvers when we set up our builder: | ||
@@ -509,3 +566,3 @@ | ||
helpers since they will not automatically return your custom properties. You will need to manually | ||
add in any custom props after gettig the result from the helpers: | ||
add in any custom props after getting the result from the helpers: | ||
@@ -552,6 +609,6 @@ ```typescript | ||
The types provided for `DefaultEdgesNullability` and `DefaultNodeNullability` must match the values | ||
provided in the nullable option of `edgesFieldOptions` and `nodeFieldOptions` respectivly. This will | ||
set the default nullabilitty for all connections created by your builder. | ||
provided in the nullable option of `edgesFieldOptions` and `nodeFieldOptions` respectively. This | ||
will set the default nullability for all connections created by your builder. | ||
Nullablity for `edges` fields defaults to `{ list: false, items: true }` and the nullablity of | ||
nullability for `edges` fields defaults to `{ list: false, items: true }` and the nullability of | ||
`node` fields default to `false`. | ||
@@ -558,0 +615,0 @@ |
@@ -9,2 +9,3 @@ import { GraphQLResolveInfo } from 'graphql'; | ||
InterfaceRef, | ||
ObjectRef, | ||
RootFieldBuilder, | ||
@@ -180,11 +181,15 @@ SchemaTypes, | ||
{ type, edgesNullable, nodeNullable, ...fieldOptions }, | ||
{ name: connectionNameFromOptions, ...connectionOptions } = {} as never, | ||
{ name: edgeNameFromOptions, ...edgeOptions } = {} as never, | ||
connectionOptionsOrRef = {} as never, | ||
edgeOptionsOrRef = {} as never, | ||
) { | ||
const placeholderRef = | ||
this.builder.objectRef<ConnectionShape<SchemaTypes, unknown, boolean>>('Unnamed connection'); | ||
const connectionRef = | ||
connectionOptionsOrRef instanceof ObjectRef | ||
? connectionOptionsOrRef | ||
: this.builder.objectRef<ConnectionShape<SchemaTypes, unknown, boolean>>( | ||
'Unnamed connection', | ||
); | ||
const fieldRef = this.field({ | ||
...fieldOptions, | ||
type: placeholderRef, | ||
type: connectionRef, | ||
args: { | ||
@@ -197,28 +202,31 @@ ...fieldOptions.args, | ||
this.builder.configStore.onFieldUse(fieldRef, (fieldConfig) => { | ||
const connectionName = | ||
connectionNameFromOptions ?? | ||
`${this.typename}${capitalize(fieldConfig.name)}${ | ||
fieldConfig.name.toLowerCase().endsWith('connection') ? '' : 'Connection' | ||
}`; | ||
const edgeName = edgeNameFromOptions ?? `${connectionName}Edge`; | ||
if (!(connectionOptionsOrRef instanceof ObjectRef)) { | ||
this.builder.configStore.onFieldUse(fieldRef, (fieldConfig) => { | ||
const connectionName = | ||
connectionOptionsOrRef.name ?? | ||
`${this.typename}${capitalize(fieldConfig.name)}${ | ||
fieldConfig.name.toLowerCase().endsWith('connection') ? '' : 'Connection' | ||
}`; | ||
this.builder.connectionObject( | ||
{ | ||
type, | ||
edgesNullable, | ||
nodeNullable, | ||
name: connectionName, | ||
...connectionOptions, | ||
}, | ||
{ | ||
name: edgeName, | ||
...edgeOptions, | ||
}, | ||
); | ||
this.builder.connectionObject( | ||
{ | ||
type, | ||
edgesNullable, | ||
nodeNullable, | ||
...connectionOptionsOrRef, | ||
name: connectionName, | ||
}, | ||
edgeOptionsOrRef instanceof ObjectRef | ||
? edgeOptionsOrRef | ||
: { | ||
name: `${connectionName}Edge`, | ||
...edgeOptionsOrRef, | ||
}, | ||
); | ||
this.builder.configStore.associateRefWithName(placeholderRef, connectionName); | ||
}); | ||
this.builder.configStore.associateRefWithName(connectionRef, connectionName); | ||
}); | ||
} | ||
return fieldRef as never; | ||
}; |
@@ -135,13 +135,32 @@ import { | ||
}, | ||
edgeOptions?: ConnectionEdgeObjectOptions< | ||
Types, | ||
Type, | ||
NodeNullability, | ||
ResolveReturnShape | ||
> & { | ||
name?: string; | ||
}, | ||
edgeOptions?: | ||
| ObjectRef<{ | ||
cursor: string; | ||
node?: ShapeFromTypeParam<Types, Type, NodeNullability>; | ||
}> | ||
| (ConnectionEdgeObjectOptions<Types, Type, NodeNullability, ResolveReturnShape> & { | ||
name?: string; | ||
}), | ||
] | ||
> | ||
) => ObjectRef<ConnectionShapeForType<Types, Type, false, EdgeNullability, NodeNullability>>; | ||
edgeObject: < | ||
Type extends OutputType<Types>, | ||
ResolveReturnShape, | ||
NodeNullability extends boolean = Types['DefaultNodeNullability'], | ||
>( | ||
edgeOptions: ConnectionEdgeObjectOptions< | ||
Types, | ||
Type, | ||
NodeNullability, | ||
ResolveReturnShape | ||
> & { | ||
type: Type; | ||
name: string; | ||
nodeNullable?: NodeNullability; | ||
}, | ||
) => ObjectRef<{ | ||
cursor: string; | ||
node: ShapeFromTypeParam<Types, Type, NodeNullability>; | ||
}>; | ||
} | ||
@@ -248,18 +267,22 @@ | ||
>, | ||
connectionOptions?: Omit< | ||
ConnectionObjectOptions< | ||
Types, | ||
Type, | ||
EdgeNullability, | ||
NodeNullability, | ||
ResolveReturnShape | ||
>, | ||
'edgesNullable' | ||
>, | ||
edgeOptions?: ConnectionEdgeObjectOptions< | ||
Types, | ||
Type, | ||
NodeNullability, | ||
ResolveReturnShape | ||
>, | ||
connectionOptions?: | ||
| ObjectRef< | ||
ConnectionShapeForType<Types, Type, false, EdgeNullability, NodeNullability> | ||
> | ||
| Omit< | ||
ConnectionObjectOptions< | ||
Types, | ||
Type, | ||
EdgeNullability, | ||
NodeNullability, | ||
ResolveReturnShape | ||
>, | ||
'edgesNullable' | ||
>, | ||
edgeOptions?: | ||
| ObjectRef<{ | ||
cursor: string; | ||
node?: ShapeFromTypeParam<Types, Type, NodeNullability>; | ||
}> | ||
| ConnectionEdgeObjectOptions<Types, Type, NodeNullability, ResolveReturnShape>, | ||
] | ||
@@ -266,0 +289,0 @@ > |
@@ -362,6 +362,6 @@ /* eslint-disable @typescript-eslint/no-unsafe-return */ | ||
edgesNullable: edgesNullableField, | ||
nodeNullable: nodeNullableField, | ||
nodeNullable, | ||
...connectionOptions | ||
}, | ||
{ name: edgeNameFromOptions, ...edgeOptions } = {} as never, | ||
edgeOptionsOrRef, | ||
) { | ||
@@ -371,3 +371,2 @@ verifyRef(type); | ||
const { | ||
cursorType = 'String', | ||
edgesFieldOptions: { | ||
@@ -377,4 +376,2 @@ nullable: edgesNullable = { items: true, list: false }, | ||
} = {} as never, | ||
cursorFieldOptions = {} as never, | ||
nodeFieldOptions: { nullable: nodeNullable = false, ...nodeFieldOptions } = {} as never, | ||
pageInfoFieldOptions = {} as never, | ||
@@ -386,9 +383,12 @@ } = this.options.relayOptions; | ||
const edgeName = edgeNameFromOptions ?? `${connectionName.replace(/Connection$/, '')}Edge`; | ||
const edgeRef = | ||
edgeOptionsOrRef instanceof ObjectRef | ||
? edgeOptionsOrRef | ||
: this.edgeObject({ | ||
name: `${connectionName.replace(/Connection$/, '')}Edge`, | ||
...edgeOptionsOrRef, | ||
nodeNullable, | ||
type, | ||
}); | ||
const edgeRef = this.objectRef<{ | ||
cursor: string; | ||
node: unknown; | ||
}>(edgeName); | ||
const connectionFields = connectionOptions.fields as unknown as | ||
@@ -398,12 +398,2 @@ | ObjectFieldsShape<SchemaTypes, ConnectionShape<SchemaTypes, unknown, false>> | ||
const edgeFields = edgeOptions.fields as | ||
| ObjectFieldsShape< | ||
SchemaTypes, | ||
{ | ||
cursor: string; | ||
node: unknown; | ||
} | ||
> | ||
| undefined; | ||
this.objectType(connectionRef, { | ||
@@ -422,3 +412,3 @@ ...connectionOptions, | ||
type: [edgeRef], | ||
resolve: (parent) => parent.edges, | ||
resolve: (parent) => parent.edges as [], | ||
}), | ||
@@ -429,2 +419,42 @@ ...connectionFields?.(t as never), | ||
if (!connectionRefs.has(this)) { | ||
connectionRefs.set(this, []); | ||
} | ||
connectionRefs.get(this)!.push(connectionRef); | ||
globalConnectionFieldsMap.get(this)?.forEach((fieldFn) => void fieldFn(connectionRef)); | ||
return connectionRef as never; | ||
}; | ||
schemaBuilderProto.edgeObject = function edgeObject({ | ||
type, | ||
name: edgeName, | ||
nodeNullable: nodeFieldNullable, | ||
...edgeOptions | ||
}) { | ||
verifyRef(type); | ||
const { | ||
cursorType = 'String', | ||
cursorFieldOptions = {} as never, | ||
nodeFieldOptions: { nullable: nodeNullable = false, ...nodeFieldOptions } = {} as never, | ||
} = this.options.relayOptions; | ||
const edgeRef = this.objectRef<{ | ||
cursor: string; | ||
node: unknown; | ||
}>(edgeName); | ||
const edgeFields = edgeOptions.fields as | ||
| ObjectFieldsShape< | ||
SchemaTypes, | ||
{ | ||
cursor: string; | ||
node: unknown; | ||
} | ||
> | ||
| undefined; | ||
this.objectType(edgeRef, { | ||
@@ -434,3 +464,3 @@ ...edgeOptions, | ||
node: t.field({ | ||
nullable: nodeNullableField ?? nodeNullable, | ||
nullable: nodeFieldNullable ?? nodeNullable, | ||
...nodeFieldOptions, | ||
@@ -449,11 +479,3 @@ type, | ||
if (!connectionRefs.has(this)) { | ||
connectionRefs.set(this, []); | ||
} | ||
connectionRefs.get(this)!.push(connectionRef); | ||
globalConnectionFieldsMap.get(this)?.forEach((fieldFn) => void fieldFn(connectionRef)); | ||
return connectionRef as never; | ||
return edgeRef as never; | ||
}; |
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
337816
3863
638