@pothos/plugin-scope-auth
Version:
A Pothos plugin for adding scope based authorization checks to your GraphQL Schema
30 lines (29 loc) • 2.86 kB
TypeScript
import { type MaybePromise, type Path, type SchemaTypes } from '@pothos/core';
import type { GraphQLResolveInfo } from 'graphql';
import { type AuthFailure, type AuthScopeMap, type ScopeLoaderMap, type TypeAuthScopesFunction } from './types.js';
export default class RequestCache<Types extends SchemaTypes> {
builder: PothosSchemaTypes.SchemaBuilder<Types>;
context: Types["Context"];
mapCache: Map<{}, MaybePromise<AuthFailure | null>>;
scopeCache: Map<keyof Types["AuthScopes"], Map<unknown, MaybePromise<AuthFailure | null>>>;
typeCache: Map<string, Map<unknown, MaybePromise<AuthFailure | null>>>;
typeGrants: Map<string, Map<unknown, MaybePromise<null>>>;
grantCache: Map<string, Set<string>>;
scopes?: MaybePromise<ScopeLoaderMap<Types>>;
cacheKey?: (value: unknown) => unknown;
treatErrorsAsUnauthorized: boolean;
defaultStrategy: "all" | "any";
constructor(builder: PothosSchemaTypes.SchemaBuilder<Types>, context: Types["Context"]);
static fromContext<T extends SchemaTypes>(context: T["Context"], builder: PothosSchemaTypes.SchemaBuilder<T>): RequestCache<T>;
static clearForContext<T extends SchemaTypes>(context: T["Context"]): void;
getScopes(): MaybePromise<ScopeLoaderMap<Types>>;
withScopes<T>(cb: (scopes: ScopeLoaderMap<Types>) => MaybePromise<T>): MaybePromise<T>;
saveGrantedScopes(scopes: readonly string[], path: Path | undefined): null;
testGrantedScopes(scope: string, path: Path): boolean;
grantTypeScopes(type: string, parent: unknown, path: Path | undefined, cb: () => MaybePromise<readonly string[]>): Promise<null>;
evaluateScopeLoader<T extends keyof Types["AuthScopes"]>(scopes: ScopeLoaderMap<Types>, name: T, arg: Types["AuthScopes"][T]): import("./types.js").AllAuthScopesFailure | import("./types.js").AnyAuthScopesFailure | import("./types.js").AuthScopeFailure | import("./types.js").AuthScopeFunctionFailure | import("./types.js").GrantedScopeFailure | import("./types.js").UnknownAuthFailure | Promise<AuthFailure | null>;
evaluateScopeMapWithScopes({ $all, $any, $granted, ...map }: AuthScopeMap<Types>, scopes: ScopeLoaderMap<Types>, info: GraphQLResolveInfo | undefined, forAll: boolean): MaybePromise<AuthFailure | null>;
evaluateScopeMap(map: AuthScopeMap<Types> | boolean, info?: GraphQLResolveInfo, forAll?: boolean): MaybePromise<AuthFailure | null>;
evaluateTypeScopeFunction(authScopes: TypeAuthScopesFunction<Types, unknown>, type: string, parent: unknown, info: GraphQLResolveInfo): import("./types.js").AllAuthScopesFailure | import("./types.js").AnyAuthScopesFailure | import("./types.js").AuthScopeFailure | import("./types.js").AuthScopeFunctionFailure | import("./types.js").GrantedScopeFailure | import("./types.js").UnknownAuthFailure | Promise<AuthFailure | null>;
}
//# sourceMappingURL=request-cache.d.ts.map