Commit Graph

39 Commits

Author SHA1 Message Date
Brian Clozel
fdf446f3e6 Load multiple GraphQL schema files
Prior to this commit, the `spring.graphql.schema.location` would only
allow a single file as the source for the GraphQL schema.

This commit changes this configuration to
`spring.graphql.schema.locations` so that it accepts actual locations
(folders) and scans for `*.graphqls` files in those locations. All files
are parsed and merged as a single GraphQL `TypeDefinitionRegistry`.

Closes gh-56
2021-06-29 21:27:18 +02:00
Brian Clozel
eef61843d3 Add property for GraphiQL UI path
This commit adds a new `spring.graphql.graphiql.path` configuration
property for setting the path to the GraphiQL UI page.

This change requires updates in the static HTML page to link the
JavaScript fetcher back to the actual GraphQL API endpoint.

Closes gh-70
2021-06-29 13:52:08 +02:00
Rossen Stoyanchev
de234c94c4 Decouple GraphQlTester from Web details
Closes gh-65
2021-06-26 05:16:35 +01:00
Rossen Stoyanchev
0ce48dc978 Turn off auto-formatting in Boot starter tests 2021-06-16 10:59:28 +01:00
Rossen Stoyanchev
43f9e34c81 Turn off auto-formatting where it reduces readability 2021-06-15 14:01:52 +01:00
Brian Clozel
f8b90b592d Apply Spring JavaFormat to Spring GraphQL Boot starter
This commit applies the build conventions to the Spring Boot GraphQL
starter module and fixes all formatting issues.

See gh-54
2021-06-02 14:30:00 +02:00
Brian Clozel
847c10be27 Add GraphQlTester test auto-configuration
This commit introduces the auto-configuration infrastructure for testing
Spring GraphQL applications with mock/embedded servers.

The new `@AutoConfigureGraphQlTester` annotation can contribute a
`GraphQlTester` bean to the test context for testing the application.

Closes gh-46
2021-05-31 21:35:54 +02:00
Rossen Stoyanchev
56917d8d83 ThreadLocal context propagation for DataFetcher's
The WebMvc starter now supports propagation of ThreadLocal values
extracted at the level of the HTTP handler.

Closes gh-53
2021-05-28 19:32:48 +01:00
Rossen Stoyanchev
ca18d03244 Add builder for WebGraphQlHandler
To allow adding more options when creating a WebGraphQlHandler.

See gh-53
2021-05-28 19:32:28 +01:00
Rossen Stoyanchev
eb88697b83 Polishing 2021-05-21 15:34:58 +01:00
Rossen Stoyanchev
cd8f4b672f Fix NPE on errors without a path
Errors that originate from GraphQL itself don't seem to have a path.
2021-05-21 15:34:58 +01:00
Rossen Stoyanchev
24bf029b02 Replace custom WebSocket handler mapping logic
Closes gh-35
2021-05-21 15:03:37 +01:00
Rossen Stoyanchev
484fb932ef Replace QL with Ql for consistency with Spring naming 2021-05-14 21:32:54 +01:00
Rossen Stoyanchev
20b8a664bd Move DataFetcherExceptionResolver to execution
DataFetcherExceptionResolver and ErrorType are better in the
execution package next to where they're used.
2021-05-14 18:29:43 +01:00
Rossen Stoyanchev
1a4ef20f8a Add actual Javadoc to package-info 2021-05-14 16:26:01 +01:00
Rossen Stoyanchev
b1a4016132 Rename support package to execution
The package contains classes to help configure and invoke graphql.GraphQL
both of which are request execution.
2021-05-14 10:45:36 +01:00
Rossen Stoyanchev
3792de375a Add DataFetcherExceptionResolver mechanism
- Support for one or more DataFetcherExceptionResolver beans
- ErrorType enum with common error categories
- Default handling of unresolved exceptions as ErrorType.INTERNAL_ERROR

Closes gh-51
2021-05-14 10:15:19 +01:00
Rossen Stoyanchev
44a034ef3d Refine use of "query" in type and method names
Following revisions in the spec
https://github.com/graphql/graphql-spec/pull/777, this commit applies
similar changes to type and method names where feasible.

The chief exception for now is the use of "query" for request input
since that is what it is called in the JSON for GraphQL over HTTP.
2021-05-12 09:50:03 +01:00
Brian Clozel
f70e552c6a Change default schema location to /graphql/schema.graphqls
This commit changes the default location for the GraphQL schema from
`classpath:schema.graphqls` to `classpath:/graphql/schema.graphqls`.

We're also adding `.graphqlconfig` files that are leveraged by a GraphQL
JS plugin in IntelliJ IDEA.

Closes gh-44
2021-05-11 15:52:58 +02:00
Brian Clozel
2d97e326e2 Add schema printer endpoint
This commit auto-configures a web endpoint that prints the GraphQL
schema of the application.

Closes gh-13
2021-05-11 11:54:17 +02:00
Brian Clozel
ee51f26755 Revisit GraphQL metrics
Prior to this commit, we introduced a basic implementation for GraphQL
metrics with Spring GraphQL. The main problem was that we were tracking
the GraphQL queries themselves and those are good candidates for
tags cardinality explosion.

