Skip to content
This repository was archived by the owner on Oct 25, 2021. It is now read-only.

Commit 3d8d478

Browse files
committed
first commit
0 parents  commit 3d8d478

File tree

11 files changed

+360
-0
lines changed

11 files changed

+360
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
build
2+
.gradle
3+
.idea/

build.gradle

Whitespace-only changes.

gradle/wrapper/gradle-wrapper.jar

53.1 KB
Binary file not shown.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#Sat Nov 03 15:43:57 AEDT 2018
2+
distributionBase=GRADLE_USER_HOME
3+
distributionPath=wrapper/dists
4+
zipStoreBase=GRADLE_USER_HOME
5+
zipStorePath=wrapper/dists
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-4.8-all.zip

gradlew

Lines changed: 172 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gradlew.bat

Lines changed: 84 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
plugins {
2+
id 'java'
3+
}
4+
5+
group 'com.graphql-java'
6+
version '1.0-SNAPSHOT'
7+
8+
sourceCompatibility = 1.8
9+
10+
repositories {
11+
mavenCentral()
12+
}
13+
14+
dependencies {
15+
compile "org.springframework.boot:spring-boot-autoconfigure:2.1.0.RELEASE"
16+
compile project(':graphql-java-spring-web')
17+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package graphql;
2+
3+
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
4+
import org.springframework.context.annotation.ComponentScan;
5+
import org.springframework.context.annotation.Configuration;
6+
7+
@Configuration
8+
@ConditionalOnWebApplication
9+
@ComponentScan("graphql")
10+
public class GraphQLEndpointConfiguration {
11+
12+
13+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
plugins {
2+
id 'java'
3+
}
4+
5+
group 'com.graphql-java'
6+
version '1.0-SNAPSHOT'
7+
8+
sourceCompatibility = 1.8
9+
10+
repositories {
11+
mavenCentral()
12+
}
13+
14+
dependencies {
15+
compile "org.springframework:spring-web:5.1.2.RELEASE"
16+
compile "com.graphql-java:graphql-java:11.0"
17+
testCompile group: 'junit', name: 'junit', version: '4.12'
18+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package graphql;
2+
3+
4+
import org.springframework.beans.factory.annotation.Autowired;
5+
import org.springframework.http.MediaType;
6+
import org.springframework.web.bind.annotation.RequestBody;
7+
import org.springframework.web.bind.annotation.RequestMapping;
8+
import org.springframework.web.bind.annotation.RequestMethod;
9+
import org.springframework.web.bind.annotation.RestController;
10+
11+
import java.util.LinkedHashMap;
12+
import java.util.Map;
13+
14+
@RestController
15+
public class GraphQLResource {
16+
17+
@Autowired
18+
private GraphQL graphql;
19+
20+
21+
@RequestMapping(value = "${graphql.url}", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
22+
public Map<String, Object> graphql(@RequestBody Map<String, Object> body) {
23+
String query = (String) body.get("query");
24+
if (query == null) {
25+
query = "";
26+
}
27+
String operationName = (String) body.get("operationName");
28+
Map<String, Object> variables = (Map<String, Object>) body.get("variables");
29+
if (variables == null) {
30+
variables = new LinkedHashMap<>();
31+
}
32+
return executeGraphqlQuery(query, operationName, variables);
33+
}
34+
35+
private Map<String, Object> executeGraphqlQuery(String query, String operationName, Map<String, Object> variables) {
36+
ExecutionInput executionInput = ExecutionInput.newExecutionInput()
37+
.query(query)
38+
.operationName(operationName)
39+
.variables(variables)
40+
.build();
41+
return this.graphql.execute(executionInput).toSpecification();
42+
}
43+
44+
}

0 commit comments

Comments
 (0)