Skip to content

Commit

Permalink
Graph fixes (#191)
Browse files Browse the repository at this point in the history
* Fix graph owners to be resource ownersand other graph cleanup

Signed-off-by: Nicole Hubbard <code@nicole.dev>

* Add apollo publish

Signed-off-by: Nicole Hubbard <code@nicole.dev>

---------

Signed-off-by: Nicole Hubbard <code@nicole.dev>
  • Loading branch information
nicolerenee authored Jun 29, 2023
1 parent 7846281 commit f7f5f76
Show file tree
Hide file tree
Showing 110 changed files with 7,076 additions and 16,854 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/apollo-studio-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Publish GraphQL Schema
on:
push:
branches:
- main

jobs:
build:
runs-on: ubuntu-latest
env:
APOLLO_KEY: ${{ secrets.APOLLO_KEY }}
APOLLO_VCS_COMMIT: ${{ github.event.pull_request.head.sha }}
steps:
- uses: actions/checkout@v3

- name: Install Rover
run: |
curl -sSL https://rover.apollo.dev/nix/latest | sh
echo "$HOME/.rover/bin" >> $GITHUB_PATH
- name: Publish subgraph schema
run: |
rover subgraph publish --name load-balancer-api --schema schema.graphql infratographer@main
52 changes: 52 additions & 0 deletions db/migrations/20230629085916_drop_status_and_annotations.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
-- +goose Up

-- reverse: create index "loadbalancerstatus_created_at" to table: "load_balancer_status"
DROP INDEX "loadbalancerstatus_created_at";
-- reverse: create index "loadbalancerstatus_load_balancer_id" to table: "load_balancer_status"
DROP INDEX "loadbalancerstatus_load_balancer_id";
-- reverse: create index "loadbalancerstatus_load_balancer_id_namespace_source" to table: "load_balancer_status"
DROP INDEX "loadbalancerstatus_load_balancer_id_namespace_source";
-- reverse: create index "loadbalancerstatus_namespace_data" to table: "load_balancer_status"
DROP INDEX "loadbalancerstatus_namespace_data";
-- reverse: create index "loadbalancerstatus_updated_at" to table: "load_balancer_status"
DROP INDEX "loadbalancerstatus_updated_at";
-- reverse: create "load_balancer_status" table
DROP TABLE "load_balancer_status";
-- reverse: create index "loadbalancerannotation_created_at" to table: "load_balancer_annotations"
DROP INDEX "loadbalancerannotation_created_at";
-- reverse: create index "loadbalancerannotation_load_balancer_id" to table: "load_balancer_annotations"
DROP INDEX "loadbalancerannotation_load_balancer_id";
-- reverse: create index "loadbalancerannotation_load_balancer_id_namespace" to table: "load_balancer_annotations"
DROP INDEX "loadbalancerannotation_load_balancer_id_namespace";
-- reverse: create index "loadbalancerannotation_namespace_data" to table: "load_balancer_annotations"
DROP INDEX "loadbalancerannotation_namespace_data";
-- reverse: create index "loadbalancerannotation_updated_at" to table: "load_balancer_annotations"
DROP INDEX "loadbalancerannotation_updated_at";
-- reverse: create "load_balancer_annotations" table
DROP TABLE "load_balancer_annotations";

-- +goose Down
-- create "load_balancer_annotations" table
CREATE TABLE "load_balancer_annotations" ("id" character varying NOT NULL, "namespace" character varying NOT NULL, "data" jsonb NOT NULL, "created_at" timestamptz NOT NULL, "updated_at" timestamptz NOT NULL, "load_balancer_id" character varying NOT NULL, PRIMARY KEY ("id"), CONSTRAINT "load_balancer_annotations_load_balancers_load_balancer" FOREIGN KEY ("load_balancer_id") REFERENCES "load_balancers" ("id") ON UPDATE NO ACTION ON DELETE NO ACTION);
-- create index "loadbalancerannotation_created_at" to table: "load_balancer_annotations"
CREATE INDEX "loadbalancerannotation_created_at" ON "load_balancer_annotations" ("created_at");
-- create index "loadbalancerannotation_load_balancer_id" to table: "load_balancer_annotations"
CREATE INDEX "loadbalancerannotation_load_balancer_id" ON "load_balancer_annotations" ("load_balancer_id");
-- create index "loadbalancerannotation_load_balancer_id_namespace" to table: "load_balancer_annotations"
CREATE INDEX "loadbalancerannotation_load_balancer_id_namespace" ON "load_balancer_annotations" ("load_balancer_id", "namespace");
-- create index "loadbalancerannotation_namespace_data" to table: "load_balancer_annotations"
CREATE INDEX "loadbalancerannotation_namespace_data" ON "load_balancer_annotations" USING gin ("namespace", "data");
-- create index "loadbalancerannotation_updated_at" to table: "load_balancer_annotations"
CREATE INDEX "loadbalancerannotation_updated_at" ON "load_balancer_annotations" ("updated_at");
-- create "load_balancer_status" table
CREATE TABLE "load_balancer_status" ("id" character varying NOT NULL, "namespace" character varying NOT NULL, "data" jsonb NOT NULL, "created_at" timestamptz NOT NULL, "updated_at" timestamptz NOT NULL, "source" character varying NOT NULL, "load_balancer_id" character varying NOT NULL, PRIMARY KEY ("id"), CONSTRAINT "load_balancer_status_load_balancers_load_balancer" FOREIGN KEY ("load_balancer_id") REFERENCES "load_balancers" ("id") ON UPDATE NO ACTION ON DELETE NO ACTION);
-- create index "loadbalancerstatus_created_at" to table: "load_balancer_status"
CREATE INDEX "loadbalancerstatus_created_at" ON "load_balancer_status" ("created_at");
-- create index "loadbalancerstatus_load_balancer_id" to table: "load_balancer_status"
CREATE INDEX "loadbalancerstatus_load_balancer_id" ON "load_balancer_status" ("load_balancer_id");
-- create index "loadbalancerstatus_load_balancer_id_namespace_source" to table: "load_balancer_status"
CREATE INDEX "loadbalancerstatus_load_balancer_id_namespace_source" ON "load_balancer_status" ("load_balancer_id", "namespace", "source");
-- create index "loadbalancerstatus_namespace_data" to table: "load_balancer_status"
CREATE INDEX "loadbalancerstatus_namespace_data" ON "load_balancer_status" USING gin ("namespace", "data");
-- create index "loadbalancerstatus_updated_at" to table: "load_balancer_status"
CREATE INDEX "loadbalancerstatus_updated_at" ON "load_balancer_status" ("updated_at");
3 changes: 2 additions & 1 deletion db/migrations/atlas.sum
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
h1:VqR1OSr9cOmG9cPyGgjEbDiQxwCpFRLGNlYKzYjpMZc=
h1:c+ziReSuevRk7RBOpYWo0gncdcwco4V61ROlPMPe5EE=
20230503185445_initial-migration.sql h1:4pqNp2MDBBRdGxU/H5mmZui9oi1SyjIiMVGatajrBeY=
20230615194819_drop_tenant_add_owner.sql h1:KGCsItU0NYhxYEkhZOaMQjfIrBMnek5rxC6D/LhnyCk=
20230629085916_drop_status_and_annotations.sql h1:kvDMoaMEjyoj/aRi6rw4XvCLxGH09vGGLbL0/p5tpPo=
109 changes: 80 additions & 29 deletions gen_schema.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// Copyright 2023 The Infratographer Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

//go:build ignore

package main
Expand All @@ -6,6 +20,7 @@ import (
"log"
"os"

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

"go.infratographer.com/load-balancer-api/internal/graphapi"
Expand All @@ -16,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/graphclient/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"
]
)
`)
16 changes: 7 additions & 9 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@ module go.infratographer.com/load-balancer-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.4-0.20230503082810-f251400818ea
github.com/99designs/gqlgen v0.17.31
github.com/Yamashou/gqlgenc v0.13.5
github.com/brianvoe/gofakeit/v6 v6.21.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/docker/go-connections v0.4.0
github.com/hashicorp/go-multierror v1.1.1
github.com/labstack/echo/v4 v4.10.2
Expand All @@ -20,9 +18,9 @@ require (
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.1
github.com/testcontainers/testcontainers-go v0.21.0
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.62.3
go.infratographer.com/permissions-api v0.1.11
go.infratographer.com/x v0.3.2
Expand Down Expand Up @@ -68,7 +66,7 @@ require (
github.com/gorilla/websocket v1.5.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.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 Down
Loading

0 comments on commit f7f5f76

Please sign in to comment.