Skip to content

Commit 02251b1

Browse files
committed
As per request
1 parent b8d2b25 commit 02251b1

4 files changed

Lines changed: 14 additions & 8 deletions

File tree

graphql/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const graphql = (client) => {
88
get: () => new Getter(client),
99
aggregate: () => new Aggregator(client),
1010
explore: () => new Explorer(client),
11-
raw: (query) => new Raw(client, query),
11+
raw: (query) => new Raw(client),
1212
};
1313
};
1414

graphql/journey.test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ describe("the graphql journey", () => {
1515

1616
test("graphql raw method", () => {
1717
return client.graphql
18-
.raw(" {Get{Article{title url wordCount}}}")
18+
.raw()
19+
.withQuery("{Get{Article{title url wordCount}}}")
1920
.do()
2021
.then(function (result) {
2122
expect(result.data.Get.Article.length).toEqual(3);

graphql/raw.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
export default class RawGraphQL {
22

3-
constructor(client, query) {
3+
constructor(client, quer) {
44
this.client = client;
55
this.errors = [];
6-
this.query = query;
76
}
87

8+
withQuery = (query) => {
9+
this.query = query;
10+
return this;
11+
};
12+
13+
914
validateIsSet = (prop, name, setter) => {
1015
if (prop == undefined || prop == null || prop.length == 0) {
1116
this.errors = [
@@ -19,7 +24,7 @@ export default class RawGraphQL {
1924
this.validateIsSet(
2025
this.query,
2126
"query",
22-
".raw(query)"
27+
".raw().withQuery(query)"
2328
);
2429
};
2530

@@ -37,4 +42,4 @@ export default class RawGraphQL {
3742
return this.client.query(this.query);
3843
};
3944
}
40-
}
45+
}

graphql/raw.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ test("a simple raw query", () => {
77

88
const expectedQuery = `{Get{Person{name}}}`;
99

10-
new Raw(mockClient, expectedQuery).do();
10+
new Raw(mockClient).withQuery(expectedQuery).do();
1111

1212
expect(mockClient.query).toHaveBeenCalledWith(expectedQuery);
1313
});
@@ -18,6 +18,6 @@ test("reject empty raw query", () => {
1818
};
1919

2020
new Raw(mockClient, "").do().catch(err => {
21-
expect(err).toMatchObject(new Error("invalid usage: query must be set - set with .raw(query)"));
21+
expect(err).toMatchObject(new Error("invalid usage: query must be set - set with .raw().withQuery(query)"));
2222
});
2323
});

0 commit comments

Comments
 (0)