Browse Source

fix(core): Correctly decode list query ID operators

Fixes #1922
Michael Bromley 3 years ago
parent
commit
9f9b0e6c4f

+ 4 - 4
packages/core/e2e/list-query-builder.e2e-spec.ts

@@ -355,7 +355,7 @@ describe('ListQueryBuilder', () => {
                 options: {
                     filter: {
                         ownerId: {
-                            eq: '13',
+                            eq: 'T_13',
                         },
                     },
                 },
@@ -369,7 +369,7 @@ describe('ListQueryBuilder', () => {
                 options: {
                     filter: {
                         ownerId: {
-                            notEq: '13',
+                            notEq: 'T_13',
                         },
                     },
                 },
@@ -383,7 +383,7 @@ describe('ListQueryBuilder', () => {
                 options: {
                     filter: {
                         ownerId: {
-                            in: ['10', '15'],
+                            in: ['T_10', 'T_15'],
                         },
                     },
                 },
@@ -411,7 +411,7 @@ describe('ListQueryBuilder', () => {
                 options: {
                     filter: {
                         ownerId: {
-                            notIn: ['10', '15'],
+                            notIn: ['T_10', 'T_15'],
                         },
                     },
                 },

+ 9 - 2
packages/core/src/api/middleware/id-interceptor.ts

@@ -1,5 +1,6 @@
 import { CallHandler, ExecutionContext, Injectable, NestInterceptor } from '@nestjs/common';
 import { GqlExecutionContext } from '@nestjs/graphql';
+import { IdOperators } from '@vendure/common/lib/generated-types';
 import { VariableValues } from 'apollo-server-core';
 import { GraphQLNamedType, GraphQLSchema, OperationDefinitionNode } from 'graphql';
 import { Observable } from 'rxjs';
@@ -55,8 +56,14 @@ export class IdInterceptor implements NestInterceptor {
     ) {
         const typeTree = graphqlValueTransformer.getInputTypeTree(definition);
         graphqlValueTransformer.transformValues(typeTree, variables, (value, type) => {
-            const isIdType = type && type.name === 'ID';
-            return isIdType ? this.idCodecService.decode(value) : value;
+            if (type?.name === 'ID') {
+                return this.idCodecService.decode(value);
+            }
+            if (type?.name === 'IDOperators') {
+                const keys: Array<keyof IdOperators> = ['eq', 'notEq', 'in', 'notIn'];
+                return this.idCodecService.decode(value, keys);
+            }
+            return value;
         });
         return variables;
     }