Skip to content

Commit

Permalink
ci: add ndc-test to validate generated schema (#109) (#110)
Browse files Browse the repository at this point in the history
  • Loading branch information
hgiasac authored May 30, 2024
1 parent cbcf3e2 commit 3887c3d
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 4 deletions.
9 changes: 7 additions & 2 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ on:
jobs:
test-go:
name: Run Go lint and unit tests
runs-on: ubuntu-20.04
runs-on: ubuntu-latest
permissions:
pull-requests: write
steps:
Expand All @@ -34,7 +34,7 @@ jobs:
- name: Vet
run: go vet ./...
- name: Lint
uses: golangci/golangci-lint-action@v4
uses: golangci/golangci-lint-action@v6
with:
version: latest
only-new-issues: true
Expand All @@ -47,9 +47,14 @@ jobs:
go test -v -coverpkg=./... -race -timeout 3m -coverprofile=coverage.out ./...
- name: Run Go unit tests for the generation example
run: |
make build-codegen
pushd example/codegen
../../_output/hasura-ndc-go generate
go test -v -race -timeout 3m ./...
popd
- name: Run ndc-test
run: |
./example/codegen/test.sh
- name: Go coverage format
if: ${{ github.event_name == 'pull_request' }}
run: |
Expand Down
3 changes: 3 additions & 0 deletions cmd/hasura-ndc-go/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,9 @@ func (sp *SchemaParser) parseType(rawSchema *RawConnectorSchema, rootType *TypeI
TypeAST: ty,
}
}
if _, ok := rawSchema.ScalarSchemas[string(scalarName)]; !ok {
rawSchema.ScalarSchemas[string(scalarName)] = defaultScalarTypes[scalarName]
}
rootType.TypeFragments = append(rootType.TypeFragments, inferredType.String())
rootType.Schema = schema.NewNamedType(string(scalarName))
rootType.IsScalar = true
Expand Down
3 changes: 2 additions & 1 deletion cmd/hasura-ndc-go/templates/new/connector.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ var connectorCapabilities = schema.CapabilitiesResponse{
Version: "0.1.3",
Capabilities: schema.Capabilities{
Query: schema.QueryCapabilities{
Variables: schema.LeafCapability{},
Variables: schema.LeafCapability{},
NestedFields: schema.NestedFieldCapabilities{},
},
Mutation: schema.MutationCapabilities{},
},
Expand Down
7 changes: 7 additions & 0 deletions cmd/hasura-ndc-go/testdata/basic/expected/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -3126,6 +3126,13 @@
"type": "int8"
}
},
"JSON": {
"aggregate_functions": {},
"comparison_operators": {},
"representation": {
"type": "json"
}
},
"RawJSON": {
"aggregate_functions": {},
"comparison_operators": {},
Expand Down
3 changes: 2 additions & 1 deletion example/codegen/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ var connectorCapabilities = schema.CapabilitiesResponse{
Version: "0.1.3",
Capabilities: schema.Capabilities{
Query: schema.QueryCapabilities{
Variables: schema.LeafCapability{},
Variables: schema.LeafCapability{},
NestedFields: schema.NestedFieldCapabilities{},
},
Mutation: schema.MutationCapabilities{},
},
Expand Down
7 changes: 7 additions & 0 deletions example/codegen/schema.generated.json
Original file line number Diff line number Diff line change
Expand Up @@ -3154,6 +3154,13 @@
"type": "int8"
}
},
"JSON": {
"aggregate_functions": {},
"comparison_operators": {},
"representation": {
"type": "json"
}
},
"RawJSON": {
"aggregate_functions": {},
"comparison_operators": {},
Expand Down
38 changes: 38 additions & 0 deletions example/codegen/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/bin/bash

set -eo pipefail

trap 'printf "\nkilling process..." && kill $serverPID' EXIT

cd "$(dirname "${BASH_SOURCE[0]}")"
mkdir -p ./dist

if [ ! -f ./dist/ndc-test ]; then
curl -L https://github.com/hasura/ndc-spec/releases/download/v0.1.3/ndc-test-x86_64-unknown-linux-gnu -o ./dist/ndc-test
chmod +x ./dist/ndc-test
fi

http_wait() {
printf "$1:\t "
for i in {1..120};
do
local code="$(curl -s -o /dev/null -m 2 -w '%{http_code}' $1)"
if [ "$code" != "200" ]; then
printf "."
sleep 1
else
printf "\r\033[K$1:\t ${GREEN}OK${NC}\n"
return 0
fi
done
printf "\n${RED}ERROR${NC}: cannot connect to $1.\n"
exit 1
}

go build -o ./dist/ndc-codegen-example .
./dist/ndc-codegen-example serve > /dev/null 2>&1 &
serverPID=$!

http_wait http://localhost:8080/health

./dist/ndc-test test --endpoint http://localhost:8080

0 comments on commit 3887c3d

Please sign in to comment.