Skip to content

Commit

Permalink
Add introspection schema check
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Scarr committed Aug 9, 2018
1 parent ae82b94 commit 45e22cb
Show file tree
Hide file tree
Showing 9 changed files with 2,815 additions and 58 deletions.
35 changes: 30 additions & 5 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,36 @@ jobs:
command: |
docker build -f .circleci/golang.Dockerfile -t gqlgen/golang .
docker build -f .circleci/node.Dockerfile -t gqlgen/node .
#
# - run:
# name: "golang tests"
# command: docker run --rm gqlgen/golang .circleci/test.sh
- run:
name: "golang tests"
command: docker run --rm gqlgen/golang .circleci/test.sh

- run:
name: "integration tests"
command: ./.circleci/integration.sh
command: |
function cleanup {
echo "Cleaning up containers..."
docker kill $SERVER_CONTAINER 1>/dev/null 2>/dev/null || true
docker rm --force -v $SERVER_CONTAINER 1>/dev/null 2>/dev/null || true
}
trap cleanup EXIT
SERVER_CONTAINER=$(docker run -d \
-e PORT=1234 \
--name integration_server \
gqlgen/golang go run ./integration/server/server.go \
)
sleep 2
docker run -it \
-e SERVER_URL=http://integration_server:1234/query \
--link=integration_server \
gqlgen/node ../.circleci/integration.sh
echo "### server logs"
docker logs $SERVER_CONTAINER
exit $(docker inspect $SERVER_CONTAINER --format='{{.State.ExitCode}}')
31 changes: 9 additions & 22 deletions .circleci/integration.sh
Original file line number Diff line number Diff line change
@@ -1,30 +1,17 @@
#!/bin/sh
#!/bin/bash

set -eu

function cleanup {
echo "Cleaning up containers..."
docker kill $SERVER_CONTAINER 1>/dev/null 2>/dev/null || true
docker rm --force -v $SERVER_CONTAINER 1>/dev/null 2>/dev/null || true
}
trap cleanup EXIT
echo "### running jest integration spec"
./node_modules/.bin/jest

SERVER_CONTAINER=$(docker run -d \
-e PORT=1234 \
--name integration_server \
gqlgen/golang go run ./integration/server/server.go \
)

sleep 2
echo "### validating introspected schema"
./node_modules/.bin/graphql get-schema

docker run \
-e SERVER_URL=http://integration_server:1234/query \
--link=integration_server \
gqlgen/node ./node_modules/.bin/jest

echo "### server logs"
docker logs $SERVER_CONTAINER

exit $(docker inspect $SERVER_CONTAINER --format='{{.State.ExitCode}}')
if ! diff <(tail -n +3 schema-expected.graphql) <(tail -n +3 schema-fetched.graphql) ; then
echo "The expected schema has changed, you need to update schema-expected.graphql with any expected changes"
exit 1
fi


1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
/docs/public
/example/chat/node_modules
/integration/node_modules
/integration/schema-fetched.graphql
/example/chat/package-lock.json
/codegen/tests/gen

Expand Down
29 changes: 15 additions & 14 deletions graphql/introspection/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,25 +31,26 @@ func WrapTypeFromType(s *ast.Schema, typ *ast.Type) *Type {
}

func (t *Type) Kind() string {
if t.def != nil {
return string(t.def.Kind)
}
if t.typ != nil {
if t.typ.NonNull {
return "NON_NULL"
}

if t.typ.NonNull {
return "NOT_NULL"
if t.typ.Elem != nil {
return "LIST"
}
} else {
return string(t.def.Kind)
}

if t.typ.Elem != nil {
return "LIST"
}
return "UNKNOWN"
panic("UNKNOWN")
}

func (t *Type) Name() string {
func (t *Type) Name() *string {
if t.def == nil {
return ""
return nil
}
return t.def.Name
return &t.def.Name
}

func (t *Type) Description() string {
Expand Down Expand Up @@ -164,10 +165,10 @@ func (t *Type) OfType() *Type {
}
if t.typ.NonNull {
// fake non null nodes
cpy := t.typ
cpy := *t.typ
cpy.NonNull = false

return WrapTypeFromType(t.schema, cpy)
return WrapTypeFromType(t.schema, &cpy)
}
return WrapTypeFromType(t.schema, t.typ.Elem)
}
14 changes: 14 additions & 0 deletions integration/.graphqlconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"projects": {
"Project Name": {
"schemaPath": "schema-fetched.graphql",
"extensions": {
"endpoints": {
"dev": {
"url": "${env:SERVER_URL}"
}
}
}
}
}
}
7 changes: 5 additions & 2 deletions integration/generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 45e22cb

Please sign in to comment.