UNPKG

@pothos/plugin-scope-auth

Version:

A Pothos plugin for adding scope based authorization checks to your GraphQL Schema

37 lines (36 loc) 1.49 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const _core = require("@pothos/core"); const objectFieldBuilder = _core.ObjectFieldBuilder.prototype; objectFieldBuilder.withAuth = function withAuth(scopes) { return addScopes(scopes, new _core.ObjectFieldBuilder(this.builder)); }; const interfaceFieldBuilder = _core.InterfaceFieldBuilder.prototype; interfaceFieldBuilder.withAuth = function withAuth(scopes) { return addScopes(scopes, new _core.InterfaceFieldBuilder(this.builder)); }; const queryFieldBuilder = _core.QueryFieldBuilder.prototype; queryFieldBuilder.withAuth = function withAuth(scopes) { return addScopes(scopes, new _core.QueryFieldBuilder(this.builder)); }; const mutationFieldBuilder = _core.MutationFieldBuilder.prototype; mutationFieldBuilder.withAuth = function withAuth(scopes) { return addScopes(scopes, new _core.MutationFieldBuilder(this.builder)); }; const subscriptionFieldBuilder = _core.SubscriptionFieldBuilder.prototype; subscriptionFieldBuilder.withAuth = function withAuth(scopes) { return addScopes(scopes, new _core.SubscriptionFieldBuilder(this.builder)); }; function addScopes(scopes, builder) { const originalCreateField = builder.createField; builder.createField = function createField(options) { return originalCreateField.call(this, { authScopes: scopes, ...options }); }; return builder; } //# sourceMappingURL=field-builders.js.map