Skip to content

Commit

Permalink
Merge pull request #572 from 99designs/handle-nonexistant-directories…
Browse files Browse the repository at this point in the history
…-when-genreating-packagenames

Handle non-existant directories when generating default package names
  • Loading branch information
vektah authored Mar 4, 2019
2 parents 2ef4b44 + 0892333 commit 3d9ad75
Show file tree
Hide file tree
Showing 11 changed files with 335 additions and 302 deletions.
15 changes: 10 additions & 5 deletions example/starwars/.gqlgen.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
exec:
filename: generated/exec.go
model:
filename: models/generated.go

models:
Droid:
model: github.com/99designs/gqlgen/example/starwars.Droid
model: github.com/99designs/gqlgen/example/starwars/models.Droid
FriendsConnection:
model: github.com/99designs/gqlgen/example/starwars.FriendsConnection
model: github.com/99designs/gqlgen/example/starwars/models.FriendsConnection
Human:
model: github.com/99designs/gqlgen/example/starwars.Human
model: github.com/99designs/gqlgen/example/starwars/models.Human
Review:
model: github.com/99designs/gqlgen/example/starwars.Review
model: github.com/99designs/gqlgen/example/starwars/models.Review
ReviewInput:
model: github.com/99designs/gqlgen/example/starwars.Review
model: github.com/99designs/gqlgen/example/starwars/models.Review
Starship:
fields:
length:
Expand Down
3 changes: 2 additions & 1 deletion example/starwars/benchmarks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ import (
"strings"
"testing"

"github.com/99designs/gqlgen/example/starwars/generated"
"github.com/99designs/gqlgen/handler"
)

func BenchmarkSimpleQueryNoArgs(b *testing.B) {
server := handler.GraphQL(NewExecutableSchema(NewResolver()))
server := handler.GraphQL(generated.NewExecutableSchema(NewResolver()))

q := `{"query":"{ search(text:\"Luke\") { ... on Human { starships { name } } } }"}`

Expand Down
363 changes: 182 additions & 181 deletions example/starwars/generated.go → example/starwars/generated/exec.go

Large diffs are not rendered by default.

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

56 changes: 12 additions & 44 deletions example/starwars/model.go → example/starwars/models/model.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
package starwars
package models

import (
"context"
"encoding/base64"
"fmt"
"strconv"
"strings"
"time"
)

Expand All @@ -19,16 +16,16 @@ type CharacterFields struct {
type Human struct {
CharacterFields
StarshipIds []string
heightMeters float64
HeightMeters float64
Mass float64
}

func (h *Human) Height(unit LengthUnit) float64 {
switch unit {
case "METER", "":
return h.heightMeters
return h.HeightMeters
case "FOOT":
return h.heightMeters * 3.28084
return h.HeightMeters * 3.28084
default:
panic("invalid unit")
}
Expand All @@ -51,53 +48,24 @@ type Droid struct {
func (Droid) IsCharacter() {}
func (Droid) IsSearchResult() {}

func (r *Resolver) resolveFriendConnection(ctx context.Context, ids []string, first *int, after *string) (*FriendsConnection, error) {
from := 0
if after != nil {
b, err := base64.StdEncoding.DecodeString(*after)
if err != nil {
return nil, err
}
i, err := strconv.Atoi(strings.TrimPrefix(string(b), "cursor"))
if err != nil {
return nil, err
}
from = i
}

to := len(ids)
if first != nil {
to = from + *first
if to > len(ids) {
to = len(ids)
}
}

return &FriendsConnection{
ids: ids,
from: from,
to: to,
}, nil
}

type FriendsConnection struct {
ids []string
from int
to int
Ids []string
From int
To int
}

func (f *FriendsConnection) TotalCount() int {
return len(f.ids)
return len(f.Ids)
}

func (f *FriendsConnection) PageInfo() PageInfo {
return PageInfo{
StartCursor: encodeCursor(f.from),
EndCursor: encodeCursor(f.to - 1),
HasNextPage: f.to < len(f.ids),
StartCursor: EncodeCursor(f.From),
EndCursor: EncodeCursor(f.To - 1),
HasNextPage: f.To < len(f.Ids),
}
}

func encodeCursor(i int) string {
func EncodeCursor(i int) string {
return base64.StdEncoding.EncodeToString([]byte(fmt.Sprintf("cursor%d", i+1)))
}
Loading

0 comments on commit 3d9ad75

Please sign in to comment.