custom-scalars.plugin.ts 623 B

12345678910111213141516171819202122232425
  1. import { PluginCommonModule, VendurePlugin } from '@vendure/core';
  2. import { GraphQLScalarType, Kind } from 'graphql';
  3. import gql from 'graphql-tag';
  4. const FooScalar = new GraphQLScalarType({
  5. name: 'FooScalar',
  6. description: 'A test scalar',
  7. serialize(value) {
  8. return value.toString() + '-foo';
  9. },
  10. parseValue(value) {
  11. return value.toString().split('-foo')[0];
  12. },
  13. });
  14. @VendurePlugin({
  15. imports: [PluginCommonModule],
  16. shopApiExtensions: {
  17. schema: gql`
  18. scalar FooScalar
  19. `,
  20. scalars: { FooScalar },
  21. },
  22. })
  23. export class CustomScalarsPlugin {}