Most Spring for GraphQL applications use Spring Boot as a way to
auto-configure the required infrastructure for running GraphQL
applications.
This commit documents a minimal setup for Spring applications not
relying on Spring Boot. This assumes an existing infrastructure for a
Spring MVC application.
Closes gh-606
This commit adds support for GraphQL fragments with `GraphQlTester`.
Fragments allow to avoid repetition in GraphQL requests by reusing
field selection sets.
For example, the "releases" fragment can be reused in multiple queries
and make the overall document shorter:
```
query frameworkReleases {
project(slug: "spring-framework") {
name
...releases
}
}
query graphqlReleases {
project(slug: "spring-graphql") {
name
...releases
}
}
fragment releases on Project {
releases {
version
}
}
```
With this change, `GraphQlTester` accepts fragments as `String` or can
load them by their name using the configured `DocumentSource`, similarly
to the document support.
Closes gh-964
Prior to this commit, the `GraphQlHttpHandler` implementations would use
the JSON codecs configured in the web Framework (MVC or WebFlux) for
reading and writing GraphQL payloads as JSON documents.
This can cause issues in cases the application configures the JSON codec
in a way that makes it incompatible with the expected GraphQL documents.
For example, not serializing empty values and arrays.
This commit adds new constructors in `GraphQlHttpHandler`
implementations that can get a custom JSON codec for GraphQL payloads.
Closes gh-860
Prior to this commit, the WebFlux and WebMVC infrastructure would only
support subscriptions over the WebSocket and RSocket transports.
This commit adds the `GraphQlSseHandler` implementations for both web
frameworks. This handler will send GraphQL responses as as stream of
Server-Sent Events, over an HTTP response with the "text/event-stream"
content type.
This implementation only supports the "Distinct connections mode" and
will reject all operations other than Subscriptions.
This commit also enhances the `HttpGraphQlTransport` client transport to
support subscriptions over this new protocol.
Closes gh-309
Prior to this commit, GraphQL Request Observations would not record
errors as Observation errors, because with GraphQL errors can partially
affect the response and there can be multiple. Instead, an invalid
request (for example) would lead to a `"graphql.outcome", "REQUEST_ERROR"`
low cardinality KeyValue. In this case, developers would not know what
type of error occured nor if there were multiple.
This commit records all errors listed in the GraphQL as
Observation.Event on the request Observation. Such events are usually
handled by the tracing handler and are recorded as span annotations for
traces. Other `ObservationHandler` annotations can leverage events in a
different fashion.
Closes gh-859