New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@pothos/plugin-relay

Package Overview
Dependencies
Maintainers
1
Versions
81
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@pothos/plugin-relay - npm Package Compare versions

Comparing version 3.25.0 to 3.26.0

7

CHANGELOG.md
# Change Log
## 3.26.0
### Minor Changes
- 631dea27: Move some checks from isTypeOf to resovleType to improve performance and allow nodes
without isTypeOf checks
## 3.25.0

@@ -4,0 +11,0 @@

66

esm/schema-builder.js

@@ -1,2 +0,3 @@

/* eslint-disable @typescript-eslint/no-unsafe-return */ /* eslint-disable @typescript-eslint/no-unsafe-member-access */ import SchemaBuilder, { createContextCache, getTypeBrand, InputObjectRef, ObjectRef, verifyRef } from '@pothos/core';
/* eslint-disable @typescript-eslint/no-unsafe-return */ /* eslint-disable @typescript-eslint/no-unsafe-member-access */ import { defaultTypeResolver } from 'graphql';
import SchemaBuilder, { createContextCache, getTypeBrand, InputObjectRef, ObjectRef, verifyRef } from '@pothos/core';
import { capitalize, resolveNodes } from './utils/index.js';

@@ -48,2 +49,33 @@ const schemaBuilderProto = SchemaBuilder.prototype;

