Skip to content

Commit

Permalink
Update schema.graphql gen with new changes; update dependencies (#34)
Browse files Browse the repository at this point in the history
Signed-off-by: Nicole Hubbard <[email protected]>
  • Loading branch information
nicolerenee authored Jun 29, 2023
1 parent f0a9cdf commit f7a1681
Show file tree
Hide file tree
Showing 24 changed files with 1,157 additions and 617 deletions.
6 changes: 2 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ test: | unit-test
unit-test: ## Runs unit tests
@echo --- Running unit tests...
@date --rfc-3339=seconds
@go test -race -cover -failfast -tags testtools -p 1 -v ./...
@go test -race -cover -failfast -tags testtools ./...

coverage: ## Generates coverage report
@echo --- Generating coverage report...
Expand Down Expand Up @@ -65,9 +65,7 @@ dev-nats: ## Initializes nats
@date --rfc-3339=seconds
@.devcontainer/scripts/nats_account.sh

generate: background-run .generate kill-running ## Generates code

.generate: vendor
generate: vendor
@echo --- Generating code...
@date --rfc-3339=seconds
@go generate ./...
Expand Down
95 changes: 66 additions & 29 deletions gen-schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"log"
"os"

"github.com/vektah/gqlparser/v2/ast"
"github.com/vektah/gqlparser/v2/formatter"

"go.infratographer.com/ipam-api/internal/graphapi"
Expand All @@ -30,49 +31,85 @@ func main() {
execSchema := graphapi.NewExecutableSchema(graphapi.Config{})
schema := execSchema.Schema()

// remove codegen directives that we don't want in published schema
for _, t := range schema.Types {
dirs := ast.DirectiveList{}
for _, td := range t.Directives {
switch td.Name {
case "goField", "goModel":
continue
default:
dirs = append(dirs, td)
}
}
t.Directives = dirs

for _, f := range t.Fields {
dirs := ast.DirectiveList{}
for _, fd := range f.Directives {
switch fd.Name {
case "goField", "goModel":
continue
default:
dirs = append(dirs, fd)
}
}
f.Directives = dirs
}
}

delete(schema.Directives, "goField")
delete(schema.Directives, "goModel")

// Some of our federation fields get marked as "BuiltIn" by gengql and the formatter doesn't print builtin types, this adds them for us.
entities := schema.Types["_Entity"]
entities.BuiltIn = false
service := schema.Types["_Service"]
service.BuiltIn = false
// entities.Position.Src.BuiltIn = false
entityType := schema.Types["_Entity"]
entityType.BuiltIn = false
serviceType := schema.Types["_Service"]
serviceType.BuiltIn = false
anyType := schema.Types["_Any"]
anyType.BuiltIn = false

f, err := os.Create("schema.graphql")
if err != nil {
log.Fatal(err)
}
defer f.Close()
fmtr := formatter.NewFormatter(f)

fmtr := formatter.NewFormatter(f)
fmtr.FormatSchema(schema)

f.Write(federationSchema)

// Write testclient schema, include all federation params
// find the internal federation src and mark it as not builtin. "interfaceObject" is a federation directive,
// so we use that to look up the source
intObj := schema.Directives["interfaceObject"]
intObj.Position.Src.BuiltIn = false
schema.Types["FieldSet"].BuiltIn = false

clientSchema, err := os.Create("internal/testclient/schema/schema.graphql")
if err != nil {
log.Fatal(err)
}
defer clientSchema.Close()

fmtr = formatter.NewFormatter(clientSchema)
fmtr.FormatSchema(schema)
}

var federationSchema = []byte(`scalar _Any
scalar FieldSet
directive @requires(fields: FieldSet!) on FIELD_DEFINITION
directive @provides(fields: FieldSet!) on FIELD_DEFINITION
directive @extends on OBJECT | INTERFACE
directive @key(fields: FieldSet!, resolvable: Boolean = true) repeatable on OBJECT | INTERFACE
directive @link(import: [String!], url: String!) repeatable on SCHEMA
directive @external on FIELD_DEFINITION | OBJECT
directive @shareable on OBJECT | FIELD_DEFINITION
directive @tag(name: String!) repeatable on FIELD_DEFINITION | INTERFACE | OBJECT | UNION | ARGUMENT_DEFINITION | SCALAR | ENUM | ENUM_VALUE | INPUT_OBJECT | INPUT_FIELD_DEFINITION
directive @override(from: String!) on FIELD_DEFINITION
directive @inaccessible on SCALAR | OBJECT | FIELD_DEFINITION | ARGUMENT_DEFINITION | INTERFACE | UNION | ENUM | ENUM_VALUE | INPUT_OBJECT | INPUT_FIELD_DEFINITION
directive @interfaceObject on OBJECT
var federationSchema = []byte(`
extend schema
@link(
url: "https://specs.apollo.dev/federation/v2.3"
import: [
"@key",
"@external",
"@shareable",
"@tag",
"@override",
"@inaccessible",
"@interfaceObject"
]
url: "https://specs.apollo.dev/federation/v2.3"
import: [
"@key",
"@interfaceObject",
"@shareable",
"@inaccessible",
"@override",
"@provides",
"@requires",
"@tag"
]
)
`)
36 changes: 17 additions & 19 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,45 +2,41 @@ module go.infratographer.com/ipam-api

go 1.20

replace github.com/testcontainers/testcontainers-go => github.com/testcontainers/testcontainers-go v0.0.0-20230503220718-0df60de8ccd8

require (
entgo.io/contrib v0.4.5
entgo.io/ent v0.12.3
github.com/3th1nk/cidr v0.2.0
github.com/99designs/gqlgen v0.17.32
github.com/Yamashou/gqlgenc v0.13.5
github.com/brianvoe/gofakeit/v6 v6.21.0
github.com/docker/go-connections v0.4.0
github.com/99designs/gqlgen v0.17.34
github.com/Yamashou/gqlgenc v0.14.0
github.com/brianvoe/gofakeit/v6 v6.22.0
github.com/hashicorp/go-multierror v1.1.1
github.com/labstack/echo/v4 v4.10.2
github.com/lib/pq v1.10.9
github.com/mattn/go-sqlite3 v1.14.16
github.com/mattn/go-sqlite3 v1.14.17
github.com/mitchellh/go-homedir v1.1.0
github.com/shurcooL/graphql v0.0.0-20220606043923-3cf50f8a0a29
github.com/spf13/cobra v1.7.0
github.com/spf13/viper v1.16.0
github.com/stretchr/testify v1.8.4
github.com/testcontainers/testcontainers-go v0.20.1
github.com/testcontainers/testcontainers-go/modules/postgres v0.20.1
github.com/vektah/gqlparser/v2 v2.5.2-0.20230422221642-25e09f9d292d
github.com/wundergraph/graphql-go-tools v1.63.1
github.com/testcontainers/testcontainers-go/modules/postgres v0.21.0
github.com/vektah/gqlparser/v2 v2.5.6
github.com/wundergraph/graphql-go-tools v1.63.2
go.infratographer.com/x v0.3.2
go.uber.org/zap v1.24.0
golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1
golang.org/x/exp v0.0.0-20230626212559-97b1e661b5df
)

require (
github.com/ThreeDotsLabs/watermill v1.2.0 // indirect
github.com/ThreeDotsLabs/watermill-nats/v2 v2.0.0 // indirect
github.com/garsue/watermillzap v1.2.0 // indirect
github.com/gofrs/uuid v4.3.1+incompatible // indirect
github.com/gofrs/uuid v4.4.0+incompatible // indirect
github.com/kylelemons/godebug v1.1.0 // indirect
github.com/lithammer/shortuuid/v3 v3.0.7 // indirect
github.com/minio/highwayhash v1.0.2 // indirect
github.com/nats-io/jwt/v2 v2.4.1 // indirect
github.com/nats-io/nats-server/v2 v2.9.17 // indirect
github.com/nats-io/nats.go v1.26.0 // indirect
github.com/nats-io/nats-server/v2 v2.9.19 // indirect
github.com/nats-io/nats.go v1.27.1 // indirect
github.com/nats-io/nkeys v0.4.4 // indirect
github.com/nats-io/nuid v1.0.1 // indirect
github.com/oklog/ulid v1.3.1 // indirect
Expand All @@ -64,6 +60,7 @@ require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/docker/distribution v2.8.2+incompatible // indirect
github.com/docker/docker v23.0.6+incompatible // indirect
github.com/docker/go-connections v0.4.0 // indirect
github.com/docker/go-units v0.5.0 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/go-logr/logr v1.2.4 // indirect
Expand All @@ -78,7 +75,7 @@ require (
github.com/gorilla/websocket v1.5.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.15.0 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/golang-lru/v2 v2.0.1 // indirect
github.com/hashicorp/golang-lru/v2 v2.0.3 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/hashicorp/hcl/v2 v2.13.0 // indirect
github.com/imdario/mergo v0.3.15 // indirect
Expand All @@ -99,7 +96,7 @@ require (
github.com/labstack/gommon v0.4.0 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.18 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/mitchellh/go-wordwrap v0.0.0-20150314170334-ad45545899c7 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
Expand All @@ -126,6 +123,7 @@ require (
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/subosito/gotenv v1.4.2 // indirect
github.com/testcontainers/testcontainers-go v0.21.0 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasttemplate v1.2.2 // indirect
github.com/vmihailenco/msgpack/v5 v5.0.0-beta.9 // indirect
Expand All @@ -146,12 +144,12 @@ require (
go.uber.org/atomic v1.10.0 // indirect
go.uber.org/multierr v1.9.0 // indirect
golang.org/x/crypto v0.9.0 // indirect
golang.org/x/mod v0.10.0 // indirect
golang.org/x/mod v0.11.0 // indirect
golang.org/x/net v0.10.0 // indirect
golang.org/x/sys v0.8.0 // indirect
golang.org/x/text v0.9.0 // indirect
golang.org/x/time v0.3.0 // indirect
golang.org/x/tools v0.9.1 // indirect
golang.org/x/tools v0.9.3 // indirect
google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1 // indirect
google.golang.org/grpc v1.55.0 // indirect
google.golang.org/protobuf v1.30.0 // indirect
Expand Down
Loading

0 comments on commit f7a1681

Please sign in to comment.