Skip to content

Commit 0cb0ca2

Browse files
committed
init commit
1 parent 2e5fdc3 commit 0cb0ca2

15 files changed

+319
-0
lines changed

.forceignore

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# List files or directories below to ignore them when running force:source:push, force:source:pull, and force:source:status
2+
# More information: https://developer.salesforce.com/docs/atlas.en-us.sfdx_dev.meta/sfdx_dev/sfdx_dev_exclude_source.htm
3+
#
4+
5+
package.xml
6+
7+
# LWC configuration files
8+
**/jsconfig.json
9+
**/.eslintrc.json
10+
11+
# LWC Jest
12+
**/__tests__/**

.gitignore

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# This file is used for Git repositories to specify intentionally untracked files that Git should ignore.
2+
# If you are not using git, you can delete this file. For more information see: https://git-scm.com/docs/gitignore
3+
# For useful gitignore templates see: https://github.com/github/gitignore
4+
5+
# Salesforce cache
6+
.sfdx/
7+
8+
# Logs
9+
logs
10+
*.log
11+
npm-debug.log*
12+
yarn-debug.log*
13+
yarn-error.log*
14+
15+
# Dependency directories
16+
node_modules/
17+
18+
# Eslint cache
19+
.eslintcache
20+
21+
# MacOS system files
22+
.DS_Store
23+
24+
# Windows system files
25+
Thumbs.db
26+
ehthumbs.db
27+
[Dd]esktop.ini
28+
$RECYCLE.BIN/
29+
30+
deploy-package

.vscode/launch.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"name": "Launch Apex Replay Debugger",
9+
"type": "apex-replay",
10+
"request": "launch",
11+
"logFile": "${command:AskForLogFileName}",
12+
"stopOnEntry": true,
13+
"trace": true
14+
}
15+
]
16+
}

.vscode/settings.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"salesforcedx-vscode-core.push-or-deploy-on-save.enabled": true,
3+
"search.exclude": {
4+
"**/node_modules": true,
5+
"**/bower_components": true,
6+
"**/.sfdx": true,
7+
"**/deploy-package": true
8+
},
9+
"salesforcedx-vscode-core.show-cli-success-msg": false
10+
}

README.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# apex-graphql-query
2+
3+
A simple library for building GraphQL queries. Currently only offers parital support.
4+
5+
## Example:
6+
7+
``` graphql
8+
{
9+
human(id: "1000") {
10+
name
11+
height
12+
address {
13+
city
14+
country
15+
}
16+
}
17+
}
18+
```
19+
20+
**Apex**
21+
22+
``` java
23+
GraphQLNode human = new GraphQLNode('human')
24+
.setArguments(new GraphQLArgument('id', '1000'))
25+
.add(new Object[]{
26+
'name',
27+
'height',
28+
new GraphQLNode('address')
29+
.add(new Object[]{ 'city', 'country' })
30+
});
31+
String qry = human.build();
32+
```
33+
34+
## Deployment
35+
36+
Choose your Adventure:
37+
38+
### A: Unlocked Package Install
39+
40+
--coming soon--
41+
42+
### B: From Source
43+
44+
1. `sfdx force:source:convert -d deploy-package`
45+
2. `sfdx force:mdapi:deploy -d deploy-package -u you@yourorg -w 1000`
46+
47+
## Contributing
48+
49+
Please do!

config/project-scratch-def.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"orgName": "charlesjonas Company",
3+
"edition": "Developer",
4+
"features": [],
5+
"settings": {
6+
"orgPreferenceSettings": {
7+
"s1DesktopEnabled": true
8+
}
9+
}
10+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
public class GraphQLArgument{
2+
public String name;
3+
public Object value; //string | GraphQLArgument | GraphQLArgument[]
4+
5+
public GraphQLArgument(String name, Object value){
6+
this.name = name;
7+
this.value = value;
8+
}
9+
10+
public string build(){
11+
String qry = this.name + ':';
12+
if(this.value instanceOf Integer || this.value instanceOf Decimal){
13+
qry += String.valueOf(this.value);
14+
}else if(this.value instanceOf DateTime){
15+
qry += '\"' + ((DateTime) this.value).format('yyyy-MM-dd\'T\'HH:mm:ss.SSS\'Z\'') + '\"';
16+
}else if(this.value instanceOf GraphQLArgument){
17+
qry += '{' + ((GraphQLArgument) this.value).build() + '}';
18+
}else if(this.value instanceOf GraphQLArgument[]){
19+
qry += '{';
20+
for(GraphQLArgument childParam : (GraphQLArgument[]) this.value){
21+
qry += childParam.build();
22+
}
23+
qry += '}';
24+
}else{ // default to string
25+
qry += '\"' + String.valueOf(this.value) + '\"';
26+
}
27+
return qry;
28+
}
29+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ApexClass xmlns="urn:metadata.tooling.soap.sforce.com" fqn="GraphQLInput">
3+
<apiVersion>45.0</apiVersion>
4+
<status>Active</status>
5+
</ApexClass>
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
public class GraphQLNode {
2+
public String name;
3+
public Boolean typeFrament; // transforms to "...on {NAME} {"
4+
public GraphQLArgument arg; //not sure this supports all use cases... might need to be GraphQLArgument | GraphQLArgument[]
5+
public Object[] children; //object or other nodes
6+
7+
public GraphQLNode(String name){
8+
this.typeFrament = false;
9+
this.children = new Object[]{};
10+
this.name = name;
11+
}
12+
13+
//returns the current node
14+
public GraphQLNode setArguments(GraphQLArgument arg){
15+
this.arg = arg;
16+
return this;
17+
}
18+
19+
//returns the current node
20+
public GraphQLNode add(Object children){
21+
if(children instanceOf Object[]){
22+
this.children.addAll((Object[])children);
23+
}else{
24+
this.children.add(children);
25+
}
26+
return this;
27+
}
28+
29+
public GraphQLNode setTypeFragment(Boolean isTypeFrag){
30+
this.typeFrament = isTypeFrag;
31+
return this;
32+
}
33+
34+
private string buildInner(){
35+
String qry = this.name;
36+
if(this.typeFrament){
37+
qry = '... on ' + this.name;
38+
}
39+
40+
if(this.arg != null){
41+
qry += '(' + this.arg.build() + ')';
42+
}
43+
qry += '{\n';
44+
for(Object child : this.children){
45+
if(child instanceOf GraphQLNode){
46+
qry += ((GraphQLNode) child).buildInner();
47+
}else{
48+
qry += ((String) child) + '\n';
49+
}
50+
}
51+
qry += '}\n';
52+
return qry;
53+
}
54+
55+
56+
public string build(){
57+
return '{\n' + this.buildInner() + '\n}';
58+
}
59+
60+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ApexClass xmlns="urn:metadata.tooling.soap.sforce.com" fqn="GraphQLQuery">
3+
<apiVersion>45.0</apiVersion>
4+
<status>Active</status>
5+
</ApexClass>

0 commit comments

Comments
 (0)