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

chore: update demo #591

Merged
merged 27 commits into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
7c7c7e1
Federation: update demo to include cycles
clayne11 Jan 26, 2024
6db18ee
Show how using nested entity keys causes bugs.
clayne11 Feb 1, 2024
6f91769
Move hobby back to being an interface
clayne11 Feb 1, 2024
995e93e
Remove details and move to employees
clayne11 Feb 1, 2024
edde984
Fix some of the tests
clayne11 Feb 1, 2024
30a8bdf
Fix tests
clayne11 Feb 1, 2024
8ea3f76
Add new test
clayne11 Feb 2, 2024
9f7bfc7
Merge branch 'main' into curtis.layne/demo-federation
devsergiy Feb 16, 2024
d04000c
revert details as entity
devsergiy Mar 1, 2024
c72308d
add compose.sh
devsergiy Mar 1, 2024
a9703f3
Merge remote-tracking branch 'origin/main' into chore/update-demo
devsergiy Mar 1, 2024
279a3eb
go work sync
devsergiy Mar 1, 2024
22a2c5c
update test queries structure
devsergiy Mar 1, 2024
b288ad6
add goldie
devsergiy Mar 1, 2024
ce30842
add update test config cmd
devsergiy Mar 1, 2024
c90d6f5
update testenv router config
devsergiy Mar 1, 2024
67607be
fix replacing urls in the test env config
devsergiy Mar 1, 2024
138d355
update fixtures
devsergiy Mar 1, 2024
4c120ea
Merge branch 'main' into chore/update-demo
devsergiy Mar 1, 2024
8cbcfaa
fix go test config generation
devsergiy Mar 4, 2024
898034f
fix tracing test
devsergiy Mar 4, 2024
46b90fa
Merge branch 'main' into chore/update-demo
devsergiy Mar 4, 2024
6beb854
enable back report websocket stats
devsergiy Mar 4, 2024
334c62d
fix: do not require details in demo subgraphs
devsergiy Mar 4, 2024
c562272
chore: add to readme a guide how to update snaphots
devsergiy Mar 4, 2024
07ba69b
replace go-snaps with goldie
devsergiy Mar 4, 2024
d345173
chore: remove line break added by ide
devsergiy Mar 4, 2024
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
Prev Previous commit
Next Next commit
Show how using nested entity keys causes bugs.
  • Loading branch information
clayne11 committed Feb 1, 2024
commit 6db18eefc0d90224cf4a77a02588eccee1489aae
13 changes: 13 additions & 0 deletions demo/Dockerfile.countries
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM golang:1.21 as builder

WORKDIR /app

COPY . ./

RUN go mod download && go mod verify

RUN go build ./cmd/countries && mv countries server

ENTRYPOINT [ "./server" ]

EXPOSE 4008
2 changes: 2 additions & 0 deletions demo/cmd/all/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ var (
test1 = flag.Int("test1", 4006, "Port for test1 subgraph")
availability = flag.Int("availability", 4007, "Port for availability subgraph")
mood = flag.Int("mood", 4008, "Port for mood subgraph")
countries = flag.Int("countries", 4009, "Port for countries subgraph")
)

func main() {
Expand All @@ -31,6 +32,7 @@ func main() {
Test1: *test1,
Availability: *availability,
Mood: *mood,
Countries: *countries,
},
EnableDebug: *debug,
}
Expand Down
1 change: 1 addition & 0 deletions demo/cmd/countries/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/countries
10 changes: 10 additions & 0 deletions demo/cmd/countries/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Cosmo demo service

This directory contains a service used for cosmo demos.

## OpenTelemetry

To configure OpenTelemtry, the following environment variables are available:

- `OTEL_HTTP_ENDPOINT`: Sets the endpoint for the OTEL collector. If empty, it defaults to `localhost:4318`.
- `OTEL_AUTH_TOKEN`: Sets the token used to authenticate with the OTEL collector.
53 changes: 53 additions & 0 deletions demo/cmd/countries/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package main

