Skip to content

Commit 4198142

Browse files
committed
GraphQL module
1 parent 33a8eeb commit 4198142

File tree

27 files changed

+4242
-3
lines changed

27 files changed

+4242
-3
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,5 @@ javadoc
3131
*.mv.db
3232
versions
3333
out
34+
node
35+
node_modules

docs/asciidoc/modules.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Available modules are listed next.
1515

1616
=== Data
1717
* link:modules/flyway[Flyway]: Flyway migration module.
18+
* link:modules/graphql[GraphQL]: GraphQL Java module.
1819
* link:modules/hikari[HikariCP]: A high-performance JDBC connection pool.
1920
* link:modules/hibernate[Hibernate]: Hibernate ORM module.
2021
* link:modules/jdbi[Jdbi]: Jdbi module.

docs/asciidoc/modules/graphql.adoc

Lines changed: 253 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,253 @@
1+
== GraphQL
2+
3+
GraphQL using https://www.graphql-java.com[GraphQL Java] library.
4+
5+
=== Usage
6+
7+
1) Add the dependency:
8+
9+
[dependency, artifactId="jooby-graphql:GraphQL, jooby-jackson: JSON library"]
10+
.
11+
12+
2) Creates `schema.graphql` inside the `src/main/resource`
13+
14+
[source, graphql]
15+
----
16+
type Query {
17+
bookById(id: ID): Book
18+
}
19+
20+
type Book {
21+
id: ID
22+
name: String
23+
pageCount: Int
24+
author: Author
25+
}
26+
27+
type Author {
28+
id: ID
29+
firstName: String
30+
lastName: String
31+
}
32+
----
33+
34+
3) Install Jackson and GraphQL
35+
36+
.Java
37+
[source, java, role="primary"]
38+
----
39+
import io.jooby.json.JacksonModule;
40+
import io.jooby.graphql.GraphQLModule;
41+
42+
{
43+
install(new JacksonModule()); <1>
44+
45+
install(new GraphQLModule(
46+
RuntimeWiring.newRuntimeWiring() <2>
47+
.type(newTypeWiring("Query")
48+
.dataFetcher("bookById", fetchers.getBookByIdDataFetcher()))
49+
.type(newTypeWiring("Book")
50+
.dataFetcher("author", fetchers.getAuthorDataFetcher()))
51+
.build())
52+
);
53+
}
54+
----
55+
56+
.Kotlin
57+
[source, kt, role="secondary"]
58+
----
59+
import io.jooby.json.JacksonModule
60+
import io.jooby.graphql.GraphQLModule
61+
62+
{
63+
install(JacksonModule()) <1>
64+
65+
install(GraphQLModule(
66+
RuntimeWiring.newRuntimeWiring() <2>
67+
.type(newTypeWiring("Query")
68+
.dataFetcher("bookById", fetchers.getBookByIdDataFetcher()))
69+
.type(newTypeWiring("Book")
70+
.dataFetcher("author", fetchers.getAuthorDataFetcher()))
71+
.build())
72+
)
73+
}
74+
----
75+
76+
<1> Install Jackson
77+
<2> Install GraphQL, uses the `schema.graphql` and provide a `RuntimeWiring`
78+
79+
The GraphQL module generates a POST `/graphql` route.
80+
81+
=== Options
82+
83+
==== Async
84+
85+
The https://www.graphql-java.com[GraphQL Java] library executes queries in async mode. To turn-off
86+
the async mode:
87+
88+
.Async Mode
89+
[source, java, role="primary"]
90+
----
91+
import io.jooby.json.JacksonModule;
92+
import io.jooby.graphql.GraphQLModule;
93+
94+
{
95+
install(new GraphQLModule(...)
96+
.setAsync(false) <1>
97+
);
98+
}
99+
----
100+
101+
.Kotlin
102+
[source, kt, role="secondary"]
103+
----
104+
import io.jooby.json.JacksonModule
105+
import io.jooby.graphql.GraphQLModule
106+
107+
{
108+
install(GraphQLModule(...)
109+
.setAsync(false) <1>
110+
)
111+
}
112+
----
113+
114+
<1> Set async false
115+
116+
Please refer to https://www.graphql-java.com/documentation/v12/execution/#asynchronous-execution[Asynchronous execution] for more information.
117+
118+
==== Support HTTP Get
119+
120+
By default the module only install a HTTP POST route. If you want a HTTP GET:
121+
122+
.HTTP GET
123+
[source, java, role="primary"]
124+
----
125+
import io.jooby.json.JacksonModule;
126+
import io.jooby.graphql.GraphQLModule;
127+
128+
{
129+
install(new GraphQLModule(...)
130+
.setSupportHttpGet(true)
131+
);
132+
}
133+
----
134+
135+
.Kotlin
136+
[source, kt, role="secondary"]
137+
----
138+
import io.jooby.json.JacksonModule
139+
import io.jooby.graphql.GraphQLModule
140+
141+
{
142+
install(GraphQLModule(...)
143+
.setSupportHttpGet(true)
144+
)
145+
}
146+
----
147+
148+
==== Path
149+
150+
To change the default path: `/graphql` set the `graphql.path` property in your application configuration file.
151+
152+
=== IDE
153+
154+
Jooby comes with supports for two IDE:
155+
156+
- https://github.com/graphql/graphiql[GraphiQL]
157+
- https://github.com/prisma-labs/graphql-playground[GraphQL Playground]
158+
159+
They are provided as optional dependencies.
160+
161+
==== GraphIQL
162+
163+
1) Add the dependencies:
164+
165+
[dependency, artifactId="jooby-jackson: JSON library, jooby-graphql:GraphQL, jooby-graphiql: GraphIQL"]
166+
.
167+
168+
1) Install
169+
170+
.Java
171+
[source, java, role="primary"]
172+
----
173+
import io.jooby.json.JacksonModule;
174+
import io.jooby.graphql.GraphQLModule;
175+
import io.jooby.graphql.GraphiQLModule;
176+
177+
{
178+
install(new JacksonModule()); <1>
179+
180+
install(new GraphQLModule(...)); <2>
181+
182+
install(new GraphiQLModule()); <3>
183+
}
184+
----
185+
186+
.Kotlin
187+
[source, kt, role="secondary"]
188+
----
189+
import io.jooby.json.JacksonModule
190+
import io.jooby.graphql.GraphQLModule
191+
import io.jooby.graphql.GraphiQLModule
192+
193+
{
194+
install(JacksonModule()) <1>
195+
196+
install(GraphQLModule(...)) <2>
197+
198+
install(GraphiQLModule()) <3>
199+
}
200+
----
201+
202+
<1> Install Jackson
203+
<2> Install GraphQL
204+
<3> Install GraphiQL
205+
206+
https://github.com/graphql/graphiql[GraphiQL] should be up and running at `/graphql`.
207+
208+
==== GraphQL Playground
209+
210+
1) Add the dependencies:
211+
212+
[dependency, artifactId="jooby-jackson: JSON library, jooby-graphql:GraphQL, jooby-graphiql-playground: GraphQL Playground"]
213+
.
214+
215+
1) Install
216+
217+
.Java
218+
[source, java, role="primary"]
219+
----
220+
import io.jooby.json.JacksonModule;
221+
import io.jooby.graphql.GraphQLModule;
222+
import io.jooby.graphql.GraphQLPlaygroundModule;
223+
224+
{
225+
install(new JacksonModule()); <1>
226+
227+
install(new GraphQLModule(...)); <2>
228+
229+
install(new GraphQLPlaygroundModule()); <3>
230+
}
231+
----
232+
233+
.Kotlin
234+
[source, kt, role="secondary"]
235+
----
236+
import io.jooby.json.JacksonModule
237+
import io.jooby.graphql.GraphQLModule
238+
import io.jooby.graphql.GraphQLPlaygroundModule
239+
240+
{
241+
install(JacksonModule()) <1>
242+
243+
install(GraphQLModule(...)) <2>
244+
245+
install(GraphQLPlaygroundModule()) <3>
246+
}
247+
----
248+
249+
<1> Install Jackson
250+
<2> Install GraphQL
251+
<3> Install GraphQL Playground
252+
253+
https://github.com/prisma-labs/graphql-playground[GraphQL Playground] should be up and running at `/graphql`.

