Skip to content

Commit e2b504b

Browse files
author
Todd Berman
committed
add simple test
1 parent 261e314 commit e2b504b

3 files changed

Lines changed: 184 additions & 33 deletions

File tree

README.md

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# graphql-rxjava
2+
3+
#### Friendly warning: As GraphQL itself is currently a Working Draft, expect changes.
4+
5+
This is an execution strategy for [graphql-java](https://github.com/andimarek/graphql-java) that makes
6+
it easier to use rxjava's Observable.
7+
8+
# Table of Contents
9+
10+
- [Rx Hello World](#hello-world)
11+
- [License](#license)
12+
13+
14+
### Rx Hello World
15+
16+
This is the famous "hello world" in graphql-rxjava:
17+
18+
```java
19+
import graphql.schema.GraphQLObjectType;
20+
import graphql.schema.GraphQLSchema;
21+
22+
import graphql.execution.RxExecutionStrategy;
23+
import graphql.execution.RxExecutionResult;
24+
25+
import static graphql.Scalars.GraphQLString;
26+
import static graphql.schema.GraphQLFieldDefinition.newFieldDefinition;
27+
import static graphql.schema.GraphQLObjectType.newObject;
28+
29+
public class HelloWorld {
30+
31+
public static void main(String[] args) {
32+
33+
GraphQLObjectType queryType = newObject()
34+
.name("helloWorldQuery")
35+
.field(newFieldDefinition()
36+
.type(GraphQLString)
37+
.name("hello")
38+
.staticValue(Observable.just("world")))
39+
.build())
40+
.build();
41+
42+
GraphQLSchema schema = GraphQLSchema.newSchema()
43+
.query(queryType)
44+
.build();
45+
46+
Observable<?> result = ((RxExecutionResult)new GraphQL(schema, new RxExecutionStrategy()).execute("{hello}")).getDataObservable();
47+
48+
result.subscribe(System.out::println);
49+
// Prints: {hello=world}
50+
}
51+
}
52+
```
53+
54+
### Getting started
55+
56+
##### How to use the latest release with Gradle
57+
58+
Make sure `mavenCentral` is among your repos:
59+
60+
```groovy
61+
repositories {
62+
mavenCentral()
63+
}
64+
65+
```
66+
Dependency:
67+
68+
```groovy
69+
dependencies {
70+
compile 'com.graphql-java:graphql-rxjava:0.0.1'
71+
}
72+
73+
```
74+
75+
### License
76+
77+
graphql-rxjava is licensed under the MIT License. See [LICENSE](LICENSE) for details.
78+
79+
Copyright (c) 2015, NFL and [Contributors](https://github.com/nfl/graphql-java/graphs/contributors)
80+
81+
[graphql-js License](https://github.com/graphql/graphql-js/blob/master/LICENSE)

build.gradle

Lines changed: 32 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
import java.text.SimpleDateFormat
2-
31
apply plugin: 'java'
42
apply plugin: 'maven'
5-
apply plugin: 'maven-publish'
3+
apply plugin: 'signing'
64

75
sourceCompatibility = 1.8
86
version = '0.0.1'
@@ -51,42 +49,43 @@ artifacts {
5149
archives javadocJar
5250
}
5351

52+
signing {
53+
sign configurations.archives
54+
}
5455

55-
publishing {
56-
publications {
57-
graphqlJava(MavenPublication) {
58-
version version
59-
from components.java
56+
uploadArchives {
57+
repositories {
58+
mavenDeployer {
59+
beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
6060

61-
artifact sourcesJar {
62-
classifier "sources"
61+
repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2/") {
62+
authentication(userName: ossrhUsername, password: ossrhPassword)
6363
}
64-
artifact javadocJar {
65-
classifier "javadoc"
64+
65+
snapshotRepository(url: "https://oss.sonatype.org/content/repositories/snapshots/") {
66+
authentication(userName: ossrhUsername, password: ossrhPassword)
6667
}
67-
pom.withXml {
68-
asNode().children().last() + {
69-
resolveStrategy = Closure.DELEGATE_FIRST
70-
name 'graphql-rxjava'
71-
description 'GraphQL Rx-Java'
68+
69+
pom.project {
70+
name 'graphql-rxjava'
71+
description 'GraphQL Rx-Java'
72+
url "https://github.com/nfl/graphql-rxjava"
73+
scm {
7274
url "https://github.com/nfl/graphql-rxjava"
73-
scm {
74-
url "https://github.com/nfl/graphql-rxjava"
75-
connection "https://github.com/nfl/graphql-rxjava"
76-
developerConnection "https://github.com/nfl/graphql-rxjava"
77-
}
78-
licenses {
79-
license {
80-
name 'MIT'
81-
url 'https://github.com/nfl/graphql-rxjava/blob/master/LICENSE'
82-
distribution 'repo'
83-
}
75+
connection "https://github.com/nfl/graphql-rxjava"
76+
developerConnection "https://github.com/nfl/graphql-rxjava"
77+
}
78+
licenses {
79+
license {
80+
name 'MIT'
81+
url 'https://github.com/nfl/graphql-rxjava/blob/master/LICENSE'
82+
distribution 'repo'
8483
}
85-
developers {
86-
developer {
87-
id 'tberman'
88-
name 'Todd Berman'
89-
}
84+
}
85+
developers {
86+
developer {
87+
id 'tberman'
88+
name 'Todd Berman'
9089
}
9190
}
9291
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
package graphql;
2+
3+
4+
import graphql.execution.RxExecutionResult;
5+
import graphql.execution.RxExecutionStrategy;
6+
import graphql.schema.GraphQLObjectType;
7+
import graphql.schema.GraphQLSchema;
8+
import org.junit.Test;
9+
import rx.Observable;
10+
import rx.observers.TestSubscriber;
11+
12+
import java.util.Map;
13+
14+
import static graphql.Scalars.GraphQLString;
15+
import static graphql.schema.GraphQLFieldDefinition.newFieldDefinition;
16+
import static graphql.schema.GraphQLObjectType.newObject;
17+
import static org.junit.Assert.assertEquals;
18+
19+
public class HelloWorld {
20+
21+
public static void main(String[] args) {
22+
GraphQLObjectType queryType = newObject()
23+
.name("helloWorldQuery")
24+
.field(newFieldDefinition()
25+
.type(GraphQLString)
26+
.name("hello")
27+
.staticValue(Observable.just("world"))
28+
.build())
29+
.build();
30+
31+
GraphQLSchema schema = GraphQLSchema.newSchema()
32+
.query(queryType)
33+
.build();
34+
35+
Observable<?> result = ((RxExecutionResult)new GraphQL(schema, new RxExecutionStrategy()).execute("{hello}")).getDataObservable();
36+
37+
result.subscribe(System.out::println);
38+
}
39+
40+
@Test
41+
public void helloWorldTest() {
42+
GraphQLObjectType queryType = newObject()
43+
.name("helloWorldQuery")
44+
.field(newFieldDefinition()
45+
.type(GraphQLString)
46+
.name("hello")
47+
.staticValue(Observable.just("world"))
48+
.build())
49+
.build();
50+
51+
GraphQLSchema schema = GraphQLSchema.newSchema()
52+
.query(queryType)
53+
.build();
54+
55+
RxExecutionResult executionResult = (RxExecutionResult)new GraphQL(schema, new RxExecutionStrategy()).execute("{hello}");
56+
57+
Observable<Map<String, Object>> result = (Observable<Map<String, Object>>)executionResult.getDataObservable();
58+
59+
TestSubscriber<Map<String, Object>> testSubscriber = new TestSubscriber<>();
60+
61+
result.subscribe(testSubscriber);
62+
63+
testSubscriber.awaitTerminalEvent();
64+
65+
testSubscriber.assertNoErrors();
66+
67+
Map<String, Object> response = testSubscriber.getOnNextEvents().get(0);
68+
69+
assertEquals("world", response.get("hello"));
70+
}
71+
}

0 commit comments

Comments
 (0)