GraphQL for Java with Spring Boot made easy.
APACHE-2.0 License
Bot releases are visible (Hide)
Published by github-actions[bot] over 3 years ago
Published by github-actions[bot] over 3 years ago
Published by github-actions[bot] over 3 years ago
Published by github-actions[bot] over 3 years ago
In this release, we added support for Webflux. Webflux support has been one of the most requested features and is now available.
The support includes the following:
DgsReactiveQueryExecutor
, which is the DgsQueryExecutor
you know and love, but each result is wrapped in a Mono
. Internally all query processing is non-blocking. In a Webflux application, both the DgsReactiveQueryExecutor
and DgsQueryExecutor
will be available for injection, so that you can still use the blocking one for things like tests. Internally the Webflux integration uses DgsReactiveQueryExecutor
./graphql
HTTP handler, GraphiQL support and a Websocket endpoint for subscriptions. These endpoints are implemented using Webflux, and the module does not require any webmvc
modules.graphql-dgs-spring-boot-starter
if you're using DGS in a Webflux environment.The Webflux integration is obviously a big feature, and we could be missing certain issues and corner cases. Please try it out and report any issues! PRs are always welcome as well.
An example application is available as well: https://github.com/netflix/dgs-examples-webflux
DgsRequestData
.In a recent release we added DgsRequestData
to the DgsContext
. We designed this to be usable both from WebMVC and Webflux, by using the WebRequest
type from Spring's web
module. However, this turned out to be a mistake. Webflux uses a ServerRequest
type instead.
To cleanly fix this issue and not create a suboptimal dependency graph, we made a small breaking change to the API. DgsRequestData
is now an interface, with two implementations: DgsWebMvcRequestData
and DgsReactiveRequestData
. Only if you need access to either WebRequest
or ServerRequest
in your data fetcher, you need to type check and cast to the correct implementation to get access to WebRequest
or ServerRequest
.
If you were using WebRequest
from DgsRequestData
, your code will no longer compile with this release without adding the extra type cast. This should be an easy fix but is the reason we decided on a major release.
As explained in the previous paragraph, we had to introduce a change to the DgsRequestData
type. Because this is an API type, this requires a major release. Since this will only impact very specific use cases, it will likely not cause any changes for most users.
We also took the opportunity to remove the previously deprecated DgsContextBuilder
. Remember that this interface has long been obsolete because we have the custom context concept.
Aside from these two changes, there are no other changes affecting backward compatibility. The Webflux modules are optional and don't impact existing WebMVC users.
Custom scalars can be used in input types in GraphQL. Let's take the example of a DateRange
scalar that represents a "from" and "to" date.
In Java, we want to represent this as a DateRange class that takes a LocalDate
for the from
and to
fields.
When generating a query API we want to be use the API as follows:
new GraphQLQueryRequest(
ReviewsGraphQLQuery.newRequest().dateRange(new DateRange(LocalDate.of(2020, 1, 1), LocalDate.now())).build(),
new ReviewsProjectionRoot().submittedDate().starScore(), scalars);
When sending the query, we somehow have to serialize this DateRange
though.
There are many ways to represent a date, so how do we make sure that we use the same representation as the server expects?
In this release we added an optional scalars
argument to the GraphQLQueryRequest
constructor.
This is a Map<Class<?>, Coercing<?,?>
that maps the Java class representing the input to an actual Scalar implementation.
This way you can re-use exactly the same serialization code that you already have for your scalar implementation or one of the existing ones from for example the graphql-dgs-extended-scalars
module.
Published by github-actions[bot] over 3 years ago
Published by github-actions[bot] over 3 years ago
In this release, we added support for Webflux. Webflux support has been one of the most requested features and is now available.
The support includes the following:
DgsReactiveQueryExecutor
, which is the DgsQueryExecutor
you know and love, but each result is wrapped in a Mono
. Internally all query processing is non-blocking. In a Webflux application, both the DgsReactiveQueryExecutor
and DgsQueryExecutor
will be available for injection, so that you can still use the blocking one for things like tests. Internally the Webflux integration uses DgsReactiveQueryExecutor
./graphql
HTTP handler, GraphiQL support and a Websocket endpoint for subscriptions. These endpoints are implemented using Webflux, and the module does not require any webmvc
modules.graphql-dgs-spring-boot-starter
if you're using DGS in a Webflux environment.DgsRequestData
.In a recent release we added DgsRequestData
to the DgsContext
. We designed this to be usable both from WebMVC and Webflux, by using the WebRequest
type from Spring's web
module. However, this turned out to be a mistake. Webflux uses a ServerRequest
type instead.
To cleanly fix this issue and not create a suboptimal dependency graph, we made a small breaking change to the API. DgsRequestData
is now an interface, with two implementations: DgsWebMvcRequestData
and DgsReactiveRequestData
. Only if you need access to either WebRequest
or ServerRequest
in your data fetcher, you need to type check and cast to the correct implementation to get access to WebRequest
or ServerRequest
.
If you were using WebRequest
from DgsRequestData
, your code will no longer compile with this release without adding the extra type cast. This should be an easy fix but is the reason we decided on a major release.
As explained in the previous paragraph, we had to introduce a change to the DgsRequestData
type. Because this is an API type, this requires a major release. Since this will only impact very specific use cases, it will likely not cause any changes for most users.
We also took the opportunity to remove the previously deprecated DgsContextBuilder
. Remember that this interface has long been obsolete because we have the custom context concept.
Aside from these two changes, there are no other changes affecting backward compatibility. The Webflux modules are optional and don't impact existing WebMVC users.
The Webflux integration is obviously a big feature, and we could be missing certain issues and corner cases. Please try it out and report any issues! PRs are always welcome as well.
To test with an RC release, add the https://netflixoss.jfrog.io/artifactory/maven-oss-candidates/
to your build configuration.
gradle.build
repositories {
mavenCentral()
maven {
url = uri("https://netflixoss.jfrog.io/artifactory/maven-oss-candidates/")
}
}
dependencies {
implementation platform("com.netflix.graphql.dgs:graphql-dgs-platform-dependencies:4.0.0-rc.1")
}
gradle.build.kts
repositories {
mavenCentral()
maven {
url = uri("https://netflixoss.jfrog.io/artifactory/maven-oss-candidates/")
}
}
dependencies {
implementation(platform("com.netflix.graphql.dgs:graphql-dgs-platform-dependencies:4.0.0-rc.1"))
}
Published by github-actions[bot] over 3 years ago
We are reverting the "Rename packages from autoconfig -> autoconfigure" (#309) to avoid introducing breaking changes on a minor release.
Published by srinivasankavitha over 3 years ago
Published by srinivasankavitha over 3 years ago
Candidate release to test query complexity metric.
Published by srinivasankavitha over 3 years ago
Creating a candidate release to test metrics.
Published by paulbakker over 3 years ago
Optional
input argumentsInput arguments are often defined as optional in schemas.
Your datafetcher code needs to null-check arguments to check if they were provided.
Instead of null-checks you can wrap an input argument in an Optional.
public List<Show> shows(@InputArgument(collectionType = ShowFilter.class) Optional<ShowFilter> filter)
You do need to provide the type in the collectionType
argument when using complex types, similar to using lists.
If the argument is not provided, the value will be Optional.empty()
.
It's a matter of preference to use Optional
or not.
If you use scalars from the graphql-java-extended-scalars
library, such as Long
, we now have a convenient way to register the scalars to your DGS. Simply add the graphql-dgs-extended-scalars
module to your Gradle/Maven build and the scalars will be automatically registered.
More information about further configuration knobs can be found in the docs.
You can now configure the location of your GraphQL schema files via the dgs.graphql.schema-locations
property.
By default it will attempt to load them from the schema
directory via the Classpath, i.e. using classpath*:schema/**/*.graphql*
.
Let's go through an example, let's say you want to change the directory from being schema
to graphql-schemas
,
you would define your configuration as follows:
dgs:
graphql:
schema-locations:
- classpath*:graphql-schemas/**/*.graphql*
Now, if you want to add additional locations to look for the GraphQL Schema files you an add them to the list.
For example, let's say we want to also look into your graphql-experimental-schemas
:
dgs:
graphql:
schema-locations:
- classpath*:graphql-schemas/**/*.graphql*
- classpath*:graphql-experimental-schemas/**/*.graphql*
Published by github-actions[bot] over 3 years ago
We now have a BOM/Gradle platform defined for the framework. A BOM helps to align versions of dependencies.
We have two different BOM definitions, graphql-dgs-platform-dependencies
and graphql-dgs-platform
. The latter only defines version alignment for the DGS modules. graphql-dgs-platform-dependencies
also defines versions for the dependencies of the DGS framework, such as Spring, Jackson and Kotlin.
In a DGS project, you can use the BOM as follows.
dependencies {
//DGS BOM/platform dependency. This is the only place you set version of DGS
implementation(platform("com.netflix.graphql.dgs:graphql-dgs-platform-dependencies:3.10.2"))
//DGS dependencies. We don't have to specify a version here!
implementation("com.netflix.graphql.dgs:graphql-dgs-spring-boot-starter")
implementation("com.netflix.graphql.dgs:graphql-dgs-subscriptions-websockets-autoconfigure")
//Additional Jackson dependency. We don't need to specify a version, because Jackson is part of the BOM/platform definition.
implementation("com.fasterxml.jackson.datatype:jackson-datatype-joda")
//Other dependencies
}
Notice that the version is only specified on the platform dependency, and not on the graphql-dgs-spring-boot-starter
and graphql-dgs-subscriptions-websockets-autoconfigure
. The BOM will make sure that all dependencies are the same version. Additionally, we can use the DGS chosen version of some dependencies as well, such as Jackson.
Note that the versions in the platform are recommendations. The versions can be overridden by the user, or by other platforms you might be using (such as the Spring dependency-management plugin).
We've added shorthand annotations for defining @DgsData
fields on Query/Mutation/Subscription.
The following datafetcher definitions are all equivalent.
@DgsData(parentType = "Query", field = "shows")
public List<Show> shows() { .... }
// The "field" argument is omitted. It uses the method name as the field name.
@DgsData(parentType = "Query")
public List<Show> shows() { .... }
// The parentType is "Query", the field name is derived from the method name.
@DgsQuery
public List<Show> shows() { .... }
// The parentType is "Query", the field name is explicitly specified.
@DgsQuery(field = "shows")
public List<Show> shows() { .... }
The same works for @DgsMutation
and @DgsSubscription
.
Thanks to @iuliiasobolevska you can now use the @RequestParam
annotation as a datafetcher argument.
This is very similar to the @RequestHeader
we previously added, but gets a request parameter.
@DgsQuery
public List<Show> shows(@RequestParam String someParameter) { ... }
Enjoy the release, and we already have a number of features lined up for another release that will follow soon!
Published by berngp over 3 years ago
Published by github-actions[bot] over 3 years ago
Published by github-actions[bot] over 3 years ago
Published by github-actions[bot] over 3 years ago
Published by github-actions[bot] over 3 years ago