jooby/pom.xml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@
1212
<modelVersion>4.0.0</modelVersion>
1313
<artifactId>jooby</artifactId>
1414

15-
<properties>
16-
<shaded.package>io.jooby.internal.\$shaded</shaded.package>
17-
</properties>
1815
<build>
1916
<plugins>
2017
<plugin>

modules/jooby-bom/pom.xml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
<gradle-core.version>2.6</gradle-core.version>
3333
<gradle-plugins.version>0.9-rc-1</gradle-plugins.version>
3434
<gradle-tooling-api.version>2.6</gradle-tooling-api.version>
35+
<graphql-java.version>13.0</graphql-java.version>
3536
<guava.version>28.1-jre</guava.version>
3637
<guice.version>4.2.2</guice.version>
3738
<h2.version>1.4.200</h2.version>
@@ -194,6 +195,21 @@
194195
<artifactId>jooby-pac4j</artifactId>
195196
<version>${jooby.version}</version>
196197
</dependency>
198+
<dependency>
199+
<groupId>io.jooby</groupId>
200+
<artifactId>jooby-graphql</artifactId>
201+
<version>${jooby.version}</version>
202+
</dependency>
203+
<dependency>
204+
<groupId>io.jooby</groupId>
205+
<artifactId>jooby-graphiql</artifactId>
206+
<version>${jooby.version}</version>
207+
</dependency>
208+
<dependency>
209+
<groupId>io.jooby</groupId>
210+
<artifactId>jooby-graphql-playground</artifactId>
211+
<version>${jooby.version}</version>
212+
</dependency>
197213
<dependency>
198214
<groupId>io.jooby</groupId>
199215
<artifactId>jooby-guice</artifactId>
@@ -369,6 +385,11 @@
369385
<artifactId>unbescape</artifactId>
370386
<version>${unbescape.version}</version>
371387
</dependency>
388+
<dependency>
389+
<groupId>com.graphql-java</groupId>
390+
<artifactId>graphql-java</artifactId>
391+
<version>${graphql-java.version}</version>
392+
</dependency>
372393
<dependency>
373394
<groupId>org.hibernate</groupId>
374395
<artifactId>hibernate-core</artifactId>

0 commit comments

Comments
 (0)