with-api-extensions.ts 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import { Query, Resolver } from '@nestjs/graphql';
  2. import { VendurePlugin } from '@vendure/core';
  3. import { GraphQLScalarType } from 'graphql';
  4. import gql from 'graphql-tag';
  5. @Resolver()
  6. export class TestAdminPluginResolver {
  7. @Query()
  8. foo() {
  9. return ['bar'];
  10. }
  11. @Query()
  12. barList() {
  13. return {
  14. items: [{ id: 1, name: 'Test', pizzaType: 'Cheese' }],
  15. totalItems: 1,
  16. };
  17. }
  18. }
  19. @Resolver()
  20. export class TestShopPluginResolver {
  21. @Query()
  22. baz() {
  23. return ['quux'];
  24. }
  25. }
  26. const PizzaScalar = new GraphQLScalarType({
  27. name: 'Pizza',
  28. description: 'Everything is pizza',
  29. serialize(value) {
  30. return ((value as any).toString() as string) + ' pizza!';
  31. },
  32. parseValue(value) {
  33. return value;
  34. },
  35. });
  36. @VendurePlugin({
  37. shopApiExtensions: {
  38. resolvers: [TestShopPluginResolver],
  39. schema: gql`
  40. extend type Query {
  41. baz: [String]!
  42. }
  43. `,
  44. },
  45. adminApiExtensions: {
  46. resolvers: [TestAdminPluginResolver],
  47. schema: gql`
  48. scalar Pizza
  49. extend type Query {
  50. foo: [String]!
  51. barList(options: BarListOptions): BarList!
  52. }
  53. input BarListOptions
  54. type Bar implements Node {
  55. id: ID!
  56. name: String!
  57. pizzaType: Pizza!
  58. }
  59. type BarList implements PaginatedList {
  60. items: [Bar!]!
  61. totalItems: Int!
  62. }
  63. `,
  64. scalars: { Pizza: PizzaScalar },
  65. },
  66. })
  67. export class TestAPIExtensionPlugin {}