Skip to content

Commit 711d4fb

Browse files
authored
Merge pull request #87 from platform-mesh/namespace-list-query-fix
fix: fix list query
2 parents 8e70ca1 + 16b2727 commit 711d4fb

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

projects/lib/services/resource/resource.service.spec.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -341,10 +341,7 @@ describe('ResourceService', () => {
341341
expect(mockApollo.subscribe).toHaveBeenCalledWith({
342342
query: expect.anything(),
343343
variables: {
344-
namespace: {
345-
type: 'String',
346-
value: namespacedNodeContext.namespaceId,
347-
},
344+
namespace: namespacedNodeContext.namespaceId,
348345
},
349346
});
350347
done();
@@ -649,7 +646,6 @@ describe('ResourceService', () => {
649646
});
650647
});
651648

652-
653649
describe('readAccountInfo', () => {
654650
it('should read account info', (done) => {
655651
const ca = 'cert-data';

projects/lib/services/resource/resource.service.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import { ApolloFactory } from './apollo-factory';
2-
import { ResourceNodeContext } from './resource-node-context';
31
import { Injectable, inject } from '@angular/core';
42
import { TypedDocumentNode } from '@apollo/client/core';
53
import { LuigiCoreService } from '@openmfp/portal-ui-lib';
@@ -15,8 +13,11 @@ import {
1513
} from '@platform-mesh/portal-ui-lib/utils';
1614
import { gql } from 'apollo-angular';
1715
import * as gqlBuilder from 'gql-query-builder';
16+
import VariableOptions from 'gql-query-builder/build/VariableOptions';
1817
import { Observable, of } from 'rxjs';
1918
import { catchError, map } from 'rxjs/operators';
19+
import { ApolloFactory } from './apollo-factory';
20+
import { ResourceNodeContext } from './resource-node-context';
2021

2122
interface ResourceResponseError extends Record<string, any> {
2223
message: string;
@@ -129,7 +130,7 @@ export class ResourceService {
129130
});
130131
} else {
131132
query = {
132-
variables: variables,
133+
variables: this.normalizeGqlBuilderVariables(variables),
133134
query: fieldsOrRawQuery,
134135
};
135136
}
@@ -343,4 +344,12 @@ export class ResourceService {
343344
private isNamespacedResource(nodeContext: ResourceNodeContext) {
344345
return nodeContext?.resourceDefinition?.scope === 'Namespaced';
345346
}
347+
348+
private normalizeGqlBuilderVariables(
349+
variables: VariableOptions,
350+
): Record<string, any> {
351+
return Object.fromEntries(
352+
Object.entries(variables).map(([key, value]) => [key, value.value]),
353+
);
354+
}
346355
}

0 commit comments

Comments
 (0)