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

pre-release @tag/@inaccessible demo - waiting on Gateway @inaccessible support #165

Merged
merged 1 commit into from
Jul 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down
106 changes: 82 additions & 24 deletions .scripts/smoke.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -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 ""
2 changes: 0 additions & 2 deletions docker-compose.managed.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
20 changes: 9 additions & 11 deletions k8s/router/base/supergraph.graphql
Original file line number Diff line number Diff line change
@@ -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
}
Expand All @@ -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
Expand All @@ -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 {
Expand Down
20 changes: 9 additions & 11 deletions k8s/router/dev/supergraph.graphql
Original file line number Diff line number Diff line change
@@ -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
}
Expand All @@ -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
Expand All @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions router/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [],
Expand Down
6 changes: 4 additions & 2 deletions subgraphs/inventory/inventory.graphql
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions subgraphs/inventory/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [],
Expand Down
2 changes: 1 addition & 1 deletion subgraphs/products/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
11 changes: 4 additions & 7 deletions subgraphs/products/products.graphql
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -12,11 +14,6 @@ type ProductVariation {
id: ID!
}

enum Color {
BLUE
GREEN
}

type ProductDimension {
size: String
weight: Float
Expand Down
4 changes: 2 additions & 2 deletions subgraphs/users/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [],
Expand Down
20 changes: 9 additions & 11 deletions supergraph.graphql
Original file line number Diff line number Diff line change
@@ -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
}
Expand All @@ -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
Expand All @@ -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 {
Expand Down