Skip to content

Commit 4ed96f9

Browse files
committed
Added a js README and updated my java example
1 parent cb95246 commit 4ed96f9

File tree

3 files changed

+24
-7
lines changed

3 files changed

+24
-7
lines changed

README.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ This repository demonstrates how to setup a skeleton coprocessor that simply log
77
> Note: To run this example, you will need a GraphOS Enterprise plan and must create `/router/.env` based on `/router/.env.example` which exports `APOLLO_KEY` and `APOLLO_GRAPH_REF`.
88
99
1. Run the subgraph from the `/subgraph` directory with `npm run dev`
10-
1. Run the coprocessor from the `/coprocessor` directory with `npm run dev`
10+
1. Run the coprocessor based on your language of choice by following the README from the appropriate `/*-coprocessor` directory ([javascript](./js-coprocessor/README.md), [Java](./java-coprocessor/README.md)).
1111
1. In the `/router` directory, download the router by running `./download_router.sh`
1212
1. In the `/router` directory, compose the schema by running `./create_local_schema.sh`
1313
1. In the `/router` directory, run the router by running `./start_router.sh`
@@ -21,7 +21,3 @@ Now if you run this code in the browser (http://127.0.0.1:4000/), you will be ab
2121
In `router/router-config.yaml`, the coprocessor is configured with the Router to be called on the `router` `request` stage.
2222

2323
### Coprocessor
24-
25-
In `coprocessor/src/index.js`, the coprocessor is setup with `express` to listen to the `/` POST endpoint and respond to the `RouterRequest` stage.
26-
27-
In the `processRouterRequestStage` function, the payload is logged.

java-coprocessor/src/main/java/com/example/demo/RequestHandlers/RouterRequest.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,20 @@
88

99
public class RouterRequest {
1010
public RouterRequestBody handle(RouterRequestBody request) {
11-
// In this Java sample, we are mapping the request sent by the router to a model called "RouterRequestBody"
12-
// Please review that class in the "Models" folder to review what you're able to retrieve at this stage
11+
// This is the object sent by the Router that you can act upon to update headers, context, auth claims, etc
1312
// If you update the "control" property from "Continue" to something like { "break": 400 }, it will terminate the request and return the specified HTTP error
1413
// See: https://www.apollographql.com/docs/router/customizations/coprocessor/
14+
// The object sent by the Router has been mapped to a `RouterRequestBody` object by the `@RequestBody` annotation in the `CoprocessorController` class
15+
System.out.println(request.getHeaders());
16+
System.out.println(request.getMethod());
17+
System.out.println(request.getContext().getEntries());
18+
System.out.println(request.getSDL());
19+
System.out.println(request.getVersion());
20+
System.out.println(request.getBody());
21+
System.out.println(request.getStage());
22+
System.out.println(request.getPath());
1523
System.out.println(request.getControl());
24+
System.out.println(request.getId());
1625

1726
return request;
1827
}

js-coprocessor/README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Javascript Coprocessor
2+
3+
## Description
4+
5+
In `js-coprocessor/src/index.js`, the coprocessor is setup with `express` to listen to the `/` POST endpoint and respond to the `RouterRequest` stage.
6+
7+
In the `processRouterRequestStage` function, the payload is logged.
8+
9+
## Running the coprocessor
10+
11+
1. Run `npm install` to install dependencies
12+
1. Run `npm run dev` to start the service

0 commit comments

Comments
 (0)