This commit revisits the metrics arrangement and introduces:

* `graphql.request` as the main metric; this tracks the execution of a
  single request (i.e. multiple queries)
* `graphql.datafetcher` for tracking data fetching operations.
* `graphql.error` for counting errors.

Closes gh-19
2021-05-10 10:41:57 +02:00
Rossen Stoyanchev
f93c46eee3 WebInterceptor contract revision
WebInterceptor now uses delegation, forming a chain of interceptors
followed by a GraphQLService at the end to invoke graphql.GraphQL.

Closes gh-49
2021-04-30 21:26:26 +01:00
Rossen Stoyanchev
e5a92a310d Introduce GraphQLSource
A pluggable abstraction to encapsulate the way GraphQL is initialized and
the way it is sourced at runtime.

Closes gh-48
2021-04-28 18:53:04 +01:00
Rossen Stoyanchev
b6cc9e4dd5 Remove spring-graphql-core module
Move its contents into the spring-graphql module.
2021-04-26 21:55:30 +01:00
Rossen Stoyanchev
403019521c Rename spring-graphql-web to spring-graphql
Re-purpose spring-graphql-web to be more general than just web and add
org.springframework.web as a top-level package for web support.
2021-04-26 21:42:36 +01:00
Rossen Stoyanchev
1e619263d2 Reactor DataFetcher support
Closes gh-47
2021-04-26 10:03:53 +01:00
Rossen Stoyanchev
b35e5f8c2f WebOutput minor updates
Rename "headers" to "responseHeaders" and clarify those work for HTTP
request queries but not for queries over a WebSocket session.

Update getter for response headers to return a read-only wrapper.

Provide only one public constructor without headers.

See gh-42
2021-04-09 13:05:40 +01:00
Rossen Stoyanchev
4a18932941 Revise GraphQLRequestHandler
Rename to GraphQLService to make it more clear it is a layer below
the specific transport such as HTTP endpoints.

Add WebGraphQLService sub-interface for query execution in web
environment with a WebInterceptor chain.

See gh-42
2021-04-09 08:43:57 +01:00
Rossen Stoyanchev
0338607a9b Parameterize GraphQLRequestHandler
This makes the contract more general and applicable to any GraphQL
request, not necessary coupled to HTTP.

Closes gh-42
2021-04-08 20:37:01 +01:00
Rossen Stoyanchev
b378231d39 Add GraphQLRequestHandler
See gh-42
2021-04-08 20:37:01 +01:00
Rossen Stoyanchev
9ceaaf5684 Polishing contribution
Closes gh-37
2021-04-07 14:23:35 +01:00
Andreas Marek
b6f79f212d Only build GraphQL once
See gh-37
2021-04-07 14:23:35 +01:00
Rossen Stoyanchev
ba0c426c32 GraphQL endpoints logged on startup
Closes gh-24
2021-02-17 07:40:37 +00:00
Rossen Stoyanchev
4e735f1ca8 Allow HTTP GET and WebSocket to use the same path
Closes gh-30
2021-02-05 21:07:27 +00:00
Brian Clozel
36121f338f Enable WebSocket endpoint with config property
Prior to this commit, the WebSocket endpoint (MVC or WebFlux) would be
enabled by default. In the case of MVC, the presence of
`spring-websocket` and the required dependencies was an additional hint
that could enable/disable this support depending on the application.

This commit changes the websocket path configuration so that it doesn't
hold a default value anymore. Configuring this property will trigger the
WebSocket support.

Right now developers cannot configure it to be the same as the
`spring.graphql.path`, but this will be solved in #30.

This commit also revisits the configuration properties namespace for
clarity, moving the websocket bits under their own section.

Closes gh-31
2021-02-02 15:27:00 +01:00
Brian Clozel
5696b8cead Configure WebInterceptors in handlers
This commit gathers `WebInterceptor` beans from the context (in an
ordered fashion) and configures them on the relevant GraphQL handlers.

Closes gh-7
2021-02-02 13:53:53 +01:00
Brian Clozel
2990df6c43 Guard MVC auto-configuration with WebSocket classes
This commit ensures that the WebSocket auto-configuration is guarded
with class conditions on WebSocket classes (from the javax API and the
spring-websocket artifact).

This prevents issues where application without such dependencies are
failing at startup.
2021-02-02 10:03:43 +01:00
Rossen Stoyanchev
2f52e35050 Support for subscriptions with WebMvc and spring-websocket 2021-02-01 22:38:52 +00:00
Brian Clozel
633ee1a1b5 Refactor project structure
This commit refactors the project structure to regroup GraphQL web
support under the spring-graphql-web module, and move all the Spring
Boot support classes under a single graphql-spring-boot-starter one.

Right now, the starter module contains everything: classes for MVC,
WebFlux and Actuator support as well as required dependencies. We will
change that in the future.
2021-01-05 16:35:34 +01:00