Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert GraphQL v2 to Quarkus #1980

Merged
merged 32 commits into from
Sep 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
8ea1c82
Convert GraphQL v2 to Quarkus
olim7t Jul 5, 2022
7c358a8
Attempt to fix deadlock issue
olim7t Jul 22, 2022
0f0277c
Port first integration test
olim7t Jul 19, 2022
512343f
Port remaining schema-first integration tests
olim7t Aug 9, 2022
16351bb
Port easy CQL-first tests
olim7t Aug 10, 2022
b58c4ef
Port Apollo-based CQL-first tests
olim7t Aug 11, 2022
f127c25
Enable metrics
olim7t Aug 11, 2022
875a853
Propagate OVERLOADED as a GraphQL error
olim7t Aug 12, 2022
3a1e2ff
Port log reduction fix (#1279)
olim7t Aug 12, 2022
4a39551
Remove non-Quarkus GraphQL v2
olim7t Aug 12, 2022
8e51d63
Add Quarkus docker extension
olim7t Aug 15, 2022
3778f2c
Allow port config via system properties
olim7t Aug 15, 2022
a8850cf
Create base class for tests that need a CQL session
olim7t Aug 20, 2022
5d23b3d
Migrate all integration tests to QuarkusIntegrationTest
olim7t Aug 22, 2022
bf965e6
Fix caching issue
olim7t Aug 26, 2022
d0366ab
Fix parent POM version
olim7t Aug 26, 2022
a72ba6e
Address misc review comments
olim7t Aug 29, 2022
7f94548
Fix GraphqlResourceBaseTest
olim7t Aug 29, 2022
14d9d4a
Use QuarkusTestResource consistently
olim7t Aug 29, 2022
a7ce16a
Simplify token handling in PlaygroundResource
olim7t Aug 29, 2022
acda8fc
Don't start gRPC server in dev
olim7t Aug 29, 2022
ec0ae34
Drop OkHttp in favor of RestAssured
olim7t Aug 29, 2022
1f9981b
Reenable integration tests
olim7t Aug 30, 2022
e641553
Fix failing tests on DSE
olim7t Aug 30, 2022
ddc61d0
Fix authentication
olim7t Aug 31, 2022
75d7b4c
Disable Swagger
olim7t Aug 31, 2022
08a2f84
Re-add docker-compose config
olim7t Aug 31, 2022
81418f9
Fix missing ks hack
olim7t Aug 31, 2022
9fe3fc9
Fix apollo-runtime dependencies
olim7t Sep 1, 2022
caf7957
Set log level for integration tests
olim7t Sep 2, 2022
cb9498e
Fix duplicated slashes in test URLs
olim7t Sep 2, 2022
7283c8c
Revert "Fix apollo-runtime dependencies"
olim7t Sep 2, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
4 changes: 2 additions & 2 deletions .github/workflows/apis-v2.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ jobs:
# image-file - file name of the image to import (must be in the artifact)
# image - final image name to use when running int tests (-Dtesting.containers.stargate-image)
matrix:
project: [ sgv2-docsapi ]
project: [ sgv2-docsapi, sgv2-graphqlapi ]
name: [ cassandra-40, cassandra-311, dse-68, c2-dse-68 ]
include:
- name: cassandra-40
Expand Down Expand Up @@ -320,7 +320,7 @@ jobs:
# container test for docsapi only for now, enable for other when ready
- name: Integration Test
env:
CONTAINER_TEST: ${{ matrix.project == 'sgv2-docsapi' && 'true' || 'false' }}
CONTAINER_TEST: ${{ ( matrix.project == 'sgv2-docsapi' || matrix.project == 'sgv2-graphqlapi' ) && 'true' || 'false' }}
run: |
cd apis/
./mvnw -B verify -DskipUnitTests -pl ${{ matrix.project }} -am -P ${{ matrix.profile }} -Dquarkus.container-image.build=$CONTAINER_TEST -Dtesting.containers.stargate-image=${{ matrix.image }}
Expand Down
17 changes: 0 additions & 17 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -60,20 +60,3 @@ ENV STARGATE_REST_PORT=8082
COPY stargate-lib/rest/sgv2*.jar stargate-lib/rest/
COPY ./starctl-service-rest /starctl-service-rest
ENTRYPOINT ["./starctl-service-rest"]


#
# Dockerfile for building GraphQL API image
#

FROM openjdk:11-jre-slim as graphqlapi

EXPOSE 9080

ENV STARGATE_BRIDGE_HOST=localhost
ENV STARGATE_BRIDGE_PORT=8091
ENV STARGATE_GRAPHQL_PORT=9080

COPY stargate-lib/graphql/sgv2*.jar stargate-lib/graphql/
COPY ./starctl-service-graphql /starctl-service-graphql
ENTRYPOINT ["./starctl-service-graphql"]
6 changes: 6 additions & 0 deletions apis/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<modules>
<module>sgv2-quarkus-common</module>
<module>sgv2-docsapi</module>
<module>sgv2-graphqlapi</module>
</modules>
<properties>
<compiler-plugin.version>3.8.1</compiler-plugin.version>
Expand Down Expand Up @@ -52,6 +53,11 @@
<artifactId>assertj-core</artifactId>
<version>3.22.0</version>
</dependency>
<dependency>
<groupId>com.datastax.oss</groupId>
<artifactId>java-driver-core</artifactId>
<version>4.14.1</version>
</dependency>
</dependencies>
</dependencyManagement>
<build>
Expand Down
5 changes: 5 additions & 0 deletions apis/sgv2-graphqlapi/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
*
!target/*-runner
!target/*-runner.jar
!target/lib/*
!target/quarkus-app/*
48 changes: 15 additions & 33 deletions sgv2-graphqlapi/README.md → apis/sgv2-graphqlapi/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,6 @@ online docs]).
one: `/graphql/<keyspace>` now uses the custom schema, and the generated schema is not available
anymore.

## Where to start

[GraphqlServiceStarter] starts the HTTP service.

[GraphqlServiceServer] is the HTTP server that exposes the GraphQL services as REST resources. As
the name indicates, it's implemented with [Dropwizard](https://www.dropwizard.io/en/latest/).

## GraphQL Java primer

We rely extensively on [GraphQL Java](https://www.graphql-java.com/). Before delving further into
Expand Down Expand Up @@ -56,7 +49,7 @@ System.out.println(result.getData().toString()); // prints {random=1384094011}
```

1. `newSchema()` provides a DSL to create the GraphQL schema programmatically. This example will
produce:
produce:

```graphql
type Query {
Expand All @@ -72,10 +65,15 @@ System.out.println(result.getData().toString()); // prints {random=1384094011}

### Bridge connectivity

The service accesses the Stargate persistence via the [gRPC bridge](../bridge).
[CreateStargateBridgeClientFilter] (imported from `sgv2-service-common`) intercepts every HTTP
request to look for an auth token and optional tenant ID in the headers, and create a bridge client
accordingly. That client is stored in the HTTP context for consumption in the REST resources.
The service accesses the Stargate persistence via the [gRPC bridge](../../bridge). The bridge client
is obtained via [StargateRequestInfo] (imported from `sgv2-quarkus-common`), which creates it
from the auth token and (optional) tenant ID passed as HTTP request headers.

Note that we don't use the gRPC client generated by Quarkus (`StargateBridge`) directly; instead, we
rewrap it in a synchronous / future-based interface: [StargateBridgeClient]. This was done out of
convenience to simplify the migration of existing code. In the future, it might be possible to make
all the fetcher code asynchronous and use the Quarkus client (but there will still be some wrapping
required because graphql-java only knows of to deal with futures).

### Resources

Expand All @@ -89,9 +87,8 @@ The only thing that changes across subclasses is how we get hold of the `GraphQL
(see [GraphQL layer](#graphql-layer) below), and whether multipart is supported.

[StargateGraphqlContext] allows us to inject state that will be available later in the data fetchers
(see [CassandraFetcher]). In particular, this is how we pass the authentication subject and
datastore that were initialized in the authentication filter. The context also handles
[batching](#batching), which will be described below.
(see [CassandraFetcher]). In particular, this is how we pass the reference to the bridge client. The
context also handles [batching](#batching), which will be described below.

#### Other resources

Expand Down Expand Up @@ -253,21 +250,10 @@ The easiest way is to use the built-in GraphQL playground at http://localhost:80
You can then interact with the various GraphQL schemas by entering their URL in the playground's
address bar, for example http://localhost:8080/graphql/{keyspace}.

### Integration tests

The integration tests are located in the [testing] module. There use two different approaches:

* the tests that extend [ApolloTestBase] use the [Apollo client] library. They provide a good
example of using a "real-world" client, but require a lot of boilerplate: external definition
files, code generation...
* the other tests use a more lightweight approach that takes GraphQL queries as plain strings, and
returns raw JSON responses. See [GraphqlClient] and its subclasses.

If you add new tests, please favor the lightweight approach.
<!-- TODO integration tests -->
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to introduce a similar guides for building the app, building the docker, int tests, etc as we do for the docs-api.. I guess it would be more a copy & paste.. I think the readme should provide all the information possible.. What about configuration guide as in the docs api?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of copy-pasting, maybe it should move to the top-level readme?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fine with me, we can even move this to a separate task to speed merging this in. It's low priority anyway.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that we should prioritize merging to the v.2.0.0 branch. That will make it easier to work on the documentation across all 3 of the APIs.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I created #2052.


[GraphqlServiceStarter]: src/main/java/io/stargate/sgv2/graphql/impl/GraphqlServiceStarter.java
[GraphqlServiceServer]: src/main/java/io/stargate/sgv2/graphql/impl/GraphqlServiceServer.java
[CreateStargateBridgeClientFilter]: ../sgv2-service-common/src/main/java/io/stargate/sgv2/common/http/CreateStargateBridgeClientFilter.java
[StargateRequestInfo]: ../sgv2-quarkus-common/src/main/java/io/stargate/sgv2/api/common/StargateRequestInfo.java
[StargateBridgeClient]: ../sgv2-quarkus-common/src/main/java/io/stargate/sgv2/api/common/grpc/StargateBridgeClient.java
[GraphqlResourceBase]: src/main/java/io/stargate/sgv2/graphql/web/resources/GraphqlResourceBase.java
[StargateGraphqlContext]: src/main/java/io/stargate/sgv2/graphql/web/resources/StargateGraphqlContext.java
[CassandraFetcher]: src/main/java/io/stargate/sgv2/graphql/schema/CassandraFetcher.java
Expand All @@ -291,9 +277,5 @@ If you add new tests, please favor the lightweight approach.
[CassandraMigrator]: src/main/java/io/stargate/sgv2/graphql/schema/graphqlfirst/migration/CassandraMigrator.java
[CqlDirectives]: src/main/java/io/stargate/sgv2/graphql/schema/graphqlfirst/processor/CqlDirectives.java
[graphqlfirst.fetchers.deployed]: src/main/java/io/stargate/sgv2/graphql/schema/graphqlfirst/fetchers/deployed
[testing]: ../testing/src/main/java/io/stargate/it/http/graphql
[ApolloTestBase]: ../testing/src/main/java/io/stargate/it/http/graphql/cqlfirst/ApolloTestBase.java
[GraphqlClient]: ../testing/src/main/java/io/stargate/it/http/graphql/GraphqlClient.java

[Apollo client]: https://www.apollographql.com/docs/android/essentials/get-started-java/
[Stargate online docs]: https://stargate.io/docs/stargate/1.0/quickstart/quick_start-graphql.html
Loading