Skip to content

Commit 3ba186c

Browse files
docs(graphql-java-kickstart#5): update readme, minor javadoc corrections
1 parent d2edc09 commit 3ba186c

File tree

2 files changed

+60
-3
lines changed

2 files changed

+60
-3
lines changed

README.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,62 @@ graphql:
398398
By default GraphQL tools uses the location pattern `**/*.graphqls` to scan for GraphQL schemas on the classpath.
399399
Use the `schemaLocationPattern` property to customize this pattern.
400400

401+
## GraphQL Annotations
402+
403+
https://github.com/Enigmatis/graphql-java-annotations
404+
405+
The schema will be built using the GraphQL Annotations library in a code-first approach - instead of writing it
406+
manually, the schema will be constructed based on the Java code. Please see the documentation of the GraphQL Annotations
407+
library for a detailed documentation of the available annotations. This readme focuses on how GraphQL Annotations -
408+
GraphQL Spring Boot Starter integration works.
409+
410+
**Note:** *Although the GraphQL Annotations Starter has a dependency on GraphQL Java Tools and uses some interfaces from
411+
that project, it will ignore schema definition files. It is not possible to combine schema- and code-first approaches.*
412+
413+
### Configuration
414+
415+
```
416+
graphql:
417+
annotations:
418+
base-package: com.example.graphl.schema # required
419+
always-prettify: true #true is the default value, no need to specify it
420+
```
421+
422+
The most important parameter is the base package. The starter will look for schema-relevant classes in the specified
423+
package and its subpackages. `always-prettify` will "prettify" getter/setter methods - the get/set/is prefix will be
424+
removed from GraphQL fields automatically.
425+
426+
### Root resolvers, directives, type extensions
427+
428+
The root resolvers must be marked by the `GraphQLQueryResolver`, `GraphQLMutationResolver` and `GraphQLSubscription`
429+
interfaces (from the GraphQL Java Tools library).
430+
431+
**Important:**
432+
433+
Unlike GraphQL Java Tools, GraphQL Annotations only supports *one* of them each. Furthermore, GraphQL Annotations
434+
only accepts a *class* as input, *not an instance*. It will either create a new instance of the class itself, or use
435+
static methods. This means that Spring dependency injection will not work in the usual way. The companion example
436+
project (which can be found in the [samples](https://github.com/graphql-java-kickstart/samples) repository)
437+
demonstrates possible workarounds for this issue.
438+
439+
`GraphQLDirectiveDefinition` and `GraphQLTypeExtension`-annotated classes are subject to the same limitation regarding
440+
dependency injection - but there can be any number of them.
441+
442+
### Custom scalars and type functions
443+
444+
Custom scalars can be defined in the same way as in the case of using GraphQL Java Tools - just define the
445+
`GraphQLScalarType` beans.
446+
447+
The starter will also pick up `TypeFunction` beans and pass them to the schema builder.
448+
449+
In these cases the actual beans will be used, not just the classes. Spring dependency injection works as usual.
450+
451+
### Custom Relay and GraphQL Annotation Processor
452+
453+
It is possible to define a bean implementing `Relay` and/or `GraphQLAnnotations`. If present, these will be passed to
454+
the schema builder. Spring dependency injection works as usual. Note that GraphQL Annotations provides default
455+
implementation for these which should be sufficient is most cases.
456+
401457
# Tracing and Metrics
402458
403459
[Apollo style tracing](https://github.com/apollographql/apollo-tracing) along with two levels of metrics based on them are currently configurable.

graphql-kickstart-spring-boot-autoconfigure-graphql-annotations/src/main/java/graphql/kickstart/graphql/annotations/GraphQLAnnotationsAutoConfiguration.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,8 @@ private void setQueryResolverClass(
141141
* {@link ReflectionsException} if there are no types with annotations in the specified package.
142142
* @param reflections the {@link Reflections} instance
143143
* @param annotation the annotation class
144-
* @return The set of classes annotated with that annotations, or empty set if no annotations found.
144+
* @return The set of classes annotated with the specified annotation, or an empty set if no annotated classes
145+
* found.
145146
*/
146147
private Set<Class<?>> getTypesAnnotatedWith(
147148
final Reflections reflections,
@@ -155,8 +156,8 @@ private Set<Class<?>> getTypesAnnotatedWith(
155156
}
156157

157158
/**
158-
* Workaround for a bug in Reflections - {@link Reflections#getSubTypesOf(Class)} )} will throw a
159-
* {@link ReflectionsException} if there are no class in the specified package.
159+
* Workaround for a bug in Reflections - {@link Reflections#getSubTypesOf(Class)} will throw a
160+
* {@link ReflectionsException} if there are no classes in the specified package.
160161
* @param reflections the {@link Reflections} instance
161162
* @param aClass a class
162163
* @return The set of classes that are subclasses of the specified class, or empty set if no annotations found.

0 commit comments

Comments
 (0)