Skip to content

Commit

Permalink
feat(GraphQL): Provide ability to specify operationName (#1224)
Browse files Browse the repository at this point in the history
* Provide ability to specify operationName

---------

Co-authored-by: Ronald Van Ryswyk <ronald.van.ryswyk@positivecircularity.com>
  • Loading branch information
Harsgalt86 and Ronald Van Ryswyk committed Nov 27, 2023
1 parent d3e871d commit 4db6c34
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
Expand Up @@ -16,6 +16,9 @@ export interface GraphqlServiceOption extends BackendServiceOption {
/** What is the dataset, this is required for the GraphQL query to be built */
datasetName: string;

/** Used for defining the operation name when building the GraphQL query */
operationName?: string;

/**
* Extra query arguments that be passed in addition to the default query arguments
* For example in GraphQL, if we want to pass "userId" and we want the query to look like
Expand Down
15 changes: 15 additions & 0 deletions packages/graphql/src/services/__tests__/graphql.service.spec.ts
Expand Up @@ -418,6 +418,21 @@ describe('GraphqlService', () => {

expect(removeSpaces(query)).toBe(removeSpaces(expectation));
});

it('should include the operationName if provided', () => {
const expectation = `query foo {users(first:10, offset:0, userId:123, firstName:"John"){ totalCount, nodes{id,field1,field2}}}`;
const columns = [{ id: 'field1', field: 'field1', width: 100 }, { id: 'field2', field: 'field2', width: 100 }];
jest.spyOn(gridStub, 'getColumns').mockReturnValue(columns);

service.init({
datasetName: 'users',
operationName: 'foo',
extraQueryArguments: [{ field: 'userId', value: 123 }, { field: 'firstName', value: 'John' }],
}, paginationOptions, gridStub);
const query = service.buildQuery();

expect(removeSpaces(query)).toBe(removeSpaces(expectation));
});
});

describe('buildFilterQuery method', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/graphql/src/services/graphql.service.ts
Expand Up @@ -93,7 +93,7 @@ export class GraphqlService implements BackendService {
let columnDefinitions = this._columnDefinitions || [];
columnDefinitions = columnDefinitions.filter((column: Column) => !column.excludeFromQuery);

const queryQb = new QueryBuilder('query');
const queryQb = new QueryBuilder(`query ${this.options.operationName ?? ''}`);
const datasetQb = new QueryBuilder(this.options.datasetName);
const nodesQb = new QueryBuilder('nodes');

Expand Down

0 comments on commit 4db6c34

Please sign in to comment.