Skip to content

Commit 6b7ccb3

Browse files
committed
Replace query builder to salesforce-queries
1 parent 5a3bf05 commit 6b7ccb3

File tree

6 files changed

+39
-116
lines changed

6 files changed

+39
-116
lines changed

.vscode/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
22
"editor.formatOnSave": true
3-
}
3+
}

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"bugs": "https://github.com/jpmonette/salesforce-graphql/issues",
55
"repository": "jpmonette/salesforce-graphql.git",
66
"homepage": "http://github.com/jpmonette/salesforce-graphql",
7-
"version": "0.0.2",
7+
"version": "0.0.3",
88
"main": "build/index.js",
99
"license": "MIT",
1010
"scripts": {
@@ -20,5 +20,8 @@
2020
"jest": "^22.4.3",
2121
"ts-jest": "^22.4.2",
2222
"typescript": "^2.8.1"
23+
},
24+
"dependencies": {
25+
"salesforce-queries": "^0.0.2"
2326
}
2427
}

src/__tests__/q.spec.ts

Lines changed: 0 additions & 23 deletions
This file was deleted.

src/index.ts

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
import Q from './q';
1+
import { SOQL } from 'salesforce-queries';
22

3-
function getFields(info) {
4-
const fields: string[] = [];
5-
info.fieldNodes.map(fieldNode => {
3+
function getFields(info: any) {
4+
const fields: Set<string> = new Set([]);
5+
info.fieldNodes.map((fieldNode: any) => {
66
if (fieldNode.selectionSet) {
7-
fieldNode.selectionSet.selections.map(value => {
8-
if (!value.selectionSet) fields.push(value.name.value);
7+
fieldNode.selectionSet.selections.map((value: any) => {
8+
if (!value.selectionSet) fields.add(value.name.value);
99
});
1010
}
1111
});
12-
return fields;
12+
return [...fields];
1313
}
1414

15-
function getWheres(info): any[] {
15+
function getWheres(info: any): any[] {
1616
const wheres: { field: string; value: string; operator: string }[] = [];
17-
info.fieldNodes.map(fieldNode => {
18-
fieldNode.arguments.map(val => {
17+
info.fieldNodes.map((fieldNode: any) => {
18+
fieldNode.arguments.map((val: any) => {
1919
const field = val.name.value;
2020
const value = val.value.value;
2121
if (field !== 'limit') {
@@ -26,10 +26,10 @@ function getWheres(info): any[] {
2626
return wheres;
2727
}
2828

29-
function getLimit(info): number | void {
29+
function getLimit(info: any): number | void {
3030
let limit;
31-
info.fieldNodes.map(fieldNode => {
32-
fieldNode.arguments.map(value => {
31+
info.fieldNodes.map((fieldNode: any) => {
32+
fieldNode.arguments.map((value: any) => {
3333
if (value.name.value === 'limit') {
3434
limit = value.value.value;
3535
}
@@ -38,17 +38,21 @@ function getLimit(info): number | void {
3838
return limit;
3939
}
4040

41+
export interface Options {
42+
conn: any;
43+
}
44+
4145
class Salesforce {
4246
conn: any;
4347

44-
constructor(props) {
45-
console.log('CONSTRUCTOR')
48+
constructor(props: Options) {
4649
this.conn = props.conn;
4750
}
4851

49-
public query = (parent: { key: string }, info) => {
50-
console.log('BEFORE')
51-
const queryBuilder = new Q(info.returnType.ofType || info.returnType).select(getFields(info));
52+
public query = (parent: { [key: string]: string }, info: any) => {
53+
const queryBuilder = new SOQL(info.returnType.ofType || info.returnType).select(
54+
getFields(info)
55+
);
5256
const limit = getLimit(info);
5357

5458
if (limit) {
@@ -60,9 +64,8 @@ class Salesforce {
6064
wheres.map(({ field, operator, value }) => queryBuilder.where(field, operator, value));
6165
Object.keys(parent).map((key: string) => queryBuilder.where(key, '=', parent[key]));
6266
const query = queryBuilder.build();
63-
console.log('\nExecuting', query);
6467
return this.conn.query(query);
6568
};
6669
}
6770

68-
export { Salesforce };
71+
export { Salesforce };

src/q.ts

Lines changed: 0 additions & 71 deletions
This file was deleted.

tsconfig.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,17 @@
33
"module": "commonjs",
44
"outDir": "build",
55
"target": "es2016",
6+
"declaration": true,
7+
"alwaysStrict": true,
8+
"sourceMap": true,
9+
"noImplicitAny": true,
10+
"noImplicitReturns": true,
11+
"noImplicitThis": true,
12+
"noUnusedLocals": true,
13+
"noUnusedParameters": true,
14+
"strictFunctionTypes": true,
15+
"strictPropertyInitialization": true,
16+
"strictNullChecks": true,
617
"lib": ["esnext","dom"]
718
},
819
"include": ["src/**/*"],

0 commit comments

Comments
 (0)