Skip to content

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
mmazur122 committed May 15, 2024
1 parent 4e36e3e commit 7a03caf
Show file tree
Hide file tree
Showing 25 changed files with 212 additions and 1,131 deletions.
34 changes: 0 additions & 34 deletions .scripts/smoke.sh
Original file line number Diff line number Diff line change
Expand Up @@ -159,40 +159,6 @@ read -r -d '' EXP_3 <<"EOF"
{"errors":[{"message":
EOF

# --------------------------------------------------------------------
# TEST 4
# --------------------------------------------------------------------
DESCR_4="exampleQuery with pandas"
OPNAME_4="exampleQuery"
ISSLOW_4="true"
ACCEPT_4="application/json"
read -r -d '' QUERY_4 <<"EOF"
query exampleQuery {
allProducts {
id,
sku,
dimensions {
size,
weight
}
delivery {
estimatedDelivery,
fastestDelivery
}
}
allPandas {
name,
favoriteFood
}
}
EOF

OP_4=equals

read -r -d '' EXP_4 <<"EOF"
{"data":{"allProducts":[{"id":"converse-1","sku":"converse-1","dimensions":{"size":"1","weight":1},"delivery":{"estimatedDelivery":"6/25/2023","fastestDelivery":"6/24/2023"}},{"id":"vans-1","sku":"vans-1","dimensions":{"size":"1","weight":1},"delivery":{"estimatedDelivery":"6/25/2023","fastestDelivery":"6/24/2023"}}],"allPandas":[{"name":"Basi","favoriteFood":"bamboo leaves"},{"name":"Yun","favoriteFood":"apple"}]}}
EOF

# --------------------------------------------------------------------
# TEST 5
# --------------------------------------------------------------------
Expand Down
4 changes: 1 addition & 3 deletions .scripts/subgraphs/docker-compose-networking.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
#!/bin/bash

subgraphs=("inventory" "products" "users" "pandas" "reviews")
subgraphs=("inventory" "products" "users" "reviews")

url_inventory="http://inventory:4000/graphql"
url_products="http://products:4000/graphql"
url_users="http://users:4000/graphql"
url_pandas="http://pandas:4000/graphql"
url_reviews="http://reviews:4000/graphql"

schema_inventory="subgraphs/inventory/app/src/main/resources/graphql/inventory.graphqls"
schema_products="subgraphs/products/products.graphql"
schema_users="subgraphs/users/users.graphql"
schema_pandas="subgraphs/pandas/pandas.graphql"
schema_reviews="subgraphs/reviews/reviews.graphql"
6 changes: 2 additions & 4 deletions .scripts/subgraphs/localhost-networking.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
#!/bin/bash

subgraphs=("products" "inventory" "users" "pandas" "reviews")
subgraphs=("products" "inventory" "users" "reviews")

url_products="http://localhost:4001/graphql"
url_inventory="http://localhost:4002/graphql"
url_users="http://localhost:4003/graphql"
url_pandas="http://localhost:4004/graphql"
url_reviews="http://localhost:4005/graphql"
url_reviews="http://localhost:4004/graphql"

schema_products="subgraphs/products/products.graphql"
schema_inventory="subgraphs/inventory/app/src/main/resources/graphql/inventory.graphqls"
schema_users="subgraphs/users/users.graphql"
schema_pandas="subgraphs/pandas/pandas.graphql"
schema_reviews="subgraphs/reviews/reviews.graphql"
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ You'll need:
* [docker-compose](https://docs.docker.com/compose/install/) - runs subgraphs locally
* [rover](https://www.apollographql.com/docs/rover/getting-started) - publishes subgraph schemas to your supergraph in the registry
* [router](https://www.apollographql.com/docs/router/quickstart) - pulls supergraph schemas from the registry
* redis instance running on `localhost:6379` - used for entity caching PoC
* Enterprise Apollo Studio account (trial works) to access entity caching PoC

Install `rover` and `router`:

Expand Down Expand Up @@ -165,7 +167,6 @@ products | 🚀 Products subgraph ready
users | 🚀 Users subgraph ready
inventory | Completed initialization in 712 ms
reviews | INFO: Application startup complete.
pandas | 🚀 Pandas subgraph ready
```

Browse the products subgraph on port 4001: http://localhost:4001/
Expand Down
9 changes: 2 additions & 7 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,8 @@ services:
build: ./subgraphs/users
ports:
- "4003:4000"
pandas:
container_name: pandas
build: ./subgraphs/pandas
ports:
- "4004:4000"
reviews:
container_name: reviews
build: ./subgraphs/reviews
build: subgraphs/reviews
ports:
- "4005:4000"
- "4004:4000"
23 changes: 23 additions & 0 deletions rhai/main.rhai
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
fn supergraph_service(service) {
let add_headers_to_response = |response| {
if response.context["set_response_headers"]?.len > 0 {
response.headers["Cache-Control"] = response.context["set_response_headers"];
}
};

service.map_response(add_headers_to_response);
}

fn subgraph_service(service, subgraph) {
let store_headers_from_subgraphs = |response| {
if "Cache-Control" in response.headers {
if response.context["set_response_headers"] == () {
response.context.set_response_headers = []
}

response.context.set_response_headers += response.headers.values("Cache-Control");
}
};

service.map_response(store_headers_from_subgraphs);
}
12 changes: 0 additions & 12 deletions subgraphs/pandas/Dockerfile

This file was deleted.

11 changes: 0 additions & 11 deletions subgraphs/pandas/pandas.graphql

This file was deleted.

25 changes: 0 additions & 25 deletions subgraphs/pandas/pandas.js

This file was deleted.

8 changes: 6 additions & 2 deletions subgraphs/products/products.graphql
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
extend schema
@link(url: "https://specs.apollo.dev/federation/v2.1",
import: ["@key", "@shareable", "@tag", "@inaccessible", "@composeDirective"])
import: ["@key", "@shareable", "@tag", "@inaccessible", "@composeDirective", "@requires", "@external"])
@link(url: "https://myspecs.dev/myDirective/v1.0", import: ["@myDirective", { name: "@anotherDirective", as: "@hello" }])
@composeDirective(name: "@myDirective")
@composeDirective(name: "@hello")
Expand All @@ -24,6 +24,8 @@ interface ProductItf implements SkuItf {
createdBy: User
hidden: String @inaccessible
oldField: String @deprecated(reason: "refactored out")
# reviewsCount: Int!
# discount: Float
}

interface SkuItf {
Expand All @@ -37,10 +39,12 @@ type Product implements ProductItf & SkuItf @key(fields: "id") @key(fields: "sku
package: String
variation: ProductVariation
dimensions: ProductDimension
createdBy: User
createdBy: User @external
hidden: String
reviewsScore: Float!
oldField: String
reviewsCount: Int! @external
discount: Float @requires(fields: "reviewsCount createdBy { email }")
}
enum ShippingClass {
STANDARD
Expand Down
39 changes: 25 additions & 14 deletions subgraphs/products/products.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,12 @@ const userByProduct = [
const typeDefs = gql(readFileSync('./products.graphql', { encoding: 'utf-8' }));
const resolvers = {
Query: {
allProducts: (_, args, context) => {
allProducts: async (_, args, context) => {
await new Promise(resolve => setTimeout(resolve, 1000));
return products;
},
product: (_, args, context) => {
product: async (_, args, context) => {
await new Promise(resolve => setTimeout(resolve, 500));
return products.find(p => p.id == args.id);
}
},
Expand All @@ -65,6 +67,14 @@ const resolvers = {
dimensions: () => {
return { size: "1", weight: 1 }
},
discount(product, args, context) {
const reviewsCount = product.reviewsCount;
console.log("product", product);
if (reviewsCount === undefined) {
throw new Error("reviewsCount is not provided");
}
return reviewsCount * 0.1;
},
createdBy: (reference) => {
if (reference.id) {
return userByProduct.find(p => p.id == reference.id).user;
Expand All @@ -75,24 +85,25 @@ const resolvers = {
return 4.5;
},
__resolveReference: (reference) => {
if (reference.id) return products.find(p => p.id == reference.id);
else if (reference.sku && reference.package) return products.find(p => p.sku == reference.sku && p.package == reference.package);
let product = {};
console.log("__resolveReference reference:", reference);
if (reference.id) {
product = products.find(p => p.id == reference.id);
}
else if (reference.sku && reference.package) {
product = products.find(p => p.sku == reference.sku && p.package == reference.package);
}
else return { id: 'rover', package: '@apollo/rover', ...reference };

return {
...reference,
...product,
}
}
}
}
const schema = buildSubgraphSchema({ typeDefs, resolvers });

// console.log(`---------------------------------------`);
// console.log(`🚀 subgraph-js::printSubgraphSchema 🚀`);
// console.log(`---------------------------------------`);
// console.log(printSubgraphSchema(schema));
//
// console.log(`---------------------------------------`);
// console.log(`🚀 graphql::printSchema 🚀`);
// console.log(`---------------------------------------`);
// console.log(printSchema(schema));

const server = new ApolloServer({ schema: schema });
server.listen( {port: port} ).then(({ url }) => {
console.log(`🚀 Products subgraph ready at ${url}`);
Expand Down
18 changes: 7 additions & 11 deletions subgraphs/reviews/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
FROM python:3.11
FROM node:18-bookworm-slim

# install PDM
RUN pip install -U pip setuptools wheel
RUN pip install pdm
WORKDIR /usr/src/app

# copy files
COPY pyproject.toml pdm.lock /project/
COPY . /project
COPY package.json .

WORKDIR /project
RUN pdm install --prod --no-lock --no-editable
RUN npm install

STOPSIGNAL SIGINT
COPY reviews.js .
COPY reviews.graphql .

CMD ["pdm", "run", "server"]
CMD [ "node", "reviews.js" ]
19 changes: 0 additions & 19 deletions subgraphs/reviews/app.py

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
{
"name": "subgraph-pandas",
"name": "subgraph-reviews",
"version": "1.1.27",
"description": "",
"main": "pandas.js",
"main": "",
"scripts": {
"start": "node pandas.js"
"start": "node "
},
"dependencies": {
"@apollo/subgraph": "^2.7.7",
"apollo-server": "3.13.0",
"apollo-server-express": "^3.13.0",
"express": "^4.19.2",
"graphql": "16.8.1"
},
"keywords": [],
Expand Down
Loading

0 comments on commit 7a03caf

Please sign in to comment.