@pothos/plugin-relay
Advanced tools
Comparing version 3.7.0 to 3.8.0
# Change Log | ||
## 3.8.0 | ||
### Minor Changes | ||
- 6279235f: Update build process to use swc and move type definitions to dts directory | ||
### Patch Changes | ||
- 21a2454e: update dev dependencies | ||
## 3.7.0 | ||
@@ -4,0 +14,0 @@ |
@@ -1,2 +0,2 @@ | ||
import { assertArray, RootFieldBuilder, } from '@pothos/core'; | ||
import { assertArray, RootFieldBuilder } from '@pothos/core'; | ||
import { capitalize, resolveNodes } from './utils/index.js'; | ||
@@ -13,5 +13,3 @@ import { internalEncodeGlobalID } from './utils/internal.js'; | ||
if (Array.isArray(result)) { | ||
return (await Promise.all(result)).map((item) => item == null || typeof item === "string" | ||
? item | ||
: internalEncodeGlobalID(this.builder, this.builder.configStore.getTypeConfig(item.type).name, String(item.id))); | ||
return (await Promise.all(result)).map((item) => item == null || typeof item === "string" ? item : internalEncodeGlobalID(this.builder, this.builder.configStore.getTypeConfig(item.type).name, String(item.id))); | ||
} | ||
@@ -22,4 +20,6 @@ return null; | ||
...options, | ||
type: ["ID"], | ||
resolve: wrappedResolve, // resolve is not expected because we don't know FieldKind | ||
type: [ | ||
"ID" | ||
], | ||
resolve: wrappedResolve | ||
}); | ||
@@ -39,3 +39,3 @@ }; | ||
type: "ID", | ||
resolve: wrappedResolve, // resolve is not expected because we don't know FieldKind | ||
resolve: wrappedResolve | ||
}); | ||
@@ -49,11 +49,11 @@ }; | ||
resolve: async (parent, args, context, info) => { | ||
const rawID = (await id(parent, args, context, info)); | ||
const rawID = await id(parent, args, context, info); | ||
if (rawID == null) { | ||
return null; | ||
} | ||
const globalID = typeof rawID === "string" | ||
? rawID | ||
: internalEncodeGlobalID(this.builder, this.builder.configStore.getTypeConfig(rawID.type).name, String(rawID.id)); | ||
return (await resolveNodes(this.builder, context, info, [globalID]))[0]; | ||
}, | ||
const globalID = typeof rawID === "string" ? rawID : internalEncodeGlobalID(this.builder, this.builder.configStore.getTypeConfig(rawID.type).name, String(rawID.id)); | ||
return (await resolveNodes(this.builder, context, info, [ | ||
globalID | ||
]))[0]; | ||
} | ||
}); | ||
@@ -66,5 +66,7 @@ }; | ||
list: false, | ||
items: true, | ||
items: true | ||
}, | ||
type: [this.builder.nodeInterfaceRef()], | ||
type: [ | ||
this.builder.nodeInterfaceRef() | ||
], | ||
resolve: async (parent, args, context, info) => { | ||
@@ -76,8 +78,6 @@ const rawIDList = await ids(parent, args, context, info); | ||
} | ||
const rawIds = (await Promise.all(rawIDList)); | ||
const globalIds = rawIds.map((id) => !id || typeof id === "string" | ||
? id | ||
: internalEncodeGlobalID(this.builder, this.builder.configStore.getTypeConfig(id.type).name, String(id.id))); | ||
const rawIds = await Promise.all(rawIDList); | ||
const globalIds = rawIds.map((id) => !id || typeof id === "string" ? id : internalEncodeGlobalID(this.builder, this.builder.configStore.getTypeConfig(id.type).name, String(id.id))); | ||
return resolveNodes(this.builder, context, info, globalIds); | ||
}, | ||
} | ||
}); | ||
@@ -92,5 +92,5 @@ }; | ||
...fieldOptions.args, | ||
...this.arg.connectionArgs(), | ||
...this.arg.connectionArgs() | ||
}, | ||
resolve: fieldOptions.resolve, | ||
resolve: fieldOptions.resolve | ||
}); | ||
@@ -105,6 +105,6 @@ this.builder.configStore.onFieldUse(fieldRef, (fieldConfig) => { | ||
name: connectionName, | ||
...connectionOptions, | ||
...connectionOptions | ||
}, { | ||
name: edgeName, | ||
...edgeOptions, | ||
...edgeOptions | ||
}); | ||
@@ -111,0 +111,0 @@ this.builder.configStore.associateRefWithName(placeholderRef, connectionName); |
@@ -1,2 +0,2 @@ | ||
import { inputShapeKey, } from '@pothos/core'; | ||
export {}; | ||
//# sourceMappingURL=global-types.js.map |
@@ -5,3 +5,3 @@ import './global-types.js'; | ||
import './schema-builder.js'; | ||
import SchemaBuilder, { BasePlugin, createInputValueMapper, mapInputFields, } from '@pothos/core'; | ||
import SchemaBuilder, { BasePlugin, createInputValueMapper, mapInputFields } from '@pothos/core'; | ||
import { internalDecodeGlobalID } from './utils/internal.js'; | ||
@@ -15,4 +15,4 @@ export * from './types.js'; | ||
const argMappings = mapInputFields(fieldConfig.args, this.buildCache, (inputField) => { | ||
var _a; | ||
if ((_a = inputField.extensions) === null || _a === void 0 ? void 0 : _a.isRelayGlobalID) { | ||
var ref; | ||
if ((ref = inputField.extensions) === null || ref === void 0 ? void 0 : ref.isRelayGlobalID) { | ||
return true; | ||
@@ -30,4 +30,4 @@ } | ||
const argMappings = mapInputFields(fieldConfig.args, this.buildCache, (inputField) => { | ||
var _a; | ||
if ((_a = inputField.extensions) === null || _a === void 0 ? void 0 : _a.isRelayGlobalID) { | ||
var ref; | ||
if ((ref = inputField.extensions) === null || ref === void 0 ? void 0 : ref.isRelayGlobalID) { | ||
return true; | ||
@@ -34,0 +34,0 @@ } |
@@ -1,2 +0,2 @@ | ||
import { InputFieldBuilder, } from '@pothos/core'; | ||
import { InputFieldBuilder } from '@pothos/core'; | ||
const inputFieldBuilder = InputFieldBuilder.prototype; | ||
@@ -8,4 +8,4 @@ inputFieldBuilder.globalIDList = function globalIDList(options = {}) { | ||
...options.extensions, | ||
isRelayGlobalID: true, | ||
}, | ||
isRelayGlobalID: true | ||
} | ||
}); | ||
@@ -18,17 +18,30 @@ }; | ||
...options.extensions, | ||
isRelayGlobalID: true, | ||
}, | ||
isRelayGlobalID: true | ||
} | ||
}); | ||
}; | ||
inputFieldBuilder.connectionArgs = function connectionArgs() { | ||
const { | ||
// TODO(breaking) make this default match other cursor fields | ||
const { // TODO(breaking) make this default match other cursor fields | ||
cursorType = "ID", beforeArgOptions = {}, afterArgOptions = {}, firstArgOptions = {}, lastArgOptions = {}, } = this.builder.options.relayOptions; | ||
return { | ||
before: this.field({ ...beforeArgOptions, type: cursorType, required: false }), | ||
after: this.field({ ...afterArgOptions, type: cursorType, required: false }), | ||
first: this.int({ ...firstArgOptions, required: false }), | ||
last: this.int({ ...lastArgOptions, required: false }), | ||
before: this.field({ | ||
...beforeArgOptions, | ||
type: cursorType, | ||
required: false | ||
}), | ||
after: this.field({ | ||
...afterArgOptions, | ||
type: cursorType, | ||
required: false | ||
}), | ||
first: this.int({ | ||
...firstArgOptions, | ||
required: false | ||
}), | ||
last: this.int({ | ||
...lastArgOptions, | ||
required: false | ||
}) | ||
}; | ||
}; | ||
//# sourceMappingURL=input-field-builder.js.map |
@@ -1,2 +0,2 @@ | ||
import SchemaBuilder, { createContextCache, getTypeBrand, verifyRef, } from '@pothos/core'; | ||
import SchemaBuilder, { createContextCache, getTypeBrand, verifyRef } from '@pothos/core'; | ||
import { capitalize, resolveNodes } from './utils/index.js'; | ||
@@ -20,7 +20,7 @@ const schemaBuilderProto = SchemaBuilder.prototype; | ||
nullable: false, | ||
...hasNextPageFieldOptions, | ||
...hasNextPageFieldOptions | ||
}), | ||
hasPreviousPage: t.exposeBoolean("hasPreviousPage", { | ||
nullable: false, | ||
...hasPreviousPageFieldOptions, | ||
...hasPreviousPageFieldOptions | ||
}), | ||
@@ -30,3 +30,3 @@ startCursor: t.expose("startCursor", { | ||
...startCursorFieldOptions, | ||
type: cursorType, | ||
type: cursorType | ||
}), | ||
@@ -36,5 +36,5 @@ endCursor: t.expose("endCursor", { | ||
...endCursorFieldOptions, | ||
type: cursorType, | ||
}), | ||
}), | ||
type: cursorType | ||
}) | ||
}) | ||
}); | ||
@@ -56,5 +56,5 @@ return ref; | ||
throw new Error("id field not implemented"); | ||
}, | ||
}), | ||
}), | ||
} | ||
}) | ||
}) | ||
}); | ||
@@ -66,5 +66,9 @@ this.queryField("node", (t) => t.field({ | ||
args: { | ||
id: t.arg.id({ required: true }), | ||
id: t.arg.id({ | ||
required: true | ||
}) | ||
}, | ||
resolve: async (root, args, context, info) => (await resolveNodes(this, context, info, [String(args.id)]))[0], | ||
resolve: async (root, args, context, info) => (await resolveNodes(this, context, info, [ | ||
String(args.id) | ||
]))[0] | ||
})); | ||
@@ -74,10 +78,14 @@ this.queryField("nodes", (t) => t.field({ | ||
list: false, | ||
items: true, | ||
items: true | ||
}, | ||
...this.options.relayOptions.nodesQueryOptions, | ||
type: [ref], | ||
type: [ | ||
ref | ||
], | ||
args: { | ||
ids: t.arg.idList({ required: true }), | ||
ids: t.arg.idList({ | ||
required: true | ||
}) | ||
}, | ||
resolve: async (root, args, context, info) => (await resolveNodes(this, context, info, args.ids)), | ||
resolve: async (root, args, context, info) => await resolveNodes(this, context, info, args.ids) | ||
})); | ||
@@ -90,3 +98,3 @@ return ref; | ||
this.nodeInterfaceRef(), | ||
...(interfaces !== null && interfaces !== void 0 ? interfaces : []), | ||
...interfaces !== null && interfaces !== void 0 ? interfaces : [], | ||
]; | ||
@@ -136,3 +144,3 @@ let nodeName; | ||
}, | ||
interfaces: interfacesWithNode, | ||
interfaces: interfacesWithNode | ||
}, fields); | ||
@@ -148,4 +156,4 @@ this.configStore.onTypeConfig(ref, (nodeConfig) => { | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument | ||
id: await options.id.resolve(parent, args, context, info), | ||
}), | ||
id: await options.id.resolve(parent, args, context, info) | ||
}) | ||
})); | ||
@@ -156,7 +164,7 @@ }); | ||
schemaBuilderProto.globalConnectionField = function globalConnectionField(name, field) { | ||
var _a; | ||
var ref1; | ||
const onRef = (ref) => { | ||
this.objectField(ref, name, field); | ||
}; | ||
(_a = connectionRefs.get(this)) === null || _a === void 0 ? void 0 : _a.forEach((ref) => void onRef(ref)); | ||
(ref1 = connectionRefs.get(this)) === null || ref1 === void 0 ? void 0 : ref1.forEach((ref) => void onRef(ref)); | ||
if (!globalConnectionFieldsMap.has(this)) { | ||
@@ -168,7 +176,7 @@ globalConnectionFieldsMap.set(this, []); | ||
schemaBuilderProto.globalConnectionFields = function globalConnectionFields(fields) { | ||
var _a; | ||
var ref2; | ||
const onRef = (ref) => { | ||
this.objectFields(ref, fields); | ||
}; | ||
(_a = connectionRefs.get(this)) === null || _a === void 0 ? void 0 : _a.forEach((ref) => void onRef(ref)); | ||
(ref2 = connectionRefs.get(this)) === null || ref2 === void 0 ? void 0 : ref2.forEach((ref) => void onRef(ref)); | ||
if (!globalConnectionFieldsMap.has(this)) { | ||
@@ -187,11 +195,9 @@ globalConnectionFieldsMap.set(this, []); | ||
...inputFields(t), | ||
...(includeClientMutationId | ||
? { | ||
clientMutationId: t.id({ | ||
...clientMutationIdInputOptions, | ||
required: this.options.relayOptions.clientMutationId !== "optional", | ||
}), | ||
} | ||
: {}), | ||
}), | ||
...includeClientMutationId ? { | ||
clientMutationId: t.id({ | ||
...clientMutationIdInputOptions, | ||
required: this.options.relayOptions.clientMutationId !== "optional" | ||
}) | ||
} : {} | ||
}) | ||
}); | ||
@@ -203,12 +209,10 @@ const payloadRef = this.objectRef(payloadName).implement({ | ||
...outputFields(t), | ||
...(includeClientMutationId | ||
? { | ||
clientMutationId: t.id({ | ||
nullable: this.options.relayOptions.clientMutationId === "optional", | ||
...clientMutationIdFieldOptions, | ||
resolve: (parent, args, context, info) => mutationIdCache(context).get(String(info.path.prev.key)), | ||
}), | ||
} | ||
: {}), | ||
}), | ||
...includeClientMutationId ? { | ||
clientMutationId: t.id({ | ||
nullable: this.options.relayOptions.clientMutationId === "optional", | ||
...clientMutationIdFieldOptions, | ||
resolve: (parent, args, context, info) => mutationIdCache(context).get(String(info.path.prev.key)) | ||
}) | ||
} : {} | ||
}) | ||
}); | ||
@@ -219,9 +223,12 @@ this.mutationField(fieldName, (t) => t.field({ | ||
args: { | ||
[argName]: t.arg({ ...mutationInputArgOptions, type: inputRef, required: true }), | ||
[argName]: t.arg({ | ||
...mutationInputArgOptions, | ||
type: inputRef, | ||
required: true | ||
}) | ||
}, | ||
resolve: (root, args, context, info) => { | ||
mutationIdCache(context).set(String(info.path.key), args[argName] | ||
.clientMutationId); | ||
mutationIdCache(context).set(String(info.path.key), args[argName].clientMutationId); | ||
return resolve(root, args, context, info); | ||
}, | ||
} | ||
})); | ||
@@ -231,9 +238,12 @@ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions | ||
inputType: inputRef, | ||
payloadType: payloadRef, | ||
payloadType: payloadRef | ||
}; | ||
}; | ||
schemaBuilderProto.connectionObject = function connectionObject({ type, name: connectionName, edgesNullable: edgesNullableField, nodeNullable: nodeNullableField, ...connectionOptions }, { name: edgeNameFromOptions, ...edgeOptions } = {}) { | ||
var _a; | ||
var ref; | ||
verifyRef(type); | ||
const { cursorType = "String", edgesFieldOptions: { nullable: edgesNullable = { items: true, list: false }, ...edgesFieldOptions } = {}, cursorFieldOptions = {}, nodeFieldOptions: { nullable: nodeNullable = false, ...nodeFieldOptions } = {}, pageInfoFieldOptions = {}, } = this.options.relayOptions; | ||
const { cursorType = "String", edgesFieldOptions: { nullable: edgesNullable = { | ||
items: true, | ||
list: false | ||
}, ...edgesFieldOptions } = {}, cursorFieldOptions = {}, nodeFieldOptions: { nullable: nodeNullable = false, ...nodeFieldOptions } = {}, pageInfoFieldOptions = {}, } = this.options.relayOptions; | ||
const connectionRef = this.objectRef(connectionName); | ||
@@ -246,35 +256,40 @@ const edgeName = edgeNameFromOptions !== null && edgeNameFromOptions !== void 0 ? edgeNameFromOptions : `${connectionName.replace(/Connection$/, "")}Edge`; | ||
...connectionOptions, | ||
fields: (t) => ({ | ||
pageInfo: t.field({ | ||
nullable: false, | ||
...pageInfoFieldOptions, | ||
type: this.pageInfoRef(), | ||
resolve: (parent) => parent.pageInfo, | ||
}), | ||
edges: t.field({ | ||
nullable: (edgesNullableField !== null && edgesNullableField !== void 0 ? edgesNullableField : edgesNullable), | ||
...edgesFieldOptions, | ||
type: [edgeRef], | ||
resolve: (parent) => parent.edges, | ||
}), | ||
...connectionFields === null || connectionFields === void 0 ? void 0 : connectionFields(t), | ||
}), | ||
fields: (t) => { | ||
return { | ||
pageInfo: t.field({ | ||
nullable: false, | ||
...pageInfoFieldOptions, | ||
type: this.pageInfoRef(), | ||
resolve: (parent) => parent.pageInfo | ||
}), | ||
edges: t.field({ | ||
nullable: edgesNullableField !== null && edgesNullableField !== void 0 ? edgesNullableField : edgesNullable, | ||
...edgesFieldOptions, | ||
type: [ | ||
edgeRef | ||
], | ||
resolve: (parent) => parent.edges | ||
}), | ||
...connectionFields === null || connectionFields === void 0 ? void 0 : connectionFields(t) | ||
}; | ||
} | ||
}); | ||
this.objectType(edgeRef, { | ||
...edgeOptions, | ||
fields: (t) => ({ | ||
node: t.field({ | ||
nullable: nodeNullableField !== null && nodeNullableField !== void 0 ? nodeNullableField : nodeNullable, | ||
...nodeFieldOptions, | ||
type, | ||
resolve: (parent) => parent.node, | ||
}), | ||
cursor: t.expose("cursor", { | ||
nullable: false, | ||
type: cursorType, | ||
...cursorFieldOptions, | ||
}), | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument | ||
...edgeFields === null || edgeFields === void 0 ? void 0 : edgeFields(t), | ||
}), | ||
fields: (t) => { | ||
return { | ||
node: t.field({ | ||
nullable: nodeNullableField !== null && nodeNullableField !== void 0 ? nodeNullableField : nodeNullable, | ||
...nodeFieldOptions, | ||
type, | ||
resolve: (parent) => parent.node | ||
}), | ||
cursor: t.expose("cursor", { | ||
nullable: false, | ||
type: cursorType, | ||
...cursorFieldOptions | ||
}), | ||
...edgeFields === null || edgeFields === void 0 ? void 0 : edgeFields(t) | ||
}; | ||
} | ||
}); | ||
@@ -285,5 +300,5 @@ if (!connectionRefs.has(this)) { | ||
connectionRefs.get(this).push(connectionRef); | ||
(_a = globalConnectionFieldsMap.get(this)) === null || _a === void 0 ? void 0 : _a.forEach((fieldFn) => void fieldFn(connectionRef)); | ||
(ref = globalConnectionFieldsMap.get(this)) === null || ref === void 0 ? void 0 : ref.forEach((fieldFn) => void fieldFn(connectionRef)); | ||
return connectionRef; | ||
}; | ||
//# sourceMappingURL=schema-builder.js.map |
@@ -1,2 +0,2 @@ | ||
import { inputShapeKey, } from '@pothos/core'; | ||
export {}; | ||
//# sourceMappingURL=types.js.map |
@@ -5,6 +5,7 @@ const OFFSET_CURSOR_PREFIX = "OffsetConnection:"; | ||
function offsetForArgs(options) { | ||
var _a, _b; | ||
const { before, after, first, last } = options.args; | ||
const defaultSize = (_a = options.defaultSize) !== null && _a !== void 0 ? _a : DEFAULT_SIZE; | ||
const maxSize = (_b = options.maxSize) !== null && _b !== void 0 ? _b : DEFAULT_MAX_SIZE; | ||
var _defaultSize; | ||
const defaultSize = (_defaultSize = options.defaultSize) !== null && _defaultSize !== void 0 ? _defaultSize : DEFAULT_SIZE; | ||
var _maxSize; | ||
const maxSize = (_maxSize = options.maxSize) !== null && _maxSize !== void 0 ? _maxSize : DEFAULT_MAX_SIZE; | ||
const beforeOffset = before ? cursorToOffset(before) : Number.POSITIVE_INFINITY; | ||
@@ -44,3 +45,3 @@ const afterOffset = after ? cursorToOffset(after) : 0; | ||
return last == null ? resultSize >= totalSize : upperBound > endOffset; | ||
}, | ||
} | ||
}; | ||
@@ -50,12 +51,13 @@ } | ||
const { limit, offset, expectedSize, hasPreviousPage, hasNextPage } = offsetForArgs(options); | ||
const nodes = (await resolve({ offset, limit })); | ||
const nodes = await resolve({ | ||
offset, | ||
limit | ||
}); | ||
if (!nodes) { | ||
return nodes; | ||
} | ||
const edges = nodes.map((value, index) => value == null | ||
? null | ||
: { | ||
cursor: offsetToCursor(offset + index), | ||
node: value, | ||
}); | ||
const edges = nodes.map((value, index) => value == null ? null : { | ||
cursor: offsetToCursor(offset + index), | ||
node: value | ||
}); | ||
const trimmed = edges.slice(0, expectedSize); | ||
@@ -68,4 +70,4 @@ return { | ||
hasPreviousPage, | ||
hasNextPage: hasNextPage(nodes.length), | ||
}, | ||
hasNextPage: hasNextPage(nodes.length) | ||
} | ||
}; | ||
@@ -86,8 +88,6 @@ } | ||
const nodes = array.slice(offset, offset + limit); | ||
const edges = nodes.map((value, index) => value == null | ||
? null | ||
: { | ||
cursor: offsetToCursor(offset + index), | ||
node: value, | ||
}); | ||
const edges = nodes.map((value, index) => value == null ? null : { | ||
cursor: offsetToCursor(offset + index), | ||
node: value | ||
}); | ||
const trimmed = edges.slice(0, expectedSize); | ||
@@ -100,6 +100,6 @@ return { | ||
hasPreviousPage, | ||
hasNextPage: hasNextPage(nodes.length), | ||
}, | ||
hasNextPage: hasNextPage(nodes.length) | ||
} | ||
}; | ||
} | ||
//# sourceMappingURL=connections.js.map |
@@ -11,3 +11,6 @@ export * from './connections.js'; | ||
} | ||
return { typename, id }; | ||
return { | ||
typename, | ||
id | ||
}; | ||
} | ||
@@ -14,0 +17,0 @@ export function capitalize(s) { |
@@ -1,2 +0,2 @@ | ||
import { brandWithType, createContextCache, } from '@pothos/core'; | ||
import { brandWithType, createContextCache } from '@pothos/core'; | ||
import { internalDecodeGlobalID, internalEncodeGlobalID } from './internal.js'; | ||
@@ -21,8 +21,12 @@ const getRequestCache = createContextCache(() => new Map()); | ||
await Promise.all(Object.keys(idsByType).map(async (typename) => { | ||
var _a, _b; | ||
const ids = [...idsByType[typename].keys()]; | ||
const globalIds = [...idsByType[typename].values()]; | ||
const ids = [ | ||
...idsByType[typename].keys() | ||
]; | ||
const globalIds = [ | ||
...idsByType[typename].values() | ||
]; | ||
const config = builder.configStore.getTypeConfig(typename, "Object"); | ||
const options = config.pothosOptions; | ||
const shouldBrandObjects = (_b = (_a = options.brandLoadedObjects) !== null && _a !== void 0 ? _a : builder.options.relayOptions.brandLoadedObjects) !== null && _b !== void 0 ? _b : false; | ||
var _brandLoadedObjects, ref; | ||
const shouldBrandObjects = (ref = (_brandLoadedObjects = options.brandLoadedObjects) !== null && _brandLoadedObjects !== void 0 ? _brandLoadedObjects : builder.options.relayOptions.brandLoadedObjects) !== null && ref !== void 0 ? ref : false; | ||
const resultsForType = await resolveUncachedNodesForType(builder, context, info, ids, typename); | ||
@@ -36,3 +40,4 @@ resultsForType.forEach((val, i) => { | ||
})); | ||
return globalIDs.map((globalID) => { var _a; return (globalID == null ? null : (_a = results[globalID]) !== null && _a !== void 0 ? _a : null); }); | ||
var _globalID; | ||
return globalIDs.map((globalID) => globalID == null ? null : (_globalID = results[globalID]) !== null && _globalID !== void 0 ? _globalID : null); | ||
} | ||
@@ -47,5 +52,3 @@ export async function resolveUncachedNodesForType(builder, context, info, ids, type) { | ||
const globalID = internalEncodeGlobalID(builder, config.name, id); | ||
const entryPromise = loadManyPromise | ||
.then((results) => results[i]) | ||
.then((result) => { | ||
const entryPromise = loadManyPromise.then((results) => results[i]).then((result) => { | ||
requestCache.set(globalID, result); | ||
@@ -52,0 +55,0 @@ return result; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const core_1 = require("@pothos/core"); | ||
const utils_1 = require("./utils"); | ||
const internal_1 = require("./utils/internal"); | ||
const fieldBuilderProto = core_1.RootFieldBuilder.prototype; | ||
fieldBuilderProto.globalIDList = function globalIDList({ resolve, ...options }) { | ||
const wrappedResolve = async (parent, args, context, info) => { | ||
var _core = require("@pothos/core"); | ||
var _utils = require("./utils"); | ||
var _internal = require("./utils/internal"); | ||
const fieldBuilderProto = _core.RootFieldBuilder.prototype; | ||
fieldBuilderProto.globalIDList = function globalIDList({ resolve , ...options }) { | ||
const wrappedResolve = async (parent, args, context, info)=>{ | ||
const result = await resolve(parent, args, context, info); | ||
@@ -13,7 +12,6 @@ if (!result) { | ||
} | ||
(0, core_1.assertArray)(result); | ||
(0, _core).assertArray(result); | ||
if (Array.isArray(result)) { | ||
return (await Promise.all(result)).map((item) => item == null || typeof item === 'string' | ||
? item | ||
: (0, internal_1.internalEncodeGlobalID)(this.builder, this.builder.configStore.getTypeConfig(item.type).name, String(item.id))); | ||
return (await Promise.all(result)).map((item)=>item == null || typeof item === 'string' ? item : (0, _internal).internalEncodeGlobalID(this.builder, this.builder.configStore.getTypeConfig(item.type).name, String(item.id)) | ||
); | ||
} | ||
@@ -24,8 +22,10 @@ return null; | ||
...options, | ||
type: ['ID'], | ||
resolve: wrappedResolve, // resolve is not expected because we don't know FieldKind | ||
type: [ | ||
'ID' | ||
], | ||
resolve: wrappedResolve | ||
}); | ||
}; | ||
fieldBuilderProto.globalID = function globalID({ resolve, ...options }) { | ||
const wrappedResolve = async (parent, args, context, info) => { | ||
fieldBuilderProto.globalID = function globalID({ resolve , ...options }) { | ||
const wrappedResolve = async (parent, args, context, info)=>{ | ||
const result = await resolve(parent, args, context, info); | ||
@@ -36,3 +36,3 @@ if (!result || typeof result === 'string') { | ||
const item = result; | ||
return (0, internal_1.internalEncodeGlobalID)(this.builder, this.builder.configStore.getTypeConfig(item.type).name, String(item.id)); | ||
return (0, _internal).internalEncodeGlobalID(this.builder, this.builder.configStore.getTypeConfig(item.type).name, String(item.id)); | ||
}; | ||
@@ -42,6 +42,6 @@ return this.field({ | ||
type: 'ID', | ||
resolve: wrappedResolve, // resolve is not expected because we don't know FieldKind | ||
resolve: wrappedResolve | ||
}); | ||
}; | ||
fieldBuilderProto.node = function node({ id, ...options }) { | ||
fieldBuilderProto.node = function node({ id , ...options }) { | ||
return this.field({ | ||
@@ -51,15 +51,15 @@ ...options, | ||
nullable: true, | ||
resolve: async (parent, args, context, info) => { | ||
const rawID = (await id(parent, args, context, info)); | ||
resolve: async (parent, args, context, info)=>{ | ||
const rawID = await id(parent, args, context, info); | ||
if (rawID == null) { | ||
return null; | ||
} | ||
const globalID = typeof rawID === 'string' | ||
? rawID | ||
: (0, internal_1.internalEncodeGlobalID)(this.builder, this.builder.configStore.getTypeConfig(rawID.type).name, String(rawID.id)); | ||
return (await (0, utils_1.resolveNodes)(this.builder, context, info, [globalID]))[0]; | ||
}, | ||
const globalID = typeof rawID === 'string' ? rawID : (0, _internal).internalEncodeGlobalID(this.builder, this.builder.configStore.getTypeConfig(rawID.type).name, String(rawID.id)); | ||
return (await (0, _utils).resolveNodes(this.builder, context, info, [ | ||
globalID | ||
]))[0]; | ||
} | ||
}); | ||
}; | ||
fieldBuilderProto.nodeList = function nodeList({ ids, ...options }) { | ||
fieldBuilderProto.nodeList = function nodeList({ ids , ...options }) { | ||
return this.field({ | ||
@@ -69,20 +69,21 @@ ...options, | ||
list: false, | ||
items: true, | ||
items: true | ||
}, | ||
type: [this.builder.nodeInterfaceRef()], | ||
resolve: async (parent, args, context, info) => { | ||
type: [ | ||
this.builder.nodeInterfaceRef() | ||
], | ||
resolve: async (parent, args, context, info)=>{ | ||
const rawIDList = await ids(parent, args, context, info); | ||
(0, core_1.assertArray)(rawIDList); | ||
(0, _core).assertArray(rawIDList); | ||
if (!Array.isArray(rawIDList)) { | ||
return []; | ||
} | ||
const rawIds = (await Promise.all(rawIDList)); | ||
const globalIds = rawIds.map((id) => !id || typeof id === 'string' | ||
? id | ||
: (0, internal_1.internalEncodeGlobalID)(this.builder, this.builder.configStore.getTypeConfig(id.type).name, String(id.id))); | ||
return (0, utils_1.resolveNodes)(this.builder, context, info, globalIds); | ||
}, | ||
const rawIds = await Promise.all(rawIDList); | ||
const globalIds = rawIds.map((id)=>!id || typeof id === 'string' ? id : (0, _internal).internalEncodeGlobalID(this.builder, this.builder.configStore.getTypeConfig(id.type).name, String(id.id)) | ||
); | ||
return (0, _utils).resolveNodes(this.builder, context, info, globalIds); | ||
} | ||
}); | ||
}; | ||
fieldBuilderProto.connection = function connection({ type, edgesNullable, nodeNullable, ...fieldOptions }, { name: connectionNameFromOptions, ...connectionOptions } = {}, { name: edgeNameFromOptions, ...edgeOptions } = {}) { | ||
fieldBuilderProto.connection = function connection({ type , edgesNullable , nodeNullable , ...fieldOptions }, { name: connectionNameFromOptions , ...connectionOptions } = {}, { name: edgeNameFromOptions , ...edgeOptions } = {}) { | ||
const placeholderRef = this.builder.objectRef('Unnamed connection'); | ||
@@ -94,8 +95,8 @@ const fieldRef = this.field({ | ||
...fieldOptions.args, | ||
...this.arg.connectionArgs(), | ||
...this.arg.connectionArgs() | ||
}, | ||
resolve: fieldOptions.resolve, | ||
resolve: fieldOptions.resolve | ||
}); | ||
this.builder.configStore.onFieldUse(fieldRef, (fieldConfig) => { | ||
const connectionName = connectionNameFromOptions !== null && connectionNameFromOptions !== void 0 ? connectionNameFromOptions : `${this.typename}${(0, utils_1.capitalize)(fieldConfig.name)}${fieldConfig.name.toLowerCase().endsWith('connection') ? '' : 'Connection'}`; | ||
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`; | ||
@@ -107,6 +108,6 @@ this.builder.connectionObject({ | ||
name: connectionName, | ||
...connectionOptions, | ||
...connectionOptions | ||
}, { | ||
name: edgeName, | ||
...edgeOptions, | ||
...edgeOptions | ||
}); | ||
@@ -117,2 +118,3 @@ this.builder.configStore.associateRefWithName(placeholderRef, connectionName); | ||
}; | ||
//# sourceMappingURL=field-builder.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const core_1 = require("@pothos/core"); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
//# sourceMappingURL=global-types.js.map |
122
lib/index.js
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
}) : function(o, v) { | ||
o["default"] = v; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
var _exportNames = { | ||
PothosRelayPlugin: true, | ||
resolver: true, | ||
fieldConfig: true, | ||
argMappings: true, | ||
argMapper: true, | ||
subscribe: true, | ||
fieldConfig: true, | ||
argMappings: true, | ||
argMapper: true | ||
}; | ||
var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.PothosRelayPlugin = void 0; | ||
exports.default = void 0; | ||
require("./global-types"); | ||
@@ -34,13 +21,57 @@ require("./field-builder"); | ||
require("./schema-builder"); | ||
const core_1 = __importStar(require("@pothos/core")); | ||
const internal_1 = require("./utils/internal"); | ||
__exportStar(require("./types"), exports); | ||
__exportStar(require("./utils"), exports); | ||
var _core = _interopRequireWildcard(require("@pothos/core")); | ||
var _internal = require("./utils/internal"); | ||
var _types = _interopRequireWildcard(require("./types")); | ||
Object.keys(_types).forEach(function(key) { | ||
if (key === "default" || key === "__esModule") return; | ||
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return; | ||
if (key in exports && exports[key] === _types[key]) return; | ||
Object.defineProperty(exports, key, { | ||
enumerable: true, | ||
get: function() { | ||
return _types[key]; | ||
} | ||
}); | ||
}); | ||
var _utils = _interopRequireWildcard(require("./utils")); | ||
Object.keys(_utils).forEach(function(key) { | ||
if (key === "default" || key === "__esModule") return; | ||
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return; | ||
if (key in exports && exports[key] === _utils[key]) return; | ||
Object.defineProperty(exports, key, { | ||
enumerable: true, | ||
get: function() { | ||
return _utils[key]; | ||
} | ||
}); | ||
}); | ||
function _interopRequireWildcard(obj) { | ||
if (obj && obj.__esModule) { | ||
return obj; | ||
} else { | ||
var newObj = {}; | ||
if (obj != null) { | ||
for(var key in obj){ | ||
if (Object.prototype.hasOwnProperty.call(obj, key)) { | ||
var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; | ||
if (desc.get || desc.set) { | ||
Object.defineProperty(newObj, key, desc); | ||
} else { | ||
newObj[key] = obj[key]; | ||
} | ||
} | ||
} | ||
} | ||
newObj.default = obj; | ||
return newObj; | ||
} | ||
} | ||
const pluginName = 'relay'; | ||
exports.default = pluginName; | ||
class PothosRelayPlugin extends core_1.BasePlugin { | ||
var _default = pluginName; | ||
exports.default = _default; | ||
class PothosRelayPlugin extends _core.BasePlugin { | ||
wrapResolve(resolver, fieldConfig) { | ||
const argMappings = (0, core_1.mapInputFields)(fieldConfig.args, this.buildCache, (inputField) => { | ||
var _a; | ||
if ((_a = inputField.extensions) === null || _a === void 0 ? void 0 : _a.isRelayGlobalID) { | ||
const argMappings = (0, _core).mapInputFields(fieldConfig.args, this.buildCache, (inputField)=>{ | ||
var ref; | ||
if ((ref = inputField.extensions) === null || ref === void 0 ? void 0 : ref.isRelayGlobalID) { | ||
return true; | ||
@@ -53,9 +84,11 @@ } | ||
} | ||
const argMapper = (0, core_1.createInputValueMapper)(argMappings, (globalID) => (0, internal_1.internalDecodeGlobalID)(this.builder, String(globalID))); | ||
return (parent, args, context, info) => resolver(parent, argMapper(args), context, info); | ||
const argMapper = (0, _core).createInputValueMapper(argMappings, (globalID)=>(0, _internal).internalDecodeGlobalID(this.builder, String(globalID)) | ||
); | ||
return (parent, args, context, info)=>resolver(parent, argMapper(args), context, info) | ||
; | ||
} | ||
wrapSubscribe(subscribe, fieldConfig) { | ||
const argMappings = (0, core_1.mapInputFields)(fieldConfig.args, this.buildCache, (inputField) => { | ||
var _a; | ||
if ((_a = inputField.extensions) === null || _a === void 0 ? void 0 : _a.isRelayGlobalID) { | ||
const argMappings = (0, _core).mapInputFields(fieldConfig.args, this.buildCache, (inputField)=>{ | ||
var ref; | ||
if ((ref = inputField.extensions) === null || ref === void 0 ? void 0 : ref.isRelayGlobalID) { | ||
return true; | ||
@@ -68,8 +101,11 @@ } | ||
} | ||
const argMapper = (0, core_1.createInputValueMapper)(argMappings, (globalID) => (0, internal_1.internalDecodeGlobalID)(this.builder, String(globalID))); | ||
return (parent, args, context, info) => subscribe(parent, argMapper(args), context, info); | ||
const argMapper = (0, _core).createInputValueMapper(argMappings, (globalID)=>(0, _internal).internalDecodeGlobalID(this.builder, String(globalID)) | ||
); | ||
return (parent, args, context, info)=>subscribe(parent, argMapper(args), context, info) | ||
; | ||
} | ||
} | ||
exports.PothosRelayPlugin = PothosRelayPlugin; | ||
core_1.default.registerPlugin(pluginName, PothosRelayPlugin); | ||
_core.default.registerPlugin(pluginName, PothosRelayPlugin); | ||
//# sourceMappingURL=index.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const core_1 = require("@pothos/core"); | ||
const inputFieldBuilder = core_1.InputFieldBuilder.prototype; | ||
var _core = require("@pothos/core"); | ||
const inputFieldBuilder = _core.InputFieldBuilder.prototype; | ||
inputFieldBuilder.globalIDList = function globalIDList(options = {}) { | ||
@@ -10,4 +9,4 @@ return this.idList({ | ||
...options.extensions, | ||
isRelayGlobalID: true, | ||
}, | ||
isRelayGlobalID: true | ||
} | ||
}); | ||
@@ -20,17 +19,31 @@ }; | ||
...options.extensions, | ||
isRelayGlobalID: true, | ||
}, | ||
isRelayGlobalID: true | ||
} | ||
}); | ||
}; | ||
inputFieldBuilder.connectionArgs = function connectionArgs() { | ||
const { | ||
// TODO(breaking) make this default match other cursor fields | ||
cursorType = 'ID', beforeArgOptions = {}, afterArgOptions = {}, firstArgOptions = {}, lastArgOptions = {}, } = this.builder.options.relayOptions; | ||
const { // TODO(breaking) make this default match other cursor fields | ||
cursorType ='ID' , beforeArgOptions ={} , afterArgOptions ={} , firstArgOptions ={} , lastArgOptions ={} , } = this.builder.options.relayOptions; | ||
return { | ||
before: this.field({ ...beforeArgOptions, type: cursorType, required: false }), | ||
after: this.field({ ...afterArgOptions, type: cursorType, required: false }), | ||
first: this.int({ ...firstArgOptions, required: false }), | ||
last: this.int({ ...lastArgOptions, required: false }), | ||
before: this.field({ | ||
...beforeArgOptions, | ||
type: cursorType, | ||
required: false | ||
}), | ||
after: this.field({ | ||
...afterArgOptions, | ||
type: cursorType, | ||
required: false | ||
}), | ||
first: this.int({ | ||
...firstArgOptions, | ||
required: false | ||
}), | ||
last: this.int({ | ||
...lastArgOptions, | ||
required: false | ||
}) | ||
}; | ||
}; | ||
//# sourceMappingURL=input-field-builder.js.map |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
}) : function(o, v) { | ||
o["default"] = v; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.globalConnectionFieldsMap = exports.connectionRefs = void 0; | ||
const core_1 = __importStar(require("@pothos/core")); | ||
const utils_1 = require("./utils"); | ||
const schemaBuilderProto = core_1.default.prototype; | ||
var _core = _interopRequireWildcard(require("@pothos/core")); | ||
var _utils = require("./utils"); | ||
function _interopRequireWildcard(obj) { | ||
if (obj && obj.__esModule) { | ||
return obj; | ||
} else { | ||
var newObj = {}; | ||
if (obj != null) { | ||
for(var key in obj){ | ||
if (Object.prototype.hasOwnProperty.call(obj, key)) { | ||
var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; | ||
if (desc.get || desc.set) { | ||
Object.defineProperty(newObj, key, desc); | ||
} else { | ||
newObj[key] = obj[key]; | ||
} | ||
} | ||
} | ||
} | ||
newObj.default = obj; | ||
return newObj; | ||
} | ||
} | ||
const schemaBuilderProto = _core.default.prototype; | ||
const pageInfoRefMap = new WeakMap(); | ||
const nodeInterfaceRefMap = new WeakMap(); | ||
exports.connectionRefs = new WeakMap(); | ||
exports.globalConnectionFieldsMap = new WeakMap(); | ||
const connectionRefs = new WeakMap(); | ||
exports.connectionRefs = connectionRefs; | ||
const globalConnectionFieldsMap = new WeakMap(); | ||
exports.globalConnectionFieldsMap = globalConnectionFieldsMap; | ||
schemaBuilderProto.pageInfoRef = function pageInfoRef() { | ||
@@ -40,25 +42,25 @@ if (pageInfoRefMap.has(this)) { | ||
pageInfoRefMap.set(this, ref); | ||
const { cursorType = 'String', hasNextPageFieldOptions = {}, hasPreviousPageFieldOptions = {}, startCursorFieldOptions = {}, endCursorFieldOptions = {}, } = this.options.relayOptions; | ||
const { cursorType ='String' , hasNextPageFieldOptions ={} , hasPreviousPageFieldOptions ={} , startCursorFieldOptions ={} , endCursorFieldOptions ={} , } = this.options.relayOptions; | ||
ref.implement({ | ||
...this.options.relayOptions.pageInfoTypeOptions, | ||
fields: (t) => ({ | ||
hasNextPage: t.exposeBoolean('hasNextPage', { | ||
nullable: false, | ||
...hasNextPageFieldOptions, | ||
}), | ||
hasPreviousPage: t.exposeBoolean('hasPreviousPage', { | ||
nullable: false, | ||
...hasPreviousPageFieldOptions, | ||
}), | ||
startCursor: t.expose('startCursor', { | ||
nullable: true, | ||
...startCursorFieldOptions, | ||
type: cursorType, | ||
}), | ||
endCursor: t.expose('endCursor', { | ||
nullable: true, | ||
...endCursorFieldOptions, | ||
type: cursorType, | ||
}), | ||
}), | ||
fields: (t)=>({ | ||
hasNextPage: t.exposeBoolean('hasNextPage', { | ||
nullable: false, | ||
...hasNextPageFieldOptions | ||
}), | ||
hasPreviousPage: t.exposeBoolean('hasPreviousPage', { | ||
nullable: false, | ||
...hasPreviousPageFieldOptions | ||
}), | ||
startCursor: t.expose('startCursor', { | ||
nullable: true, | ||
...startCursorFieldOptions, | ||
type: cursorType | ||
}), | ||
endCursor: t.expose('endCursor', { | ||
nullable: true, | ||
...endCursorFieldOptions, | ||
type: cursorType | ||
}) | ||
}) | ||
}); | ||
@@ -75,39 +77,49 @@ return ref; | ||
...this.options.relayOptions.nodeTypeOptions, | ||
fields: (t) => ({ | ||
id: t.globalID({ | ||
nullable: false, | ||
resolve: (parent) => { | ||
throw new Error('id field not implemented'); | ||
}, | ||
}), | ||
}), | ||
fields: (t)=>({ | ||
id: t.globalID({ | ||
nullable: false, | ||
resolve: (parent)=>{ | ||
throw new Error('id field not implemented'); | ||
} | ||
}) | ||
}) | ||
}); | ||
this.queryField('node', (t) => t.field({ | ||
nullable: true, | ||
...this.options.relayOptions.nodeQueryOptions, | ||
type: ref, | ||
args: { | ||
id: t.arg.id({ required: true }), | ||
}, | ||
resolve: async (root, args, context, info) => (await (0, utils_1.resolveNodes)(this, context, info, [String(args.id)]))[0], | ||
})); | ||
this.queryField('nodes', (t) => t.field({ | ||
nullable: { | ||
list: false, | ||
items: true, | ||
}, | ||
...this.options.relayOptions.nodesQueryOptions, | ||
type: [ref], | ||
args: { | ||
ids: t.arg.idList({ required: true }), | ||
}, | ||
resolve: async (root, args, context, info) => (await (0, utils_1.resolveNodes)(this, context, info, args.ids)), | ||
})); | ||
this.queryField('node', (t)=>t.field({ | ||
nullable: true, | ||
...this.options.relayOptions.nodeQueryOptions, | ||
type: ref, | ||
args: { | ||
id: t.arg.id({ | ||
required: true | ||
}) | ||
}, | ||
resolve: async (root, args, context, info)=>(await (0, _utils).resolveNodes(this, context, info, [ | ||
String(args.id) | ||
]))[0] | ||
}) | ||
); | ||
this.queryField('nodes', (t)=>t.field({ | ||
nullable: { | ||
list: false, | ||
items: true | ||
}, | ||
...this.options.relayOptions.nodesQueryOptions, | ||
type: [ | ||
ref | ||
], | ||
args: { | ||
ids: t.arg.idList({ | ||
required: true | ||
}) | ||
}, | ||
resolve: async (root, args, context, info)=>await (0, _utils).resolveNodes(this, context, info, args.ids) | ||
}) | ||
); | ||
return ref; | ||
}; | ||
schemaBuilderProto.node = function node(param, { interfaces, ...options }, fields) { | ||
(0, core_1.verifyRef)(param); | ||
schemaBuilderProto.node = function node(param, { interfaces , ...options }, fields) { | ||
(0, _core).verifyRef(param); | ||
const interfacesWithNode = [ | ||
this.nodeInterfaceRef(), | ||
...(interfaces !== null && interfaces !== void 0 ? interfaces : []), | ||
...interfaces !== null && interfaces !== void 0 ? interfaces : [], | ||
]; | ||
@@ -117,3 +129,3 @@ let nodeName; | ||
...options, | ||
isTypeOf: (maybeNode, context, info) => { | ||
isTypeOf: (maybeNode, context, info)=>{ | ||
if (options.isTypeOf) { | ||
@@ -125,3 +137,3 @@ return options.isTypeOf(maybeNode, context, info); | ||
} | ||
const typeBrand = (0, core_1.getTypeBrand)(maybeNode); | ||
const typeBrand = (0, _core).getTypeBrand(maybeNode); | ||
if (typeBrand && this.configStore.getTypeConfig(typeBrand).name === nodeName) { | ||
@@ -153,22 +165,22 @@ return true; | ||
} | ||
} catch { | ||
// ignore | ||
} | ||
catch { | ||
// ignore | ||
} | ||
return false; | ||
}, | ||
interfaces: interfacesWithNode, | ||
interfaces: interfacesWithNode | ||
}, fields); | ||
this.configStore.onTypeConfig(ref, (nodeConfig) => { | ||
this.configStore.onTypeConfig(ref, (nodeConfig)=>{ | ||
nodeName = nodeConfig.name; | ||
this.objectField(ref, 'id', (t) => t.globalID({ | ||
nullable: false, | ||
...options.id, | ||
args: {}, | ||
resolve: async (parent, args, context, info) => ({ | ||
type: nodeConfig.name, | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument | ||
id: await options.id.resolve(parent, args, context, info), | ||
}), | ||
})); | ||
this.objectField(ref, 'id', (t)=>t.globalID({ | ||
nullable: false, | ||
...options.id, | ||
args: {}, | ||
resolve: async (parent, args, context, info)=>({ | ||
type: nodeConfig.name, | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument | ||
id: await options.id.resolve(parent, args, context, info) | ||
}) | ||
}) | ||
); | ||
}); | ||
@@ -178,40 +190,41 @@ return ref; | ||
schemaBuilderProto.globalConnectionField = function globalConnectionField(name, field) { | ||
var _a; | ||
const onRef = (ref) => { | ||
var ref1; | ||
const onRef = (ref)=>{ | ||
this.objectField(ref, name, field); | ||
}; | ||
(_a = exports.connectionRefs.get(this)) === null || _a === void 0 ? void 0 : _a.forEach((ref) => void onRef(ref)); | ||
if (!exports.globalConnectionFieldsMap.has(this)) { | ||
exports.globalConnectionFieldsMap.set(this, []); | ||
(ref1 = connectionRefs.get(this)) === null || ref1 === void 0 ? void 0 : ref1.forEach((ref)=>void onRef(ref) | ||
); | ||
if (!globalConnectionFieldsMap.has(this)) { | ||
globalConnectionFieldsMap.set(this, []); | ||
} | ||
exports.globalConnectionFieldsMap.get(this).push(onRef); | ||
globalConnectionFieldsMap.get(this).push(onRef); | ||
}; | ||
schemaBuilderProto.globalConnectionFields = function globalConnectionFields(fields) { | ||
var _a; | ||
const onRef = (ref) => { | ||
var ref2; | ||
const onRef = (ref)=>{ | ||
this.objectFields(ref, fields); | ||
}; | ||
(_a = exports.connectionRefs.get(this)) === null || _a === void 0 ? void 0 : _a.forEach((ref) => void onRef(ref)); | ||
if (!exports.globalConnectionFieldsMap.has(this)) { | ||
exports.globalConnectionFieldsMap.set(this, []); | ||
(ref2 = connectionRefs.get(this)) === null || ref2 === void 0 ? void 0 : ref2.forEach((ref)=>void onRef(ref) | ||
); | ||
if (!globalConnectionFieldsMap.has(this)) { | ||
globalConnectionFieldsMap.set(this, []); | ||
} | ||
exports.globalConnectionFieldsMap.get(this).push(onRef); | ||
globalConnectionFieldsMap.get(this).push(onRef); | ||
}; | ||
const mutationIdCache = (0, core_1.createContextCache)(() => new Map()); | ||
schemaBuilderProto.relayMutationField = function relayMutationField(fieldName, { name: inputName = `${(0, utils_1.capitalize)(fieldName)}Input`, argName = 'input', inputFields, ...inputOptions }, { resolve, ...fieldOptions }, { name: payloadName = `${(0, utils_1.capitalize)(fieldName)}Payload`, outputFields, interfaces, ...paylaodOptions }) { | ||
const { relayOptions: { clientMutationIdInputOptions = {}, clientMutationIdFieldOptions = {}, mutationInputArgOptions = {}, }, } = this.options; | ||
const mutationIdCache = (0, _core).createContextCache(()=>new Map() | ||
); | ||
schemaBuilderProto.relayMutationField = function relayMutationField(fieldName, { name: inputName = `${(0, _utils).capitalize(fieldName)}Input` , argName ='input' , inputFields , ...inputOptions }, { resolve , ...fieldOptions }, { name: payloadName = `${(0, _utils).capitalize(fieldName)}Payload` , outputFields , interfaces , ...paylaodOptions }) { | ||
const { relayOptions: { clientMutationIdInputOptions ={} , clientMutationIdFieldOptions ={} , mutationInputArgOptions ={} , } , } = this.options; | ||
const includeClientMutationId = this.options.relayOptions.clientMutationId !== 'omit'; | ||
const inputRef = this.inputType(inputName, { | ||
...inputOptions, | ||
fields: (t) => ({ | ||
...inputFields(t), | ||
...(includeClientMutationId | ||
? { | ||
fields: (t)=>({ | ||
...inputFields(t), | ||
...includeClientMutationId ? { | ||
clientMutationId: t.id({ | ||
...clientMutationIdInputOptions, | ||
required: this.options.relayOptions.clientMutationId !== 'optional', | ||
}), | ||
} | ||
: {}), | ||
}), | ||
required: this.options.relayOptions.clientMutationId !== 'optional' | ||
}) | ||
} : {} | ||
}) | ||
}); | ||
@@ -221,37 +234,42 @@ const payloadRef = this.objectRef(payloadName).implement({ | ||
interfaces: interfaces, | ||
fields: (t) => ({ | ||
...outputFields(t), | ||
...(includeClientMutationId | ||
? { | ||
fields: (t)=>({ | ||
...outputFields(t), | ||
...includeClientMutationId ? { | ||
clientMutationId: t.id({ | ||
nullable: this.options.relayOptions.clientMutationId === 'optional', | ||
...clientMutationIdFieldOptions, | ||
resolve: (parent, args, context, info) => mutationIdCache(context).get(String(info.path.prev.key)), | ||
}), | ||
} | ||
: {}), | ||
}), | ||
resolve: (parent, args, context, info)=>mutationIdCache(context).get(String(info.path.prev.key)) | ||
}) | ||
} : {} | ||
}) | ||
}); | ||
this.mutationField(fieldName, (t) => t.field({ | ||
...fieldOptions, | ||
type: payloadRef, | ||
args: { | ||
[argName]: t.arg({ ...mutationInputArgOptions, type: inputRef, required: true }), | ||
}, | ||
resolve: (root, args, context, info) => { | ||
mutationIdCache(context).set(String(info.path.key), args[argName] | ||
.clientMutationId); | ||
return resolve(root, args, context, info); | ||
}, | ||
})); | ||
this.mutationField(fieldName, (t)=>t.field({ | ||
...fieldOptions, | ||
type: payloadRef, | ||
args: { | ||
[argName]: t.arg({ | ||
...mutationInputArgOptions, | ||
type: inputRef, | ||
required: true | ||
}) | ||
}, | ||
resolve: (root, args, context, info)=>{ | ||
mutationIdCache(context).set(String(info.path.key), args[argName].clientMutationId); | ||
return resolve(root, args, context, info); | ||
} | ||
}) | ||
); | ||
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions | ||
return { | ||
inputType: inputRef, | ||
payloadType: payloadRef, | ||
payloadType: payloadRef | ||
}; | ||
}; | ||
schemaBuilderProto.connectionObject = function connectionObject({ type, name: connectionName, edgesNullable: edgesNullableField, nodeNullable: nodeNullableField, ...connectionOptions }, { name: edgeNameFromOptions, ...edgeOptions } = {}) { | ||
var _a; | ||
(0, core_1.verifyRef)(type); | ||
const { cursorType = 'String', edgesFieldOptions: { nullable: edgesNullable = { items: true, list: false }, ...edgesFieldOptions } = {}, cursorFieldOptions = {}, nodeFieldOptions: { nullable: nodeNullable = false, ...nodeFieldOptions } = {}, pageInfoFieldOptions = {}, } = this.options.relayOptions; | ||
schemaBuilderProto.connectionObject = function connectionObject({ type , name: connectionName , edgesNullable: edgesNullableField , nodeNullable: nodeNullableField , ...connectionOptions }, { name: edgeNameFromOptions , ...edgeOptions } = {}) { | ||
var ref; | ||
(0, _core).verifyRef(type); | ||
const { cursorType ='String' , edgesFieldOptions: { nullable: edgesNullable = { | ||
items: true, | ||
list: false | ||
} , ...edgesFieldOptions } = {} , cursorFieldOptions ={} , nodeFieldOptions: { nullable: nodeNullable = false , ...nodeFieldOptions } = {} , pageInfoFieldOptions ={} , } = this.options.relayOptions; | ||
const connectionRef = this.objectRef(connectionName); | ||
@@ -264,43 +282,50 @@ const edgeName = edgeNameFromOptions !== null && edgeNameFromOptions !== void 0 ? edgeNameFromOptions : `${connectionName.replace(/Connection$/, '')}Edge`; | ||
...connectionOptions, | ||
fields: (t) => ({ | ||
pageInfo: t.field({ | ||
nullable: false, | ||
...pageInfoFieldOptions, | ||
type: this.pageInfoRef(), | ||
resolve: (parent) => parent.pageInfo, | ||
}), | ||
edges: t.field({ | ||
nullable: (edgesNullableField !== null && edgesNullableField !== void 0 ? edgesNullableField : edgesNullable), | ||
...edgesFieldOptions, | ||
type: [edgeRef], | ||
resolve: (parent) => parent.edges, | ||
}), | ||
...connectionFields === null || connectionFields === void 0 ? void 0 : connectionFields(t), | ||
}), | ||
fields: (t)=>{ | ||
return { | ||
pageInfo: t.field({ | ||
nullable: false, | ||
...pageInfoFieldOptions, | ||
type: this.pageInfoRef(), | ||
resolve: (parent)=>parent.pageInfo | ||
}), | ||
edges: t.field({ | ||
nullable: edgesNullableField !== null && edgesNullableField !== void 0 ? edgesNullableField : edgesNullable, | ||
...edgesFieldOptions, | ||
type: [ | ||
edgeRef | ||
], | ||
resolve: (parent)=>parent.edges | ||
}), | ||
...connectionFields === null || connectionFields === void 0 ? void 0 : connectionFields(t) | ||
}; | ||
} | ||
}); | ||
this.objectType(edgeRef, { | ||
...edgeOptions, | ||
fields: (t) => ({ | ||
node: t.field({ | ||
nullable: nodeNullableField !== null && nodeNullableField !== void 0 ? nodeNullableField : nodeNullable, | ||
...nodeFieldOptions, | ||
type, | ||
resolve: (parent) => parent.node, | ||
}), | ||
cursor: t.expose('cursor', { | ||
nullable: false, | ||
type: cursorType, | ||
...cursorFieldOptions, | ||
}), | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument | ||
...edgeFields === null || edgeFields === void 0 ? void 0 : edgeFields(t), | ||
}), | ||
fields: (t)=>{ | ||
return { | ||
node: t.field({ | ||
nullable: nodeNullableField !== null && nodeNullableField !== void 0 ? nodeNullableField : nodeNullable, | ||
...nodeFieldOptions, | ||
type, | ||
resolve: (parent)=>parent.node | ||
}), | ||
cursor: t.expose('cursor', { | ||
nullable: false, | ||
type: cursorType, | ||
...cursorFieldOptions | ||
}), | ||
...edgeFields === null || edgeFields === void 0 ? void 0 : edgeFields(t) | ||
}; | ||
} | ||
}); | ||
if (!exports.connectionRefs.has(this)) { | ||
exports.connectionRefs.set(this, []); | ||
if (!connectionRefs.has(this)) { | ||
connectionRefs.set(this, []); | ||
} | ||
exports.connectionRefs.get(this).push(connectionRef); | ||
(_a = exports.globalConnectionFieldsMap.get(this)) === null || _a === void 0 ? void 0 : _a.forEach((fieldFn) => void fieldFn(connectionRef)); | ||
connectionRefs.get(this).push(connectionRef); | ||
(ref = globalConnectionFieldsMap.get(this)) === null || ref === void 0 ? void 0 : ref.forEach((fieldFn)=>void fieldFn(connectionRef) | ||
); | ||
return connectionRef; | ||
}; | ||
//# sourceMappingURL=schema-builder.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const core_1 = require("@pothos/core"); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
//# sourceMappingURL=types.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.resolveArrayConnection = exports.offsetToCursor = exports.cursorToOffset = exports.resolveOffsetConnection = void 0; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.resolveOffsetConnection = resolveOffsetConnection; | ||
exports.cursorToOffset = cursorToOffset; | ||
exports.offsetToCursor = offsetToCursor; | ||
exports.resolveArrayConnection = resolveArrayConnection; | ||
const OFFSET_CURSOR_PREFIX = 'OffsetConnection:'; | ||
@@ -8,6 +13,7 @@ const DEFAULT_MAX_SIZE = 100; | ||
function offsetForArgs(options) { | ||
var _a, _b; | ||
const { before, after, first, last } = options.args; | ||
const defaultSize = (_a = options.defaultSize) !== null && _a !== void 0 ? _a : DEFAULT_SIZE; | ||
const maxSize = (_b = options.maxSize) !== null && _b !== void 0 ? _b : DEFAULT_MAX_SIZE; | ||
const { before , after , first , last } = options.args; | ||
var _defaultSize; | ||
const defaultSize = (_defaultSize = options.defaultSize) !== null && _defaultSize !== void 0 ? _defaultSize : DEFAULT_SIZE; | ||
var _maxSize; | ||
const maxSize = (_maxSize = options.maxSize) !== null && _maxSize !== void 0 ? _maxSize : DEFAULT_MAX_SIZE; | ||
const beforeOffset = before ? cursorToOffset(before) : Number.POSITIVE_INFINITY; | ||
@@ -44,20 +50,22 @@ const afterOffset = after ? cursorToOffset(after) : 0; | ||
expectedSize: totalSize - 1, | ||
hasNextPage: (resultSize) => { | ||
hasNextPage: (resultSize)=>{ | ||
const upperBound = before == null ? startOffset + resultSize : beforeOffset; | ||
return last == null ? resultSize >= totalSize : upperBound > endOffset; | ||
}, | ||
} | ||
}; | ||
} | ||
async function resolveOffsetConnection(options, resolve) { | ||
const { limit, offset, expectedSize, hasPreviousPage, hasNextPage } = offsetForArgs(options); | ||
const nodes = (await resolve({ offset, limit })); | ||
const { limit , offset , expectedSize , hasPreviousPage , hasNextPage } = offsetForArgs(options); | ||
const nodes = await resolve({ | ||
offset, | ||
limit | ||
}); | ||
if (!nodes) { | ||
return nodes; | ||
} | ||
const edges = nodes.map((value, index) => value == null | ||
? null | ||
: { | ||
const edges = nodes.map((value, index)=>value == null ? null : { | ||
cursor: offsetToCursor(offset + index), | ||
node: value, | ||
}); | ||
node: value | ||
} | ||
); | ||
const trimmed = edges.slice(0, expectedSize); | ||
@@ -70,7 +78,6 @@ return { | ||
hasPreviousPage, | ||
hasNextPage: hasNextPage(nodes.length), | ||
}, | ||
hasNextPage: hasNextPage(nodes.length) | ||
} | ||
}; | ||
} | ||
exports.resolveOffsetConnection = resolveOffsetConnection; | ||
function cursorToOffset(cursor) { | ||
@@ -83,16 +90,13 @@ const string = Buffer.from(cursor, 'base64').toString(); | ||
} | ||
exports.cursorToOffset = cursorToOffset; | ||
function offsetToCursor(offset) { | ||
return Buffer.from(`${OFFSET_CURSOR_PREFIX}${offset}`).toString('base64'); | ||
} | ||
exports.offsetToCursor = offsetToCursor; | ||
function resolveArrayConnection(options, array) { | ||
const { limit, offset, expectedSize, hasPreviousPage, hasNextPage } = offsetForArgs(options); | ||
const { limit , offset , expectedSize , hasPreviousPage , hasNextPage } = offsetForArgs(options); | ||
const nodes = array.slice(offset, offset + limit); | ||
const edges = nodes.map((value, index) => value == null | ||
? null | ||
: { | ||
const edges = nodes.map((value, index)=>value == null ? null : { | ||
cursor: offsetToCursor(offset + index), | ||
node: value, | ||
}); | ||
node: value | ||
} | ||
); | ||
const trimmed = edges.slice(0, expectedSize); | ||
@@ -105,7 +109,7 @@ return { | ||
hasPreviousPage, | ||
hasNextPage: hasNextPage(nodes.length), | ||
}, | ||
hasNextPage: hasNextPage(nodes.length) | ||
} | ||
}; | ||
} | ||
exports.resolveArrayConnection = resolveArrayConnection; | ||
//# sourceMappingURL=connections.js.map |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
var _exportNames = { | ||
encodeGlobalID: true, | ||
typename: true, | ||
id: true, | ||
decodeGlobalID: true, | ||
globalID: true, | ||
typename: true, | ||
id: true, | ||
capitalize: true, | ||
s: true | ||
}; | ||
exports.encodeGlobalID = encodeGlobalID; | ||
exports.decodeGlobalID = decodeGlobalID; | ||
exports.capitalize = capitalize; | ||
var _connections = _interopRequireWildcard(require("./connections")); | ||
Object.keys(_connections).forEach(function(key) { | ||
if (key === "default" || key === "__esModule") return; | ||
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return; | ||
if (key in exports && exports[key] === _connections[key]) return; | ||
Object.defineProperty(exports, key, { | ||
enumerable: true, | ||
get: function() { | ||
return _connections[key]; | ||
} | ||
}); | ||
}); | ||
var _resolveNodes = _interopRequireWildcard(require("./resolve-nodes")); | ||
Object.keys(_resolveNodes).forEach(function(key) { | ||
if (key === "default" || key === "__esModule") return; | ||
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return; | ||
if (key in exports && exports[key] === _resolveNodes[key]) return; | ||
Object.defineProperty(exports, key, { | ||
enumerable: true, | ||
get: function() { | ||
return _resolveNodes[key]; | ||
} | ||
}); | ||
}); | ||
function _interopRequireWildcard(obj) { | ||
if (obj && obj.__esModule) { | ||
return obj; | ||
} else { | ||
var newObj = {}; | ||
if (obj != null) { | ||
for(var key in obj){ | ||
if (Object.prototype.hasOwnProperty.call(obj, key)) { | ||
var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; | ||
if (desc.get || desc.set) { | ||
Object.defineProperty(newObj, key, desc); | ||
} else { | ||
newObj[key] = obj[key]; | ||
} | ||
} | ||
} | ||
} | ||
newObj.default = obj; | ||
return newObj; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.capitalize = exports.decodeGlobalID = exports.encodeGlobalID = void 0; | ||
__exportStar(require("./connections"), exports); | ||
__exportStar(require("./resolve-nodes"), exports); | ||
} | ||
function encodeGlobalID(typename, id) { | ||
return Buffer.from(`${typename}:${id}`).toString('base64'); | ||
} | ||
exports.encodeGlobalID = encodeGlobalID; | ||
function decodeGlobalID(globalID) { | ||
@@ -29,9 +72,11 @@ const [typename, id] = Buffer.from(globalID, 'base64').toString().split(':'); | ||
} | ||
return { typename, id }; | ||
return { | ||
typename, | ||
id | ||
}; | ||
} | ||
exports.decodeGlobalID = decodeGlobalID; | ||
function capitalize(s) { | ||
return `${s.slice(0, 1).toUpperCase()}${s.slice(1)}`; | ||
} | ||
exports.capitalize = capitalize; | ||
//# sourceMappingURL=index.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.internalDecodeGlobalID = exports.internalEncodeGlobalID = void 0; | ||
const _1 = require("."); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.internalEncodeGlobalID = internalEncodeGlobalID; | ||
exports.internalDecodeGlobalID = internalDecodeGlobalID; | ||
var _ = require("."); | ||
function internalEncodeGlobalID(builder, typename, id) { | ||
@@ -9,5 +12,4 @@ if (builder.options.relayOptions.encodeGlobalID) { | ||
} | ||
return (0, _1.encodeGlobalID)(typename, id); | ||
return (0, _).encodeGlobalID(typename, id); | ||
} | ||
exports.internalEncodeGlobalID = internalEncodeGlobalID; | ||
function internalDecodeGlobalID(builder, globalID) { | ||
@@ -17,5 +19,5 @@ if (builder.options.relayOptions.decodeGlobalID) { | ||
} | ||
return (0, _1.decodeGlobalID)(globalID); | ||
return (0, _).decodeGlobalID(globalID); | ||
} | ||
exports.internalDecodeGlobalID = internalDecodeGlobalID; | ||
//# sourceMappingURL=internal.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.resolveUncachedNodesForType = exports.resolveNodes = void 0; | ||
const core_1 = require("@pothos/core"); | ||
const internal_1 = require("./internal"); | ||
const getRequestCache = (0, core_1.createContextCache)(() => new Map()); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.resolveNodes = resolveNodes; | ||
exports.resolveUncachedNodesForType = resolveUncachedNodesForType; | ||
var _core = require("@pothos/core"); | ||
var _internal = require("./internal"); | ||
const getRequestCache = (0, _core).createContextCache(()=>new Map() | ||
); | ||
async function resolveNodes(builder, context, info, globalIDs) { | ||
@@ -11,3 +15,3 @@ const requestCache = getRequestCache(context); | ||
const results = {}; | ||
globalIDs.forEach((globalID, i) => { | ||
globalIDs.forEach((globalID, i)=>{ | ||
if (globalID == null) { | ||
@@ -20,17 +24,21 @@ return; | ||
} | ||
const { id, typename } = (0, internal_1.internalDecodeGlobalID)(builder, globalID); | ||
const { id , typename } = (0, _internal).internalDecodeGlobalID(builder, globalID); | ||
idsByType[typename] = idsByType[typename] || new Map(); | ||
idsByType[typename].set(id, globalID); | ||
}); | ||
await Promise.all(Object.keys(idsByType).map(async (typename) => { | ||
var _a, _b; | ||
const ids = [...idsByType[typename].keys()]; | ||
const globalIds = [...idsByType[typename].values()]; | ||
await Promise.all(Object.keys(idsByType).map(async (typename)=>{ | ||
const ids = [ | ||
...idsByType[typename].keys() | ||
]; | ||
const globalIds = [ | ||
...idsByType[typename].values() | ||
]; | ||
const config = builder.configStore.getTypeConfig(typename, 'Object'); | ||
const options = config.pothosOptions; | ||
const shouldBrandObjects = (_b = (_a = options.brandLoadedObjects) !== null && _a !== void 0 ? _a : builder.options.relayOptions.brandLoadedObjects) !== null && _b !== void 0 ? _b : false; | ||
var _brandLoadedObjects, ref; | ||
const shouldBrandObjects = (ref = (_brandLoadedObjects = options.brandLoadedObjects) !== null && _brandLoadedObjects !== void 0 ? _brandLoadedObjects : builder.options.relayOptions.brandLoadedObjects) !== null && ref !== void 0 ? ref : false; | ||
const resultsForType = await resolveUncachedNodesForType(builder, context, info, ids, typename); | ||
resultsForType.forEach((val, i) => { | ||
resultsForType.forEach((val, i)=>{ | ||
if (shouldBrandObjects) { | ||
(0, core_1.brandWithType)(val, typename); | ||
(0, _core).brandWithType(val, typename); | ||
} | ||
@@ -40,5 +48,6 @@ results[globalIds[i]] = val; | ||
})); | ||
return globalIDs.map((globalID) => { var _a; return (globalID == null ? null : (_a = results[globalID]) !== null && _a !== void 0 ? _a : null); }); | ||
var _globalID; | ||
return globalIDs.map((globalID)=>globalID == null ? null : (_globalID = results[globalID]) !== null && _globalID !== void 0 ? _globalID : null | ||
); | ||
} | ||
exports.resolveNodes = resolveNodes; | ||
async function resolveUncachedNodesForType(builder, context, info, ids, type) { | ||
@@ -50,7 +59,6 @@ const requestCache = getRequestCache(context); | ||
const loadManyPromise = Promise.resolve(options.loadMany(ids, context)); | ||
return Promise.all(ids.map((id, i) => { | ||
const globalID = (0, internal_1.internalEncodeGlobalID)(builder, config.name, id); | ||
const entryPromise = loadManyPromise | ||
.then((results) => results[i]) | ||
.then((result) => { | ||
return Promise.all(ids.map((id, i)=>{ | ||
const globalID = (0, _internal).internalEncodeGlobalID(builder, config.name, id); | ||
const entryPromise = loadManyPromise.then((results)=>results[i] | ||
).then((result)=>{ | ||
requestCache.set(globalID, result); | ||
@@ -64,5 +72,5 @@ return result; | ||
if (options.loadOne) { | ||
return Promise.all(ids.map((id) => { | ||
const globalID = (0, internal_1.internalEncodeGlobalID)(builder, config.name, id); | ||
const entryPromise = Promise.resolve(options.loadOne(id, context)).then((result) => { | ||
return Promise.all(ids.map((id)=>{ | ||
const globalID = (0, _internal).internalEncodeGlobalID(builder, config.name, id); | ||
const entryPromise = Promise.resolve(options.loadOne(id, context)).then((result)=>{ | ||
requestCache.set(globalID, result); | ||
@@ -79,7 +87,8 @@ return result; | ||
if (options.loadWithoutCache) { | ||
return Promise.all(ids.map((id) => Promise.resolve(options.loadWithoutCache(id, context, info)))); | ||
return Promise.all(ids.map((id)=>Promise.resolve(options.loadWithoutCache(id, context, info)) | ||
)); | ||
} | ||
throw new Error(`${config.name} does not support loading by id`); | ||
} | ||
exports.resolveUncachedNodesForType = resolveUncachedNodesForType; | ||
//# sourceMappingURL=resolve-nodes.js.map |
{ | ||
"name": "@pothos/plugin-relay", | ||
"version": "3.7.0", | ||
"version": "3.8.0", | ||
"description": "A Pothos plugin for adding relay style connections, nodes, and cursor based pagination to your GraphQL schema", | ||
"main": "./lib/index.js", | ||
"types": "./lib/index.d.ts", | ||
"types": "./dts/index.d.ts", | ||
"module": "./esm/index.js", | ||
@@ -38,4 +38,4 @@ "exports": { | ||
"devDependencies": { | ||
"@pothos/core": "3.4.0", | ||
"@pothos/test-utils": "1.0.2", | ||
"@pothos/core": "3.5.0", | ||
"@pothos/test-utils": "1.1.0", | ||
"graphql": "16.3.0", | ||
@@ -47,7 +47,9 @@ "graphql-subscriptions": "^2.0.0", | ||
"scripts": { | ||
"type": "tsc --noEmit && tsc --project tests/tsconfig.json", | ||
"build": "pnpm build:cjs && pnpm build:esm", | ||
"build:cjs": "tsc --module commonjs --outDir lib", | ||
"build:esm": "tsc --module es2020 --outDir esm && pnpm esm:extensions", | ||
"esm:extensions": "ts-node --compiler-options \"{\\\"module\\\":\\\"commonjs\\\"}\" ../../.config/esm-transformer.ts", | ||
"type": "tsc --project tsconfig.type.json", | ||
"build": "pnpm build:clean && pnpm build:cjs && pnpm build:esm && pnpm build:dts", | ||
"build:clean": "git clean -dfX esm lib", | ||
"build:cjs": "swc src -d lib --config-file ../../.swcrc -C module.type=commonjs", | ||
"build:esm": "swc src -d esm --config-file ../../.swcrc -C module.type=es6 && pnpm esm:extensions", | ||
"build:dts": "tsc", | ||
"esm:extensions": "TS_NODE_PROJECT=../../tsconfig.json node -r @swc-node/register ../../.config/esm-transformer.ts", | ||
"test": "pnpm jest --runInBand" | ||
@@ -54,0 +56,0 @@ }, |
{ | ||
"compilerOptions": { | ||
"outDir": "lib", | ||
"noEmit": false, | ||
"declaration": true, | ||
"declarationMap": true, | ||
"emitDeclarationOnly": true, | ||
"outDir": "dts", | ||
"rootDir": "src" | ||
}, | ||
"exclude": [ | ||
"lib", | ||
"tests" | ||
"include": [ | ||
"src/**/*" | ||
], | ||
"extends": "../../tsconfig.options.json", | ||
"include": [ | ||
"src/**/*", | ||
"types/**/*", | ||
"../../types/**/*" | ||
], | ||
"references": [ | ||
{ | ||
"path": "../test-utils" | ||
} | ||
] | ||
} |
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
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
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
478077
79
3720