ref.implement({
resolveType: (value, context, info, graphQLType) => {
if (!value) {
return defaultTypeResolver(value, context, info, graphQLType);
}
const typeBrand = getTypeBrand(value);
if (typeBrand) {
const type = this.configStore.getTypeConfig(typeBrand);
return type.name;
}
try {
if (typeof value === "object") {
// eslint-disable-next-line no-underscore-dangle
const typename = value.__typename;
if (typename) {
return typename;
}
// eslint-disable-next-line no-underscore-dangle
const nodeRef = value.__type;
if (nodeRef) {
const config = this.configStore.getTypeConfig(nodeRef);
if (config) {
return config.name;
}
}
}
}
catch {
// ignore
}
return defaultTypeResolver(value, context, info, graphQLType);
},
...this.options.relayOptions.nodeTypeOptions,

@@ -100,38 +132,18 @@ fields: (t) => {

let nodeName;
var _isTypeOf;
const ref = this.objectType(param, {
...options,
isTypeOf: (maybeNode, context, info) => {
if (options.isTypeOf) {
return options.isTypeOf(maybeNode, context, info);
}
isTypeOf: (_isTypeOf = options.isTypeOf) !== null && _isTypeOf !== void 0 ? _isTypeOf : typeof param === "function" ? (maybeNode, context, info) => {
if (!maybeNode) {
return false;
}
const typeBrand = getTypeBrand(maybeNode);
if (typeBrand && this.configStore.getTypeConfig(typeBrand).name === nodeName) {
if (maybeNode instanceof param) {
return true;
}
if (typeof param === "function" && maybeNode instanceof param) {
return true;
}
const proto = Object.getPrototypeOf(maybeNode);
try {
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;
if (!nodeRef) {
return false;
}
const config = this.configStore.getTypeConfig(nodeRef);
if (proto === null || proto === void 0 ? void 0 : proto.constructor) {
const config = this.configStore.getTypeConfig(proto.constructor);
return config.name === nodeName;
}
if (proto === null || proto === void 0 ? void 0 : proto.constructor) {
const config1 = this.configStore.getTypeConfig(proto.constructor);
return config1.name === nodeName;
}
}

@@ -142,3 +154,3 @@ catch {

return false;
},
} : undefined,
interfaces: interfacesWithNode

@@ -145,0 +157,0 @@ }, fields);

@@ -15,2 +15,3 @@ /* eslint-disable @typescript-eslint/no-unsafe-return */ /* eslint-disable @typescript-eslint/no-unsafe-member-access */ "use strict";

});
const _graphql = require("graphql");
const _core = /*#__PURE__*/ _interopRequireWildcard(require("@pothos/core"));

@@ -102,2 +103,32 @@ const _utils = require("./utils");

ref.implement({
resolveType: (value, context, info, graphQLType)=>{
if (!value) {
return (0, _graphql.defaultTypeResolver)(value, context, info, graphQLType);
}
const typeBrand = (0, _core.getTypeBrand)(value);
if (typeBrand) {
const type = this.configStore.getTypeConfig(typeBrand);
return type.name;
}
try {
if (typeof value === 'object') {
// eslint-disable-next-line no-underscore-dangle
const typename = value.__typename;
if (typename) {
return typename;
}
// eslint-disable-next-line no-underscore-dangle
const nodeRef = value.__type;
if (nodeRef) {
const config = this.configStore.getTypeConfig(nodeRef);
if (config) {
return config.name;
}
}
}
} catch {
// ignore
}
return (0, _graphql.defaultTypeResolver)(value, context, info, graphQLType);
},
...this.options.relayOptions.nodeTypeOptions,

@@ -154,38 +185,18 @@ fields: (t)=>{

let nodeName;
var _isTypeOf;
const ref = this.objectType(param, {
...options,
isTypeOf: (maybeNode, context, info)=>{
if (options.isTypeOf) {
return options.isTypeOf(maybeNode, context, info);
}
isTypeOf: (_isTypeOf = options.isTypeOf) !== null && _isTypeOf !== void 0 ? _isTypeOf : typeof param === 'function' ? (maybeNode, context, info)=>{
if (!maybeNode) {
return false;
}
const typeBrand = (0, _core.getTypeBrand)(maybeNode);
if (typeBrand && this.configStore.getTypeConfig(typeBrand).name === nodeName) {
if (maybeNode instanceof param) {
return true;
}
if (typeof param === 'function' && maybeNode instanceof param) {
return true;
}
const proto = Object.getPrototypeOf(maybeNode);
try {
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;
if (!nodeRef) {
return false;
}
const config = this.configStore.getTypeConfig(nodeRef);
if (proto === null || proto === void 0 ? void 0 : proto.constructor) {
const config = this.configStore.getTypeConfig(proto.constructor);
return config.name === nodeName;
}
if (proto === null || proto === void 0 ? void 0 : proto.constructor) {
const config1 = this.configStore.getTypeConfig(proto.constructor);
return config1.name === nodeName;
}
} catch {

@@ -195,3 +206,3 @@ // ignore

return false;
},
} : undefined,
interfaces: interfacesWithNode

@@ -198,0 +209,0 @@ }, fields);

{
"name": "@pothos/plugin-relay",
"version": "3.25.0",
"version": "3.26.0",
"description": "A Pothos plugin for adding relay style connections, nodes, and cursor based pagination to your GraphQL schema",

@@ -5,0 +5,0 @@ "main": "./lib/index.js",

/* eslint-disable @typescript-eslint/no-unsafe-return */
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
import { GraphQLResolveInfo } from 'graphql';
import { defaultTypeResolver, GraphQLResolveInfo } from 'graphql';
import SchemaBuilder, {

@@ -31,3 +31,3 @@ createContextCache,

PothosSchemaTypes.SchemaBuilder<SchemaTypes>,
InterfaceRef<ObjectParam<SchemaTypes>>
InterfaceRef<{}>
>();

@@ -94,3 +94,3 @@

const ref = this.interfaceRef<ObjectParam<SchemaTypes>>('Node');
const ref = this.interfaceRef<{}>('Node');

@@ -100,2 +100,41 @@ nodeInterfaceRefMap.set(this, ref);

ref.implement({
resolveType: (value, context, info, graphQLType) => {
if (!value) {
return defaultTypeResolver(value, context, info, graphQLType);
}
const typeBrand = getTypeBrand(value);
if (typeBrand) {
const type = this.configStore.getTypeConfig(typeBrand as string);
return type.name;
}
try {
if (typeof value === 'object') {
// eslint-disable-next-line no-underscore-dangle
const typename = (value as { __typename: string }).__typename;
if (typename) {
return typename;
}
// eslint-disable-next-line no-underscore-dangle
const nodeRef = (value as { __type: OutputRef }).__type;
if (nodeRef) {
const config = this.configStore.getTypeConfig(nodeRef);
if (config) {
return config.name;
}
}
}
} catch {
// ignore
}
return defaultTypeResolver(value, context, info, graphQLType);
},
...this.options.relayOptions.nodeTypeOptions,

@@ -161,55 +200,29 @@ fields: (t) => ({

...(options as {}),
isTypeOf: (maybeNode: unknown, context: object, info: GraphQLResolveInfo) => {
if (options.isTypeOf) {
return options.isTypeOf(maybeNode, context, info);
}
isTypeOf:
options.isTypeOf ??
(typeof param === 'function'
? (maybeNode: unknown, context: object, info: GraphQLResolveInfo) => {
if (!maybeNode) {
return false;
}
if (!maybeNode) {
return false;
}
if (maybeNode instanceof (param as Function)) {
return true;
}
const typeBrand = getTypeBrand(maybeNode);
const proto = Object.getPrototypeOf(maybeNode) as { constructor: unknown };
if (typeBrand && this.configStore.getTypeConfig(typeBrand as string).name === nodeName) {
return true;
}
try {
if (proto?.constructor) {
const config = this.configStore.getTypeConfig(proto.constructor as OutputRef);
if (typeof param === 'function' && maybeNode instanceof (param as Function)) {
return true;
}
return config.name === nodeName;
}
} catch {
// ignore
}
const proto = Object.getPrototypeOf(maybeNode) as { constructor: unknown };
try {
if (typeof maybeNode === 'object') {
// eslint-disable-next-line no-underscore-dangle
const typename = (maybeNode as { __typename: string }).__typename;
if (typename === nodeName) {
return true;
}
// eslint-disable-next-line no-underscore-dangle
const nodeRef = (maybeNode as { __type: OutputRef }).__type;
if (!nodeRef) {
return false;
}
const config = this.configStore.getTypeConfig(nodeRef);
return config.name === nodeName;
}
if (proto?.constructor) {
const config = this.configStore.getTypeConfig(proto.constructor as OutputRef);
return config.name === nodeName;
}
} catch {
// ignore
}
return false;
},
: undefined),
interfaces: interfacesWithNode as [],

@@ -216,0 +229,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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc