diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 3694bf8f..5c841c27 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -50,6 +50,7 @@ jobs: - name: make supergraph run: | make supergraph + cat supergraph.graphql - name: docker-compose build run: | ( set -x; docker-compose build --no-cache --pull --parallel --progress plain ) diff --git a/.scripts/smoke.sh b/.scripts/smoke.sh index fb0f740f..700de6d5 100755 --- a/.scripts/smoke.sh +++ b/.scripts/smoke.sh @@ -4,8 +4,9 @@ PORT="${1:-4000}" TESTS=(1 2) # -------------------------------------------------------------------- -# QUERY 1 +# TEST 1 # -------------------------------------------------------------------- +DESCR_1="allProducts with delivery" read -r -d '' QUERY_1 <<"EOF" { allProducts { @@ -21,13 +22,16 @@ read -r -d '' QUERY_1 <<"EOF" } EOF +OP_1=equals + read -r -d '' EXP_1 <<"EOF" {"data":{"allProducts":[{"delivery":{"estimatedDelivery":"6/25/2021","fastestDelivery":"6/24/2021"},"createdBy":{"name":"Apollo Studio Support","email":"support@apollographql.com"}},{"delivery":{"estimatedDelivery":"6/25/2021","fastestDelivery":"6/24/2021"},"createdBy":{"name":"Apollo Studio Support","email":"support@apollographql.com"}}]}} EOF # -------------------------------------------------------------------- -# QUERY 2 +# TEST 2 # -------------------------------------------------------------------- +DESCR_2="allProducts with totalProductsCreated" read -r -d '' QUERY_2 <<"EOF" { allProducts { @@ -41,45 +45,99 @@ read -r -d '' QUERY_2 <<"EOF" } EOF +OP_2=equals + read -r -d '' EXP_2 <<"EOF" {"data":{"allProducts":[{"id":"apollo-federation","sku":"federation","createdBy":{"email":"support@apollographql.com","totalProductsCreated":1337}},{"id":"apollo-studio","sku":"studio","createdBy":{"email":"support@apollographql.com","totalProductsCreated":1337}}]}} EOF +# -------------------------------------------------------------------- +# TEST 3 - DISABLED FOR NOW - UNTIL WE ALLOW @inaccessible in subgraphs +# -------------------------------------------------------------------- +DESCR_3="weight: Float @inaccessible should return error" +read -r -d '' QUERY_3 <<"EOF" +{ + allProducts { + id, + dimensions { + size, + weight + } + } +} +EOF + +OP_3=startsWith + +read -r -d '' EXP_3 <<"EOF" +{"errors":[{"message":"Cannot query field \"weight\" on type \"ProductDimension\" +EOF + + set -e -echo Running smoke tests ... +OK_CHECK="\xE2\x9C\x85" +FAIL_MARK="\xE2\x9D\x8C" +ROCKET="\xF0\x9F\x9A\x80" + +printf "Running smoke tests ... $ROCKET $ROCKET $ROCKET\n" sleep 2 for test in ${TESTS[@]}; do - echo "" - echo ------------------------------------------------------------------------------------------- - echo TEST $test - echo ------------------------------------------------------------------------------------------- + descr_var="DESCR_$test" query_var="QUERY_$test" exp_var="EXP_$test" + op_var="OP_$test" + + DESCR="${!descr_var}" QUERY=$(echo "${!query_var}" | awk -v ORS= -v OFS= '{$1=$1}1') EXP="${!exp_var}" - ACT=$(set -x; curl -X POST -H 'Content-Type: application/json' --data '{ "query": "'"${QUERY}"'" }' http://localhost:$PORT/) - if [ "$ACT" = "$EXP" ]; then - echo "" - echo "Result:" + OP="${!op_var}" + + echo "" + echo "==============================================================" + echo "TEST $test: $DESCR" + echo "==============================================================" + + ACT=$(set -x; curl -X POST -H 'Content-Type: application/json' --data '{ "query": "'"${QUERY}"'" }' http://localhost:$PORT/ 2>/dev/null) + + OK=0 + if [ "$OP" == "equals" ]; then + [ "$ACT" == "$EXP" ] && OK=1 + + elif [ "$OP" == "startsWith" ]; then + EXP=$( echo "$EXP" | sed 's|\\|\\\\|g' | sed 's|\[|\\[|g' | sed 's|\]|\\]|g') + if echo "$ACT" | grep -q "^${EXP}"; then + OK=1 + fi + fi + + if [ $OK -eq 1 ]; then + echo ------------------------- + echo "[Expected: $OP]" + echo "$EXP" + echo ------------------------- + echo "[Actual]" echo "$ACT" - echo "" - echo "Success!" + echo ------------------------- + printf "$OK_CHECK Success!\n" else - echo ------------------------------------------------------------------------------------------- - echo "Error: query failed" - echo ------------------------------------------------------------------------------------------- - echo "[Expected]" + echo ------------------------- + printf "$FAIL_MARK TEST $test Failed! \n" + echo ------------------------- + echo "[Expected: $OP]" echo "$EXP" - echo ------------------------------------------------------------------------------------------- - echo "$ACT" + echo ------------------------- echo "[Actual]" - echo ------------------------------------------------------------------------------------------- - echo "Error: query failed" - echo ------------------------------------------------------------------------------------------- + echo "$ACT" + echo ------------------------- + printf "$FAIL_MARK TEST $test Failed! \n" + echo ------------------------- exit 1 fi done -echo ------------------------------------------------------------------------------------------- -echo Done! +echo "" +echo "================================" +printf "$OK_CHECK ALL TESTS PASS! \n" +echo "================================" +echo "" diff --git a/docker-compose.managed.yml b/docker-compose.managed.yml index a7371a43..a3348123 100644 --- a/docker-compose.managed.yml +++ b/docker-compose.managed.yml @@ -3,8 +3,6 @@ services: router: container_name: router build: ./router - environment: - - APOLLO_SCHEMA_CONFIG_DELIVERY_ENDPOINT=https://uplink.api.apollographql.com/ env_file: # create with make graph-api-env - graph-api.env ports: diff --git a/k8s/router/base/supergraph.graphql b/k8s/router/base/supergraph.graphql index 3a26843b..c68d785b 100644 --- a/k8s/router/base/supergraph.graphql +++ b/k8s/router/base/supergraph.graphql @@ -1,6 +1,7 @@ schema @core(feature: "https://specs.apollo.dev/core/v0.1"), - @core(feature: "https://specs.apollo.dev/join/v0.1") + @core(feature: "https://specs.apollo.dev/join/v0.1"), + @core(feature: "https://specs.apollo.dev/tag/v0.1") { query: Query } @@ -15,10 +16,7 @@ directive @join__owner(graph: join__Graph!) on OBJECT | INTERFACE directive @join__graph(name: String!, url: String!) on ENUM_VALUE -enum Color { - BLUE - GREEN -} +directive @tag(name: String!) repeatable on FIELD_DEFINITION type DeliveryEstimates { estimatedDelivery: String @@ -40,18 +38,18 @@ type Product @join__type(graph: PRODUCTS, key: "sku variation{id}") @join__type(graph: INVENTORY, key: "id") { - id: ID! @join__field(graph: PRODUCTS) - sku: String @join__field(graph: PRODUCTS) - package: String @join__field(graph: PRODUCTS) - variation: ProductVariation @join__field(graph: PRODUCTS) - dimensions: ProductDimension @join__field(graph: PRODUCTS) createdBy: User @join__field(graph: PRODUCTS, provides: "totalProductsCreated") delivery(zip: String): DeliveryEstimates @join__field(graph: INVENTORY, requires: "dimensions{size weight}") + dimensions: ProductDimension @join__field(graph: PRODUCTS) + id: ID! @join__field(graph: PRODUCTS) @tag(name: "hi from products") @tag(name: "hi from inventory") + package: String @join__field(graph: PRODUCTS) + sku: String @join__field(graph: PRODUCTS) @tag(name: "hi from products") + variation: ProductVariation @join__field(graph: PRODUCTS) } type ProductDimension { size: String - weight: Float + weight: Float @tag(name: "hi from inventory value type field") } type ProductVariation { diff --git a/k8s/router/dev/supergraph.graphql b/k8s/router/dev/supergraph.graphql index 3a26843b..c68d785b 100644 --- a/k8s/router/dev/supergraph.graphql +++ b/k8s/router/dev/supergraph.graphql @@ -1,6 +1,7 @@ schema @core(feature: "https://specs.apollo.dev/core/v0.1"), - @core(feature: "https://specs.apollo.dev/join/v0.1") + @core(feature: "https://specs.apollo.dev/join/v0.1"), + @core(feature: "https://specs.apollo.dev/tag/v0.1") { query: Query } @@ -15,10 +16,7 @@ directive @join__owner(graph: join__Graph!) on OBJECT | INTERFACE directive @join__graph(name: String!, url: String!) on ENUM_VALUE -enum Color { - BLUE - GREEN -} +directive @tag(name: String!) repeatable on FIELD_DEFINITION type DeliveryEstimates { estimatedDelivery: String @@ -40,18 +38,18 @@ type Product @join__type(graph: PRODUCTS, key: "sku variation{id}") @join__type(graph: INVENTORY, key: "id") { - id: ID! @join__field(graph: PRODUCTS) - sku: String @join__field(graph: PRODUCTS) - package: String @join__field(graph: PRODUCTS) - variation: ProductVariation @join__field(graph: PRODUCTS) - dimensions: ProductDimension @join__field(graph: PRODUCTS) createdBy: User @join__field(graph: PRODUCTS, provides: "totalProductsCreated") delivery(zip: String): DeliveryEstimates @join__field(graph: INVENTORY, requires: "dimensions{size weight}") + dimensions: ProductDimension @join__field(graph: PRODUCTS) + id: ID! @join__field(graph: PRODUCTS) @tag(name: "hi from products") @tag(name: "hi from inventory") + package: String @join__field(graph: PRODUCTS) + sku: String @join__field(graph: PRODUCTS) @tag(name: "hi from products") + variation: ProductVariation @join__field(graph: PRODUCTS) } type ProductDimension { size: String - weight: Float + weight: Float @tag(name: "hi from inventory value type field") } type ProductVariation { diff --git a/router/package.json b/router/package.json index ea382a91..d830312c 100644 --- a/router/package.json +++ b/router/package.json @@ -7,9 +7,9 @@ "start": "node router.js" }, "dependencies": { - "@apollo/gateway": "0.33.0", + "@apollo/gateway": "0.34.0-rc.0", "apollo-server": "3.0.0", - "supergraph-demo-opentelemetry": "0.0.1", + "supergraph-demo-opentelemetry": "0.0.3", "graphql": "15.5.1" }, "keywords": [], diff --git a/subgraphs/inventory/inventory.graphql b/subgraphs/inventory/inventory.graphql index 1f960fb0..6601ed5e 100644 --- a/subgraphs/inventory/inventory.graphql +++ b/subgraphs/inventory/inventory.graphql @@ -1,12 +1,14 @@ +directive @tag(name: String!) repeatable on FIELD_DEFINITION + extend type Product @key(fields: "id") { - id: ID! @external + id: ID! @external @tag(name: "hi from inventory") dimensions: ProductDimension @external delivery(zip: String): DeliveryEstimates @requires(fields: "dimensions { size weight }") } type ProductDimension { size: String - weight: Float + weight: Float @tag(name: "hi from inventory value type field") } type DeliveryEstimates { diff --git a/subgraphs/inventory/package.json b/subgraphs/inventory/package.json index 351449e1..90e099d1 100644 --- a/subgraphs/inventory/package.json +++ b/subgraphs/inventory/package.json @@ -7,9 +7,9 @@ "start": "node inventory.js" }, "dependencies": { - "@apollo/federation": "0.25.2", + "@apollo/federation": "0.27.0-rc.0", "apollo-server": "3.0.0", - "supergraph-demo-opentelemetry": "0.0.1", + "supergraph-demo-opentelemetry": "0.0.3", "graphql": "15.5.1" }, "keywords": [], diff --git a/subgraphs/products/package.json b/subgraphs/products/package.json index 0d2938de..37aa5574 100644 --- a/subgraphs/products/package.json +++ b/subgraphs/products/package.json @@ -7,7 +7,7 @@ "start": "node products.js" }, "dependencies": { - "@apollo/federation": "0.25.2", + "@apollo/federation": "0.27.0-rc.0", "apollo-server": "3.0.0", "supergraph-demo-opentelemetry": "0.0.3", "graphql": "15.5.1" diff --git a/subgraphs/products/products.graphql b/subgraphs/products/products.graphql index c885696f..ae74b3d3 100644 --- a/subgraphs/products/products.graphql +++ b/subgraphs/products/products.graphql @@ -1,6 +1,8 @@ +directive @tag(name: String!) repeatable on FIELD_DEFINITION + type Product @key(fields: "id") @key(fields: "sku package") @key(fields: "sku variation { id }"){ - id: ID! - sku: String + id: ID! @tag(name: "hi from products") + sku: String @tag(name: "hi from products") package: String variation: ProductVariation dimensions: ProductDimension @@ -12,11 +14,6 @@ type ProductVariation { id: ID! } -enum Color { - BLUE - GREEN -} - type ProductDimension { size: String weight: Float diff --git a/subgraphs/users/package.json b/subgraphs/users/package.json index 3a1b80b6..a79fb1ae 100644 --- a/subgraphs/users/package.json +++ b/subgraphs/users/package.json @@ -7,9 +7,9 @@ "start": "node users.js" }, "dependencies": { - "@apollo/federation": "0.25.2", + "@apollo/federation": "0.27.0-rc.0", "apollo-server": "3.0.0", - "supergraph-demo-opentelemetry": "0.0.1", + "supergraph-demo-opentelemetry": "0.0.3", "graphql": "15.5.1" }, "keywords": [], diff --git a/supergraph.graphql b/supergraph.graphql index 3a26843b..c68d785b 100644 --- a/supergraph.graphql +++ b/supergraph.graphql @@ -1,6 +1,7 @@ schema @core(feature: "https://specs.apollo.dev/core/v0.1"), - @core(feature: "https://specs.apollo.dev/join/v0.1") + @core(feature: "https://specs.apollo.dev/join/v0.1"), + @core(feature: "https://specs.apollo.dev/tag/v0.1") { query: Query } @@ -15,10 +16,7 @@ directive @join__owner(graph: join__Graph!) on OBJECT | INTERFACE directive @join__graph(name: String!, url: String!) on ENUM_VALUE -enum Color { - BLUE - GREEN -} +directive @tag(name: String!) repeatable on FIELD_DEFINITION type DeliveryEstimates { estimatedDelivery: String @@ -40,18 +38,18 @@ type Product @join__type(graph: PRODUCTS, key: "sku variation{id}") @join__type(graph: INVENTORY, key: "id") { - id: ID! @join__field(graph: PRODUCTS) - sku: String @join__field(graph: PRODUCTS) - package: String @join__field(graph: PRODUCTS) - variation: ProductVariation @join__field(graph: PRODUCTS) - dimensions: ProductDimension @join__field(graph: PRODUCTS) createdBy: User @join__field(graph: PRODUCTS, provides: "totalProductsCreated") delivery(zip: String): DeliveryEstimates @join__field(graph: INVENTORY, requires: "dimensions{size weight}") + dimensions: ProductDimension @join__field(graph: PRODUCTS) + id: ID! @join__field(graph: PRODUCTS) @tag(name: "hi from products") @tag(name: "hi from inventory") + package: String @join__field(graph: PRODUCTS) + sku: String @join__field(graph: PRODUCTS) @tag(name: "hi from products") + variation: ProductVariation @join__field(graph: PRODUCTS) } type ProductDimension { size: String - weight: Float + weight: Float @tag(name: "hi from inventory value type field") } type ProductVariation {