@pothos/plugin-relay
Advanced tools
Comparing version 0.0.0-preview-20220211214221 to 0.0.0-preview-20220225212244
# Change Log | ||
## 0.0.0-preview-20220211214221 | ||
## 3.5.2 | ||
### Patch Changes | ||
- 31f9e8be: Fix isTypeOf check not handling \_\_typename correctly | ||
## 3.5.1 | ||
### Patch Changes | ||
- 03aecf76: update .npmignore | ||
## 3.5.0 | ||
### Minor Changes | ||
- 4ad5f4ff: Normalize resloveType and isTypeOf behavior to match graphql spec behavir and allow both | ||
to be optional | ||
- 80b24ec1: Add ability to branded objects loaded by relay plugin with typename to reduce need to | ||
isTypeOf checks | ||
### Patch Changes | ||
- 80b24ec1: Fix issue with connection arg types | ||
## 3.4.0 | ||
### Minor Changes | ||
- 4ad5f4ff: Normalize resolveType and isTypeOf behavior to match graphql spec behavior and allow | ||
both to be optional | ||
### Patch Changes | ||
- 43ca3031: Update dev dependencies | ||
## 3.3.1 | ||
@@ -11,0 +38,0 @@ |
@@ -72,3 +72,3 @@ 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'; | ||
nodeNullable?: NodeNullability; | ||
resolve: Resolver<ParentShape, InputShapeFromFields<Args & InputFieldsFromShape<DefaultConnectionArguments>>, Types['Context'], ConnectionShapeForType<Types, Type, Nullable, EdgeNullability, NodeNullability>, ResolveReturnShape>; | ||
resolve: Resolver<ParentShape, InputShapeFromFields<Args> & DefaultConnectionArguments, Types['Context'], ConnectionShapeForType<Types, Type, Nullable, EdgeNullability, NodeNullability>, ResolveReturnShape>; | ||
} | ||
@@ -75,0 +75,0 @@ interface ConnectionObjectOptions<Types extends SchemaTypes, Type extends OutputType<Types>, EdgeNullability extends FieldNullability<[unknown]>, NodeNullability extends boolean, Resolved> extends ObjectTypeOptions<Types, ConnectionShapeFromResolve<Types, Type, false, EdgeNullability, NodeNullability, Resolved>> { |
@@ -1,2 +0,2 @@ | ||
import SchemaBuilder, { createContextCache, verifyRef, } from '@pothos/core'; | ||
import SchemaBuilder, { createContextCache, getTypeBrand, verifyRef, } from '@pothos/core'; | ||
import { capitalize, resolveNodes } from './utils/index.js'; | ||
@@ -95,2 +95,6 @@ const schemaBuilderProto = SchemaBuilder.prototype; | ||
} | ||
const typeBrand = getTypeBrand(maybeNode); | ||
if (typeBrand && this.configStore.getTypeConfig(typeBrand).name === nodeName) { | ||
return true; | ||
} | ||
if (typeof param === "function" && maybeNode instanceof param) { | ||
@@ -101,8 +105,9 @@ return true; | ||
try { | ||
if (proto === null || proto === void 0 ? void 0 : proto.constructor) { | ||
const config = this.configStore.getTypeConfig(proto.constructor); | ||
return config.name === nodeName; | ||
} | ||
if (typeof maybeNode === "object") { | ||
// eslint-disable-next-line no-underscore-dangle | ||
const typename = maybeNode.__typename; | ||
if (typename === nodeName) { | ||
return true; | ||
} | ||
// eslint-disable-next-line no-underscore-dangle | ||
const nodeRef = maybeNode.__type; | ||
@@ -115,2 +120,6 @@ if (!nodeRef) { | ||
} | ||
if (proto === null || proto === void 0 ? void 0 : proto.constructor) { | ||
const config = this.configStore.getTypeConfig(proto.constructor); | ||
return config.name === nodeName; | ||
} | ||
} | ||
@@ -117,0 +126,0 @@ catch { |
@@ -6,2 +6,3 @@ import { GraphQLResolveInfo } from 'graphql'; | ||
cursorType?: 'ID' | 'String'; | ||
brandLoadedObjects?: boolean; | ||
nodeTypeOptions: Omit<PothosSchemaTypes.ObjectTypeOptions<Types, unknown>, 'fields'>; | ||
@@ -75,2 +76,3 @@ pageInfoTypeOptions: Omit<PothosSchemaTypes.ObjectTypeOptions<Types, PageInfoShape>, 'fields'>; | ||
id: Omit<FieldOptionsFromKind<Types, ParentShape<Types, Param>, 'ID', false, {}, 'Object', OutputShape<Types, 'ID'>, MaybePromise<OutputShape<Types, 'ID'>>>, 'args' | 'nullable' | 'type'>; | ||
brandLoadedObjects?: boolean; | ||
loadOne?: (id: string, context: Types['Context']) => MaybePromise<OutputShape<Types, Param> | null | undefined>; | ||
@@ -77,0 +79,0 @@ loadMany?: (ids: string[], context: Types['Context']) => MaybePromise<MaybePromise<OutputShape<Types, Param> | null | undefined>[]>; |
@@ -1,2 +0,2 @@ | ||
import { createContextCache, } from '@pothos/core'; | ||
import { brandWithType, createContextCache, } from '@pothos/core'; | ||
import { internalDecodeGlobalID, internalEncodeGlobalID } from './internal.js'; | ||
@@ -21,6 +21,13 @@ 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 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; | ||
const resultsForType = await resolveUncachedNodesForType(builder, context, info, ids, typename); | ||
resultsForType.forEach((val, i) => { | ||
if (shouldBrandObjects) { | ||
brandWithType(val, typename); | ||
} | ||
results[globalIds[i]] = val; | ||
@@ -27,0 +34,0 @@ }); |
@@ -72,3 +72,3 @@ 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'; | ||
nodeNullable?: NodeNullability; | ||
resolve: Resolver<ParentShape, InputShapeFromFields<Args & InputFieldsFromShape<DefaultConnectionArguments>>, Types['Context'], ConnectionShapeForType<Types, Type, Nullable, EdgeNullability, NodeNullability>, ResolveReturnShape>; | ||
resolve: Resolver<ParentShape, InputShapeFromFields<Args> & DefaultConnectionArguments, Types['Context'], ConnectionShapeForType<Types, Type, Nullable, EdgeNullability, NodeNullability>, ResolveReturnShape>; | ||
} | ||
@@ -75,0 +75,0 @@ interface ConnectionObjectOptions<Types extends SchemaTypes, Type extends OutputType<Types>, EdgeNullability extends FieldNullability<[unknown]>, NodeNullability extends boolean, Resolved> extends ObjectTypeOptions<Types, ConnectionShapeFromResolve<Types, Type, false, EdgeNullability, NodeNullability, Resolved>> { |
@@ -117,2 +117,6 @@ "use strict"; | ||
} | ||
const typeBrand = (0, core_1.getTypeBrand)(maybeNode); | ||
if (typeBrand && this.configStore.getTypeConfig(typeBrand).name === nodeName) { | ||
return true; | ||
} | ||
if (typeof param === 'function' && maybeNode instanceof param) { | ||
@@ -123,8 +127,9 @@ return true; | ||
try { | ||
if (proto === null || proto === void 0 ? void 0 : proto.constructor) { | ||
const config = this.configStore.getTypeConfig(proto.constructor); | ||
return config.name === nodeName; | ||
} | ||
if (typeof maybeNode === 'object') { | ||
// eslint-disable-next-line no-underscore-dangle | ||
const typename = maybeNode.__typename; | ||
if (typename === nodeName) { | ||
return true; | ||
} | ||
// eslint-disable-next-line no-underscore-dangle | ||
const nodeRef = maybeNode.__type; | ||
@@ -137,2 +142,6 @@ if (!nodeRef) { | ||
} | ||
if (proto === null || proto === void 0 ? void 0 : proto.constructor) { | ||
const config = this.configStore.getTypeConfig(proto.constructor); | ||
return config.name === nodeName; | ||
} | ||
} | ||
@@ -139,0 +148,0 @@ catch { |
@@ -6,2 +6,3 @@ import { GraphQLResolveInfo } from 'graphql'; | ||
cursorType?: 'ID' | 'String'; | ||
brandLoadedObjects?: boolean; | ||
nodeTypeOptions: Omit<PothosSchemaTypes.ObjectTypeOptions<Types, unknown>, 'fields'>; | ||
@@ -75,2 +76,3 @@ pageInfoTypeOptions: Omit<PothosSchemaTypes.ObjectTypeOptions<Types, PageInfoShape>, 'fields'>; | ||
id: Omit<FieldOptionsFromKind<Types, ParentShape<Types, Param>, 'ID', false, {}, 'Object', OutputShape<Types, 'ID'>, MaybePromise<OutputShape<Types, 'ID'>>>, 'args' | 'nullable' | 'type'>; | ||
brandLoadedObjects?: boolean; | ||
loadOne?: (id: string, context: Types['Context']) => MaybePromise<OutputShape<Types, Param> | null | undefined>; | ||
@@ -77,0 +79,0 @@ loadMany?: (ids: string[], context: Types['Context']) => MaybePromise<MaybePromise<OutputShape<Types, Param> | null | undefined>[]>; |
@@ -24,6 +24,13 @@ "use strict"; | ||
await Promise.all(Object.keys(idsByType).map(async (typename) => { | ||
var _a, _b; | ||
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; | ||
const resultsForType = await resolveUncachedNodesForType(builder, context, info, ids, typename); | ||
resultsForType.forEach((val, i) => { | ||
if (shouldBrandObjects) { | ||
(0, core_1.brandWithType)(val, typename); | ||
} | ||
results[globalIds[i]] = val; | ||
@@ -30,0 +37,0 @@ }); |
{ | ||
"name": "@pothos/plugin-relay", | ||
"version": "0.0.0-preview-20220211214221", | ||
"version": "0.0.0-preview-20220225212244", | ||
"description": "A Pothos plugin for adding relay style connections, nodes, and cursor based pagination to your GraphQL schema", | ||
@@ -38,4 +38,4 @@ "main": "./lib/index.js", | ||
"devDependencies": { | ||
"@pothos/core": "0.0.0-preview-20220211214221", | ||
"@pothos/test-utils": "1.0.1", | ||
"@pothos/core": "0.0.0-preview-20220225212244", | ||
"@pothos/test-utils": "1.0.2", | ||
"graphql": "16.3.0", | ||
@@ -42,0 +42,0 @@ "graphql-subscriptions": "^2.0.0", |
@@ -285,3 +285,3 @@ import { | ||
ParentShape, | ||
InputShapeFromFields<Args & InputFieldsFromShape<DefaultConnectionArguments>>, | ||
InputShapeFromFields<Args> & DefaultConnectionArguments, | ||
Types['Context'], | ||
@@ -288,0 +288,0 @@ ConnectionShapeForType<Types, Type, Nullable, EdgeNullability, NodeNullability>, |
@@ -7,2 +7,3 @@ /* eslint-disable @typescript-eslint/no-unsafe-return */ | ||
FieldRef, | ||
getTypeBrand, | ||
InterfaceParam, | ||
@@ -168,2 +169,8 @@ InterfaceRef, | ||
const typeBrand = getTypeBrand(maybeNode); | ||
if (typeBrand && this.configStore.getTypeConfig(typeBrand as string).name === nodeName) { | ||
return true; | ||
} | ||
if (typeof param === 'function' && maybeNode instanceof (param as Function)) { | ||
@@ -176,9 +183,10 @@ return true; | ||
try { | ||
if (proto?.constructor) { | ||
const config = this.configStore.getTypeConfig(proto.constructor as OutputRef); | ||
if (typeof maybeNode === 'object') { | ||
// eslint-disable-next-line no-underscore-dangle | ||
const typename = (maybeNode as { __typename: string }).__typename; | ||
return config.name === nodeName; | ||
} | ||
if (typename === nodeName) { | ||
return true; | ||
} | ||
if (typeof maybeNode === 'object') { | ||
// eslint-disable-next-line no-underscore-dangle | ||
@@ -195,2 +203,8 @@ const nodeRef = (maybeNode as { __type: OutputRef }).__type; | ||
} | ||
if (proto?.constructor) { | ||
const config = this.configStore.getTypeConfig(proto.constructor as OutputRef); | ||
return config.name === nodeName; | ||
} | ||
} catch { | ||
@@ -197,0 +211,0 @@ // ignore |
@@ -35,2 +35,3 @@ import { GraphQLResolveInfo } from 'graphql'; | ||
cursorType?: 'ID' | 'String'; | ||
brandLoadedObjects?: boolean; | ||
nodeTypeOptions: Omit<PothosSchemaTypes.ObjectTypeOptions<Types, unknown>, 'fields'>; | ||
@@ -282,2 +283,3 @@ pageInfoTypeOptions: Omit<PothosSchemaTypes.ObjectTypeOptions<Types, PageInfoShape>, 'fields'>; | ||
>; | ||
brandLoadedObjects?: boolean; | ||
loadOne?: ( | ||
@@ -284,0 +286,0 @@ id: string, |
@@ -1,4 +0,4 @@ | ||
/* eslint-disable @typescript-eslint/no-use-before-define */ | ||
import { GraphQLResolveInfo } from 'graphql'; | ||
import { | ||
brandWithType, | ||
createContextCache, | ||
@@ -46,2 +46,7 @@ MaybePromise, | ||
const config = builder.configStore.getTypeConfig(typename, 'Object'); | ||
const options = config.pothosOptions as NodeObjectOptions<Types, ObjectParam<Types>, []>; | ||
const shouldBrandObjects = | ||
options.brandLoadedObjects ?? builder.options.relayOptions.brandLoadedObjects ?? false; | ||
const resultsForType = await resolveUncachedNodesForType( | ||
@@ -56,2 +61,6 @@ builder, | ||
resultsForType.forEach((val, i) => { | ||
if (shouldBrandObjects) { | ||
brandWithType(val, typename as OutputType<Types>); | ||
} | ||
results[globalIds[i]] = val; | ||
@@ -58,0 +67,0 @@ }); |
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
317895
3830
96