issue-2097-plugin.ts 807 B

12345678910111213141516171819202122232425262728293031323334
  1. import { Query, Resolver } from '@nestjs/graphql';
  2. import { Allow, Ctx, Permission, RequestContext, VendurePlugin } from '@vendure/core';
  3. import gql from 'graphql-tag';
  4. @Resolver()
  5. class TestResolver {
  6. @Query()
  7. async publicThing(@Ctx() ctx: RequestContext) {
  8. return true;
  9. }
  10. @Query()
  11. @Allow(Permission.Owner)
  12. async ownerProtectedThing(@Ctx() ctx: RequestContext) {
  13. if (ctx.authorizedAsOwnerOnly) {
  14. return true;
  15. } else {
  16. return false;
  17. }
  18. }
  19. }
  20. @VendurePlugin({
  21. shopApiExtensions: {
  22. schema: gql`
  23. extend type Query {
  24. publicThing: Boolean!
  25. ownerProtectedThing: Boolean!
  26. }
  27. `,
  28. resolvers: [TestResolver],
  29. },
  30. })
  31. export class Issue2097Plugin {}