GraphQL for Java with Spring Boot made easy.
APACHE-2.0 License
Bot releases are hidden (Show)
Published by berngp about 3 years ago
Published by paulbakker about 3 years ago
It is now possible to register a bean of type PreparsedDocumentProvider
, which the framework uses during query execution.
A PreparsedDocumentProvider
can be used to build a cache of queries that were previously parsed, which can improve query execution performance.
The developer is responsible for choosing and configuring a cache implementation. The following is an example using Caffeine
.
@SpringBootApplication
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
@Configuration
static class PreparsedDocumentProviderConfig {
private final Cache<String, PreparsedDocumentEntry> cache = Caffeine.newBuilder().maximumSize(250)
.expireAfterAccess(5, TimeUnit.MINUTES).recordStats().build();
@Bean
public PreparsedDocumentProvider preparsedDocumentProvider() {
return (executionInput, parseAndValidateFunction) -> {
Function<String, PreparsedDocumentEntry> mapCompute = key -> parseAndValidateFunction.apply(executionInput);
return cache.get(executionInput.getQuery(), mapCompute);
};
}
}
}
This fixes a bug that was introduced in 4.6.0
that caused lists of input objects nested inside an input object to not be deserialized correctly for @InputArgument
values.
Published by srinivasankavitha about 3 years ago
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 berngp over 3 years ago
Published by srinivasankavitha over 3 years ago