@pothos/plugin-scope-auth
Advanced tools
Comparing version 3.17.0 to 3.18.0
# Change Log | ||
## 3.18.0 | ||
### Minor Changes | ||
- bf0385ae: Add new PothosError classes | ||
## 3.17.0 | ||
@@ -4,0 +10,0 @@ |
@@ -0,3 +1,4 @@ | ||
import { PothosValidationError } from '@pothos/core'; | ||
import type { AuthFailure } from '.'; | ||
export declare class ForbiddenError extends Error { | ||
export declare class ForbiddenError extends PothosValidationError { | ||
code: string; | ||
@@ -4,0 +5,0 @@ result: AuthFailure; |
@@ -0,3 +1,4 @@ | ||
import { PothosValidationError } from '@pothos/core'; | ||
import type { AuthFailure } from './index.js'; | ||
export declare class ForbiddenError extends Error { | ||
export declare class ForbiddenError extends PothosValidationError { | ||
code: string; | ||
@@ -4,0 +5,0 @@ result: AuthFailure; |
@@ -0,3 +1,4 @@ | ||
import { PothosValidationError } from '@pothos/core'; | ||
import { AuthScopeFailureType } from './types.js'; | ||
export class ForbiddenError extends Error { | ||
export class ForbiddenError extends PothosValidationError { | ||
constructor(message, result) { | ||
@@ -4,0 +5,0 @@ super(message); |
import './global-types.js'; | ||
import './schema-builder.js'; | ||
import './field-builders.js'; | ||
import SchemaBuilder, { BasePlugin, RootFieldBuilder } from '@pothos/core'; | ||
import SchemaBuilder, { BasePlugin, PothosSchemaError, RootFieldBuilder } from '@pothos/core'; | ||
import { isTypeOfHelper } from './is-type-of-helper.js'; | ||
@@ -21,3 +21,3 @@ import { resolveHelper } from './resolve-helper.js'; | ||
if (typeConfig.graphqlKind !== "Object" && typeConfig.graphqlKind !== "Interface") { | ||
throw new Error(`Got fields for ${fieldConfig.parentType} which is a ${typeConfig.graphqlKind} which cannot have fields`); | ||
throw new PothosSchemaError(`Got fields for ${fieldConfig.parentType} which is a ${typeConfig.graphqlKind} which cannot have fields`); | ||
} | ||
@@ -41,3 +41,3 @@ const authorizedOnSubscribe = !!((_this_builder_options_scopeAuthOptions = this.builder.options.scopeAuthOptions) === null || _this_builder_options_scopeAuthOptions === void 0 ? void 0 : _this_builder_options_scopeAuthOptions.authorizeOnSubscribe) && typeConfig.kind === "Subscription"; | ||
if (typeConfig.graphqlKind !== "Object" && typeConfig.graphqlKind !== "Interface") { | ||
throw new Error(`Got fields for ${fieldConfig.parentType} which is a ${typeConfig.graphqlKind} which cannot have fields`); | ||
throw new PothosSchemaError(`Got fields for ${fieldConfig.parentType} which is a ${typeConfig.graphqlKind} which cannot have fields`); | ||
} | ||
@@ -44,0 +44,0 @@ if (!((_this_builder_options_scopeAuthOptions = this.builder.options.scopeAuthOptions) === null || _this_builder_options_scopeAuthOptions === void 0 ? void 0 : _this_builder_options_scopeAuthOptions.authorizeOnSubscribe) || typeConfig.kind !== "Subscription") { |
@@ -1,2 +0,2 @@ | ||
/* eslint-disable @typescript-eslint/promise-function-async */ import { isThenable } from '@pothos/core'; | ||
/* eslint-disable @typescript-eslint/promise-function-async */ import { isThenable, PothosValidationError } from '@pothos/core'; | ||
import { AuthScopeFailureType } from './types.js'; | ||
@@ -77,3 +77,3 @@ import { cacheKey, canCache } from './util.js'; | ||
if (typeof loader !== "function") { | ||
throw new TypeError(`Attempted to evaluate scope ${String(name)} as scope loader, but it is not a function`); | ||
throw new PothosValidationError(`Attempted to evaluate scope ${String(name)} as scope loader, but it is not a function`); | ||
} | ||
@@ -216,11 +216,11 @@ let result; | ||
for (const [loaderName, arg] of loaderList) { | ||
const result1 = this.evaluateScopeLoader(scopes, loaderName, arg); | ||
if (isThenable(result1)) { | ||
promises.push(result1); | ||
const result = this.evaluateScopeLoader(scopes, loaderName, arg); | ||
if (isThenable(result)) { | ||
promises.push(result); | ||
} | ||
else if (result1 === null && !forAll) { | ||
else if (result === null && !forAll) { | ||
return resolveAndReturn(null); | ||
} | ||
else if (result1) { | ||
problems.push(result1); | ||
else if (result) { | ||
problems.push(result); | ||
if (forAll) { | ||
@@ -227,0 +227,0 @@ return resolveAndReturn(failure); |
@@ -9,4 +9,5 @@ "use strict"; | ||
}); | ||
const _core = require("@pothos/core"); | ||
const _types = require("./types"); | ||
class ForbiddenError extends Error { | ||
class ForbiddenError extends _core.PothosValidationError { | ||
constructor(message, result){ | ||
@@ -13,0 +14,0 @@ super(message); |
@@ -85,3 +85,3 @@ "use strict"; | ||
if (typeConfig.graphqlKind !== 'Object' && typeConfig.graphqlKind !== 'Interface') { | ||
throw new Error(`Got fields for ${fieldConfig.parentType} which is a ${typeConfig.graphqlKind} which cannot have fields`); | ||
throw new _core.PothosSchemaError(`Got fields for ${fieldConfig.parentType} which is a ${typeConfig.graphqlKind} which cannot have fields`); | ||
} | ||
@@ -105,3 +105,3 @@ const authorizedOnSubscribe = !!((_this_builder_options_scopeAuthOptions = this.builder.options.scopeAuthOptions) === null || _this_builder_options_scopeAuthOptions === void 0 ? void 0 : _this_builder_options_scopeAuthOptions.authorizeOnSubscribe) && typeConfig.kind === 'Subscription'; | ||
if (typeConfig.graphqlKind !== 'Object' && typeConfig.graphqlKind !== 'Interface') { | ||
throw new Error(`Got fields for ${fieldConfig.parentType} which is a ${typeConfig.graphqlKind} which cannot have fields`); | ||
throw new _core.PothosSchemaError(`Got fields for ${fieldConfig.parentType} which is a ${typeConfig.graphqlKind} which cannot have fields`); | ||
} | ||
@@ -108,0 +108,0 @@ if (!((_this_builder_options_scopeAuthOptions = this.builder.options.scopeAuthOptions) === null || _this_builder_options_scopeAuthOptions === void 0 ? void 0 : _this_builder_options_scopeAuthOptions.authorizeOnSubscribe) || typeConfig.kind !== 'Subscription') { |
@@ -83,3 +83,3 @@ /* eslint-disable @typescript-eslint/promise-function-async */ "use strict"; | ||
if (typeof loader !== 'function') { | ||
throw new TypeError(`Attempted to evaluate scope ${String(name)} as scope loader, but it is not a function`); | ||
throw new _core.PothosValidationError(`Attempted to evaluate scope ${String(name)} as scope loader, but it is not a function`); | ||
} | ||
@@ -213,9 +213,9 @@ let result; | ||
for (const [loaderName, arg] of loaderList){ | ||
const result1 = this.evaluateScopeLoader(scopes, loaderName, arg); | ||
if ((0, _core.isThenable)(result1)) { | ||
promises.push(result1); | ||
} else if (result1 === null && !forAll) { | ||
const result = this.evaluateScopeLoader(scopes, loaderName, arg); | ||
if ((0, _core.isThenable)(result)) { | ||
promises.push(result); | ||
} else if (result === null && !forAll) { | ||
return resolveAndReturn(null); | ||
} else if (result1) { | ||
problems.push(result1); | ||
} else if (result) { | ||
problems.push(result); | ||
if (forAll) { | ||
@@ -222,0 +222,0 @@ return resolveAndReturn(failure); |
{ | ||
"name": "@pothos/plugin-scope-auth", | ||
"version": "3.17.0", | ||
"version": "3.18.0", | ||
"description": "A Pothos plugin for adding scope based authorization checks to your GraphQL Schema", | ||
@@ -46,9 +46,9 @@ "main": "./lib/index.js", | ||
"devDependencies": { | ||
"@prisma/client": "^4.7.1", | ||
"@prisma/client": "^4.9.0", | ||
"graphql": "16.6.0", | ||
"graphql-tag": "^2.12.6", | ||
"prisma": "^4.7.1", | ||
"@pothos/core": "3.24.0", | ||
"@pothos/plugin-prisma": "3.40.0", | ||
"@pothos/plugin-relay": "3.32.0", | ||
"prisma": "^4.9.0", | ||
"@pothos/core": "3.25.0", | ||
"@pothos/plugin-prisma": "3.41.0", | ||
"@pothos/plugin-relay": "3.35.0", | ||
"@pothos/test-utils": "1.4.7" | ||
@@ -55,0 +55,0 @@ }, |
@@ -0,1 +1,2 @@ | ||
import { PothosValidationError } from '@pothos/core'; | ||
import { AuthScopeFailureType } from './types'; | ||
@@ -5,3 +6,3 @@ | ||
export class ForbiddenError extends Error { | ||
export class ForbiddenError extends PothosValidationError { | ||
code = 'FORBIDDEN'; | ||
@@ -8,0 +9,0 @@ result: AuthFailure; |
@@ -13,2 +13,3 @@ import './global-types'; | ||
PothosQueryTypeConfig, | ||
PothosSchemaError, | ||
PothosSubscriptionTypeConfig, | ||
@@ -50,3 +51,3 @@ PothosUnionTypeConfig, | ||
if (typeConfig.graphqlKind !== 'Object' && typeConfig.graphqlKind !== 'Interface') { | ||
throw new Error( | ||
throw new PothosSchemaError( | ||
`Got fields for ${fieldConfig.parentType} which is a ${typeConfig.graphqlKind} which cannot have fields`, | ||
@@ -100,3 +101,3 @@ ); | ||
if (typeConfig.graphqlKind !== 'Object' && typeConfig.graphqlKind !== 'Interface') { | ||
throw new Error( | ||
throw new PothosSchemaError( | ||
`Got fields for ${fieldConfig.parentType} which is a ${typeConfig.graphqlKind} which cannot have fields`, | ||
@@ -103,0 +104,0 @@ ); |
/* eslint-disable @typescript-eslint/promise-function-async */ | ||
import { GraphQLResolveInfo } from 'graphql'; | ||
import { isThenable, MaybePromise, Path, SchemaTypes } from '@pothos/core'; | ||
import { isThenable, MaybePromise, Path, PothosValidationError, SchemaTypes } from '@pothos/core'; | ||
import { | ||
@@ -155,3 +155,3 @@ AuthFailure, | ||
if (typeof loader !== 'function') { | ||
throw new TypeError( | ||
throw new PothosValidationError( | ||
`Attempted to evaluate scope ${String(name)} as scope loader, but it is not a function`, | ||
@@ -158,0 +158,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
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
411926
3660