UNPKG

@pothos/plugin-scope-auth

Version:

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

33 lines (32 loc) 1.45 kB
import { InterfaceFieldBuilder, MutationFieldBuilder, ObjectFieldBuilder, QueryFieldBuilder, SubscriptionFieldBuilder } from '@pothos/core'; const objectFieldBuilder = ObjectFieldBuilder.prototype; objectFieldBuilder.withAuth = function withAuth(scopes) { return addScopes(scopes, new ObjectFieldBuilder(this.builder)); }; const interfaceFieldBuilder = InterfaceFieldBuilder.prototype; interfaceFieldBuilder.withAuth = function withAuth(scopes) { return addScopes(scopes, new InterfaceFieldBuilder(this.builder)); }; const queryFieldBuilder = QueryFieldBuilder.prototype; queryFieldBuilder.withAuth = function withAuth(scopes) { return addScopes(scopes, new QueryFieldBuilder(this.builder)); }; const mutationFieldBuilder = MutationFieldBuilder.prototype; mutationFieldBuilder.withAuth = function withAuth(scopes) { return addScopes(scopes, new MutationFieldBuilder(this.builder)); }; const subscriptionFieldBuilder = SubscriptionFieldBuilder.prototype; subscriptionFieldBuilder.withAuth = function withAuth(scopes) { return addScopes(scopes, new 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