Skip to content

Commit e3331ca

Browse files
committed
initial version of new documentation
1 parent 2a16238 commit e3331ca

File tree

8 files changed

+920
-5
lines changed

8 files changed

+920
-5
lines changed

docs/README.rst

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

docs/contributions.rst

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
Contributions
2+
==============
3+
4+
Every contribution to make this project better is welcome: Thank you!
5+
6+
In order to make this a pleasant as possible for everybody involved, here are some tips:
7+
8+
* Respect the [Code of Conduct](#code-of-conduct)
9+
10+
* Before opening an Issue to report a bug, please try the latest development version. It can happen that the problem is already solved.
11+
12+
* Please use Markdown to format your comments properly. If you are not familiar with that: `Getting started with writing and formatting on GitHub <https://help.github.com/articles/getting-started-with-writing-and-formatting-on-github/>`_
13+
14+
* For Pull Requests:
15+
* Here are some `general tips <https://github.com/blog/1943-how-to-write-the-perfect-pull-request>`_
16+
17+
* Please be a as focused and clear as possible and don't mix concerns. This includes refactorings mixed with bug-fixes/features, see [Open Source Contribution Etiquette](http://tirania.org/blog/archive/2010/Dec-31.html)
18+
19+
* It would be good to add a automatic test. All tests are written in `Spock <http://spockframework.github.io/spock/docs/1.0/index.html>`_.
20+
21+
22+
Build and test locally
23+
----------------------
24+
25+
Just clone the repo and type
26+
27+
.. code-block:: sh
28+
29+
./gradlew build
30+
31+
In ``build/libs`` you will find the jar file.
32+
33+
Running the tests:
34+
35+
.. code-block:: sh
36+
37+
./gradlew test
38+
39+
Installing in the local Maven repository:
40+
41+
.. code-block:: sh
42+
43+
./gradlew install

docs/execution.rst

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
Execution
2+
============
3+
4+
5+
To execute a Query/Mutation against a Schema build a new ``GraphQL`` Object with the appropriate arguments and then call ``execute()``.
6+
7+
The result of a Query is a ``ExecutionResult`` Object with the result and/or a list of Errors.
8+
9+
Example: [GraphQL Test](src/test/groovy/graphql/GraphQLTest.groovy)
10+
11+
More complex examples: [StarWars query tests](src/test/groovy/graphql/StarWarsQueryTest.groovy)
12+
13+
14+
Mutations
15+
----------
16+
17+
A good starting point to learn more about mutating data in graphql is `http://graphql.org/learn/queries/#mutations <http://graphql.org/learn/queries/#mutations>`_.
18+
19+
In essence you need to define a ``GraphQLObjectType`` that takes arguments as input. Those arguments are what you can use to mutate your data store
20+
via the data fetcher invoked.
21+
22+
The mutation is invoked via a query like :
23+
24+
.. code-block:: graphql
25+
26+
mutation CreateReviewForEpisode($ep: Episode!, $review: ReviewInput!) {
27+
createReview(episode: $ep, review: $review) {
28+
stars
29+
commentary
30+
}
31+
}
32+
33+
You need to send in arguments during that mutation operation, in this case for the variables for `$ep` and `$review`
34+
35+
You would create types like this to handle this mutation :
36+
37+
.. code-block:: java
38+
GraphQLInputObjectType episodeType = GraphQLInputObjectType.newInputObject()
39+
.name("Episode")
40+
.field(newInputObjectField()
41+
.name("episodeNumber")
42+
.type(Scalars.GraphQLInt))
43+
.build();
44+
45+
GraphQLInputObjectType reviewInputType = GraphQLInputObjectType.newInputObject()
46+
.name("ReviewInput")
47+
.field(newInputObjectField()
48+
.name("stars")
49+
.type(Scalars.GraphQLString)
50+
.name("commentary")
51+
.type(Scalars.GraphQLString))
52+
.build();
53+
54+
GraphQLObjectType reviewType = newObject()
55+
.name("Review")
56+
.field(newFieldDefinition()
57+
.name("stars")
58+
.type(GraphQLString))
59+
.field(newFieldDefinition()
60+
.name("commentary")
61+
.type(GraphQLString))
62+
.build();
63+
64+
GraphQLObjectType createReviewForEpisodeMutation = newObject()
65+
.name("CreateReviewForEpisodeMutation")
66+
.field(newFieldDefinition()
67+
.name("createReview")
68+
.type(reviewType)
69+
.argument(newArgument()
70+
.name("episode")
71+
.type(episodeType)
72+
)
73+
.argument(newArgument()
74+
.name("review")
75+
.type(reviewInputType)
76+
)
77+
.dataFetcher(mutationDataFetcher())
78+
)
79+
.build();
80+
81+
GraphQLSchema schema = GraphQLSchema.newSchema()
82+
.query(queryType)
83+
.mutation(createReviewForEpisodeMutation)
84+
.build();
85+
86+
87+
Notice that the input arguments are of type ``GraphQLInputObjectType``. This is important. Input arguments can ONLY be of that type
88+
and you cannot use output types such as ``GraphQLObjectType``. Scalars types are consider both input and output types.
89+
90+
The data fetcher here is responsible for executing the mutation and returning some sensible output values.
91+
92+
.. code-block:: java
93+
94+
private DataFetcher mutationDataFetcher() {
95+
return new DataFetcher() {
96+
@Override
97+
public Review get(DataFetchingEnvironment environment) {
98+
Episode episode = environment.getArgument("episode");
99+
ReviewInput review = environment.getArgument("review");
100+
101+
// make a call to your store to mutate your database
102+
Review updatedReview = reviewStore().update(episode, review);
103+
104+
// this returns a new view of the data
105+
return updatedReview;
106+
}
107+
};
108+
}
109+
110+
Notice how it calls a data store to mutate the backing database and then returns a ``Review`` object that can be used as the output values
111+
to the caller.
112+
113+
Execution strategies
114+
--------------------
115+
116+
All fields in a SelectionSet are executed serially per default.
117+
118+
You can however provide your own execution strategies, one to use while querying data and one
119+
to use when mutating data.
120+
121+
.. code-block:: java
122+
123+
ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(
124+
2, /* core pool size 2 thread */
125+
2, /* max pool size 2 thread */
126+
30, TimeUnit.SECONDS,
127+
new LinkedBlockingQueue<Runnable>(),
128+
new ThreadPoolExecutor.CallerRunsPolicy());
129+
130+
GraphQL graphQL = GraphQL.newObject(StarWarsSchema.starWarsSchema)
131+
.queryExecutionStrategy(new ExecutorServiceExecutionStrategy(threadPoolExecutor))
132+
.mutationExecutionStrategy(new SimpleExecutionStrategy())
133+
.build();
134+
135+
136+
137+
When provided fields will be executed parallel, except the first level of a mutation operation.
138+
139+
See `specification <http://facebook.github.io/graphql/#sec-Normal-evaluation>`_ for details.
140+
141+
Alternatively, schemas with nested lists may benefit from using a BatchedExecutionStrategy and creating batched DataFetchers with get() methods annotated @Batched.

docs/getting_started.rst

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
Getting started
2+
===============
3+
4+
``graphql-java`` is requires at least Java 8.
5+
6+
7+
How to use the latest release with Gradle
8+
------------------------------------------
9+
10+
Make sure ``mavenCentral`` is among your repos:
11+
12+
.. code-block:: groovy
13+
14+
repositories {
15+
mavenCentral()
16+
}
17+
18+
19+
Dependency:
20+
21+
.. code-block:: groovy
22+
23+
dependencies {
24+
compile 'com.graphql-java:graphql-java:2.4.0'
25+
}
26+
27+
28+
How to use the latest release with Maven
29+
-----------------------------------------
30+
31+
Dependency:
32+
33+
.. code-block:: xml
34+
35+
<dependency>
36+
<groupId>com.graphql-java</groupId>
37+
<artifactId>graphql-java</artifactId>
38+
<version>2.4.0</version>
39+
</dependency>
40+
41+
42+
Hello World
43+
---------------
44+
45+
This is the famous "hello world" in ``graphql-java``:
46+
47+
.. literalinclude:: ../src/test/java/HelloWorld.java
48+
:language: java
49+
50+
51+
Using the latest development build
52+
-----------------------------------
53+
54+
The latest development build is available on Bintray.
55+
56+
Please look at `Latest Build <https://bintray.com/andimarek/graphql-java/graphql-java/_latestVersion>`_ for the
57+
latest version value.
58+
59+
60+
How to use the latest build with Gradle
61+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
62+
63+
Add the repositories:
64+
65+
.. code-block:: groovy
66+
67+
repositories {
68+
mavenCentral()
69+
maven { url "http://dl.bintray.com/andimarek/graphql-java" }
70+
}
71+
72+
73+
Dependency:
74+
75+
.. code-block:: groovy
76+
77+
dependencies {
78+
compile 'com.graphql-java:graphql-java:INSERT_LATEST_VERSION_HERE'
79+
}
80+
81+
82+
83+
How to use the latest build with Maven
84+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
85+
86+
87+
Add the repository:
88+
89+
.. code-block:: xml
90+
91+
<repository>
92+
<snapshots>
93+
<enabled>false</enabled>
94+
</snapshots>
95+
<id>bintray-andimarek-graphql-java</id>
96+
<name>bintray</name>
97+
<url>http://dl.bintray.com/andimarek/graphql-java</url>
98+
</repository>
99+
100+
Dependency:
101+
102+
.. code-block:: xml
103+
104+
<dependency>
105+
<groupId>com.graphql-java</groupId>
106+
<artifactId>graphql-java</artifactId>
107+
<version>INSERT_LATEST_VERSION_HERE</version>
108+
</dependency>
109+
110+
111+

docs/index.rst

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,51 @@
1-
This is a test
2-
==============
1+
Welcome to graphql-java
2+
=========================
3+
4+
5+
This is a GraphQL Java implementation based on the `specification <https://github.com/facebook/graphql>`_
6+
and the JavaScript `reference implementation <https://github.com/graphql/graphql-js>`_.
7+
8+
9+
**Status**: Version ``3.0.0`` is released.
10+
11+
The versioning follows `Semantic Versioning <http://semver.org>`_ since ``2.0.0``.
12+
13+
Make sure to check out the `awesome related projects <https://github.com/graphql-java/awesome-graphql-java>`_ built on ``graphql-java``.
14+
15+
16+
17+
Code of Conduct
18+
----------------
19+
20+
Please note that this project is released with a `Contributor Code of Conduct <https://github.com/graphql-java/graphql-java/blob/master/CODE_OF_CONDUCT.md>`_.
21+
By contributing to this project (commenting or opening PR/Issues etc) you are agreeing to follow this conduct, so please
22+
take the time to read it.
23+
24+
25+
Questions and discussions
26+
--------------------------
27+
28+
If you have a question or want to discuss anything else related to this project:
29+
30+
* Feel free to open a new `Issue <https://github.com/graphql-java/graphql-java/issues>`_
31+
32+
* We have a public chat room (Gitter.im) for graphql-java: https://gitter.im/graphql-java/graphql-java
33+
34+
35+
License
36+
--------
37+
38+
graphql-java is licensed under the MIT License.
39+
40+
.. toctree::
41+
:maxdepth: 1
42+
:caption: Documentation
43+
44+
Home <self>
45+
getting_started
46+
schema
47+
execution
48+
logging
49+
contributions
50+
351

docs/logging.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Logging
2+
========
3+
4+
Logging is done with `SLF4J <http://www.slf4j.org/>`_. Please have a look at the `Manual <http://www.slf4j.org/manual.html>`_ for details.
5+
The ``graphql-java`` root Logger name is ``graphql``.

0 commit comments

Comments
 (0)