with-api-extensions.ts 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import { Query, Resolver } from '@nestjs/graphql';
  2. import { VendurePlugin } from '@vendure/core';
  3. import gql from 'graphql-tag';
  4. @Resolver()
  5. export class TestAdminPluginResolver {
  6. @Query()
  7. foo() {
  8. return ['bar'];
  9. }
  10. @Query()
  11. barList() {
  12. return {
  13. items: [{ id: 1, name: 'Test' }],
  14. totalItems: 1,
  15. };
  16. }
  17. }
  18. @Resolver()
  19. export class TestShopPluginResolver {
  20. @Query()
  21. baz() {
  22. return ['quux'];
  23. }
  24. }
  25. @VendurePlugin({
  26. shopApiExtensions: {
  27. resolvers: [TestShopPluginResolver],
  28. schema: gql`
  29. extend type Query {
  30. baz: [String]!
  31. }
  32. `,
  33. },
  34. adminApiExtensions: {
  35. resolvers: [TestAdminPluginResolver],
  36. schema: gql`
  37. extend type Query {
  38. foo: [String]!
  39. barList(options: BarListOptions): BarList!
  40. }
  41. input BarListOptions
  42. type Bar implements Node {
  43. id: ID!
  44. name: String!
  45. }
  46. type BarList implements PaginatedList {
  47. items: [Bar!]!
  48. totalItems: Int!
  49. }
  50. `,
  51. },
  52. })
  53. export class TestAPIExtensionPlugin {}