import (
"context"
"fmt"
"github.com/wundergraph/cosmo/demo/pkg/subgraphs/countries"
"log"
"net/http"
"os"

"github.com/99designs/gqlgen/graphql"
"github.com/99designs/gqlgen/graphql/handler/debug"
"github.com/99designs/gqlgen/graphql/playground"
"github.com/ravilushqa/otelgqlgen"
"github.com/rs/cors"
"github.com/wundergraph/cosmo/demo/pkg/injector"
"github.com/wundergraph/cosmo/demo/pkg/otel"
"github.com/wundergraph/cosmo/demo/pkg/subgraphs"
"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
)

const (
defaultPort = "4009"
serviceName = "countries"
)

func main() {
otel.InitTracing(context.Background(), otel.Options{ServiceName: serviceName})
port := os.Getenv("PORT")
if port == "" {
port = defaultPort
}

srv := subgraphs.NewDemoServer(countries.NewSchema(nil))

srv.Use(&debug.Tracer{})
srv.Use(otelgqlgen.Middleware(otelgqlgen.WithCreateSpanFromFields(func(ctx *graphql.FieldContext) bool {
return true
})))

c := cors.New(cors.Options{
AllowedOrigins: []string{"*"},
AllowedHeaders: []string{"*"},
})

http.Handle("/", c.Handler(playground.Handler("GraphQL playground", "/graphql")))
http.Handle("/graphql", injector.HTTP(c.Handler(otelhttp.NewHandler(srv, "", otelhttp.WithSpanNameFormatter(func(_operation string, r *http.Request) string {
return fmt.Sprintf("%s %s", r.Method, r.URL.Path)
})))))

log.Printf("connect to http://localhost:%s/ for GraphQL playground", port)
log.Fatal(http.ListenAndServe(":"+port, nil))
}
10 changes: 10 additions & 0 deletions demo/cmd/generateconfig/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ func main() {

mood := subgraphs.MoodHandler(&subgraphs.SubgraphOptions{})

countries := subgraphs.CountriesHandler(&subgraphs.SubgraphOptions{})

employeesServer := httptest.NewServer(employees)
defer employeesServer.Close()
familyServer := httptest.NewServer(family)
Expand All @@ -43,6 +45,8 @@ func main() {
defer availabilityServer.Close()
moodServer := httptest.NewServer(mood)
defer moodServer.Close()
countriesServer := httptest.NewServer(countries)
defer countriesServer.Close()

employeeUpdatedSchema, err := os.ReadFile(filepath.Join("..", "..", "pkg", "subgraphs", "employeeupdated", "subgraph", "schema.graphqls"))
if err != nil {
Expand Down Expand Up @@ -78,6 +82,10 @@ func main() {
Name: "mood",
URL: gqlURL(moodServer),
},
{
Name: "countries",
URL: gqlURL(countriesServer),
},
{
Name: "employeeupdated",
Schema: string(employeeUpdatedSchema),
Expand Down Expand Up @@ -112,6 +120,8 @@ func main() {
return "{{ .AvailabilityURL }}"
case sgs[6].URL:
return "{{ .MoodURL }}"
case sgs[7].URL:
return "{{ .CountriesURL }}"
default:
return s
}
Expand Down
2 changes: 1 addition & 1 deletion demo/config.json

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion demo/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ subgraphs:
schema:
file: ./pkg/subgraphs/availability/subgraph/schema.graphqls
- name: mood
routing_url: http://localhos2:4008/graphql
routing_url: http://localhost:4008/graphql
schema:
file: ./pkg/subgraphs/mood/subgraph/schema.graphqls
- name: countries
routing_url: http://localhost:4009/graphql
schema:
file: ./pkg/subgraphs/countries/subgraph/schema.graphqls
15 changes: 15 additions & 0 deletions demo/pkg/subgraphs/countries/countries.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package countries

import (
"github.com/99designs/gqlgen/graphql"
"github.com/nats-io/nats.go"

"github.com/wundergraph/cosmo/demo/pkg/subgraphs/countries/subgraph"
"github.com/wundergraph/cosmo/demo/pkg/subgraphs/countries/subgraph/generated"
)

func NewSchema(nc *nats.Conn) graphql.ExecutableSchema {
return generated.NewExecutableSchema(generated.Config{Resolvers: &subgraph.Resolver{
NC: nc,
}})
}
2 changes: 2 additions & 0 deletions demo/pkg/subgraphs/countries/generate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
//go:generate go run github.com/99designs/gqlgen generate
package countries
57 changes: 57 additions & 0 deletions demo/pkg/subgraphs/countries/gqlgen.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Where are all the schema files located? globs are supported eg src/**/*.graphqls
schema:
- subgraph/*.graphqls

# Where should the generated server code go?
exec:
filename: subgraph/generated/generated.go
package: generated

federation:
filename: subgraph/generated/federation.go
package: generated
version: 2

# Where should any generated models go?
model:
filename: subgraph/model/models_gen.go
package: model

# Where should the resolver implementations go?
resolver:
layout: follow-schema
dir: subgraph
package: subgraph

# Optional: turn on use `gqlgen:"fieldName"` tags in your models
# struct_tag: json

# Optional: turn on to use []Thing instead of []*Thing
# omit_slice_element_pointers: false

# Optional: set to speed up generation time by not performing a final validation pass.
# skip_validation: true

# This section declares type mapping between the GraphQL and go type systems
#
# The first line in each type will be used as defaults for resolver arguments and
# modelgen, the others will be allowed when binding to fields. Configure them to
# your liking
models:
ID:
model:
- github.com/99designs/gqlgen/graphql.ID
- github.com/99designs/gqlgen/graphql.Int
- github.com/99designs/gqlgen/graphql.Int64
- github.com/99designs/gqlgen/graphql.Int32
Int:
model:
- github.com/99designs/gqlgen/graphql.Int
- github.com/99designs/gqlgen/graphql.Int64
- github.com/99designs/gqlgen/graphql.Int32
Documentation:
fields:
url:
resolver: true
urls:
resolver: true
82 changes: 82 additions & 0 deletions demo/pkg/subgraphs/countries/subgraph/countries.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package subgraph

import "github.com/wundergraph/cosmo/demo/pkg/subgraphs/countries/subgraph/model"

func strToPtr(s string) *string {
return &s
}

var countries = []*model.Country{
{
Key: &model.CountryKey{
Name: "America",
},
Language: strToPtr("English"),
},
{
Key: &model.CountryKey{
Name: "England",
},
Language: strToPtr("English"),
},
{
Key: &model.CountryKey{
Name: "Germany",
},
Language: strToPtr("German"),
},
{
Key: &model.CountryKey{
Name: "India",
},
Language: strToPtr("Hindi"),
},
{
Key: &model.CountryKey{
Name: "Netherlands",
},
Language: strToPtr("Dutch"),
},
{
Key: &model.CountryKey{
Name: "Portugal",
},
Language: strToPtr("Portuguese"),
},
{
Key: &model.CountryKey{
Name: "Spain",
},
Language: strToPtr("Spanish"),
},
{
Key: &model.CountryKey{
Name: "Ukraine",
},
Language: strToPtr("Ukrainian"),
},
{
Key: &model.CountryKey{
Name: "Indonesia",
},
Language: strToPtr("Indonesian"),
},
{
Key: &model.CountryKey{
Name: "Thailand",
},
Language: strToPtr("Thai"),
},
{
Key: &model.CountryKey{
Name: "Korea",
},
Language: strToPtr("Korean"),
},
{
Key: &model.CountryKey{
Name: "Taiwan",
},
Language: strToPtr("Taiwanese"),
},
}
28 changes: 28 additions & 0 deletions demo/pkg/subgraphs/countries/subgraph/entity.resolvers.go

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

Loading