From 08923334725c963ffcff948efe030881d658c38a Mon Sep 17 00:00:00 2001 From: Adam Scarr Date: Mon, 4 Mar 2019 15:11:34 +1100 Subject: [PATCH] Handle non-existant directories when generating default package names --- example/starwars/.gqlgen.yml | 15 +- example/starwars/benchmarks_test.go | 3 +- .../{generated.go => generated/exec.go} | 363 +++++++++--------- .../{models_gen.go => models/generated.go} | 2 +- example/starwars/{ => models}/model.go | 56 +-- example/starwars/resolvers.go | 166 ++++---- example/starwars/server/server.go | 3 +- example/starwars/starwars_test.go | 3 +- internal/code/imports.go | 16 +- internal/code/imports_test.go | 2 +- plugin/stubgen/stubs.go | 8 +- 11 files changed, 335 insertions(+), 302 deletions(-) rename example/starwars/{generated.go => generated/exec.go} (90%) rename example/starwars/{models_gen.go => models/generated.go} (99%) rename example/starwars/{ => models}/model.go (50%) diff --git a/example/starwars/.gqlgen.yml b/example/starwars/.gqlgen.yml index 49f10ad9700..42d07800ed9 100644 --- a/example/starwars/.gqlgen.yml +++ b/example/starwars/.gqlgen.yml @@ -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: diff --git a/example/starwars/benchmarks_test.go b/example/starwars/benchmarks_test.go index 8386b7963f0..f0d9e1f0438 100644 --- a/example/starwars/benchmarks_test.go +++ b/example/starwars/benchmarks_test.go @@ -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 } } } }"}` diff --git a/example/starwars/generated.go b/example/starwars/generated/exec.go similarity index 90% rename from example/starwars/generated.go rename to example/starwars/generated/exec.go index 99116eac698..65c84b4aa76 100644 --- a/example/starwars/generated.go +++ b/example/starwars/generated/exec.go @@ -1,6 +1,6 @@ // Code generated by github.com/99designs/gqlgen, DO NOT EDIT. -package starwars +package generated import ( "bytes" @@ -11,6 +11,7 @@ import ( "sync" "time" + "github.com/99designs/gqlgen/example/starwars/models" "github.com/99designs/gqlgen/graphql" "github.com/99designs/gqlgen/graphql/introspection" "github.com/vektah/gqlparser" @@ -71,7 +72,7 @@ type ComplexityRoot struct { Human struct { ID func(childComplexity int) int Name func(childComplexity int) int - Height func(childComplexity int, unit LengthUnit) int + Height func(childComplexity int, unit models.LengthUnit) int Mass func(childComplexity int) int Friends func(childComplexity int) int FriendsConnection func(childComplexity int, first *int, after *string) int @@ -80,7 +81,7 @@ type ComplexityRoot struct { } Mutation struct { - CreateReview func(childComplexity int, episode Episode, review Review) int + CreateReview func(childComplexity int, episode models.Episode, review models.Review) int } PageInfo struct { @@ -90,8 +91,8 @@ type ComplexityRoot struct { } Query struct { - Hero func(childComplexity int, episode *Episode) int - Reviews func(childComplexity int, episode Episode, since *time.Time) int + Hero func(childComplexity int, episode *models.Episode) int + Reviews func(childComplexity int, episode models.Episode, since *time.Time) int Search func(childComplexity int, text string) int Character func(childComplexity int, id string) int Droid func(childComplexity int, id string) int @@ -108,39 +109,39 @@ type ComplexityRoot struct { Starship struct { ID func(childComplexity int) int Name func(childComplexity int) int - Length func(childComplexity int, unit *LengthUnit) int + Length func(childComplexity int, unit *models.LengthUnit) int History func(childComplexity int) int } } type DroidResolver interface { - Friends(ctx context.Context, obj *Droid) ([]Character, error) - FriendsConnection(ctx context.Context, obj *Droid, first *int, after *string) (*FriendsConnection, error) + Friends(ctx context.Context, obj *models.Droid) ([]models.Character, error) + FriendsConnection(ctx context.Context, obj *models.Droid, first *int, after *string) (*models.FriendsConnection, error) } type FriendsConnectionResolver interface { - Edges(ctx context.Context, obj *FriendsConnection) ([]FriendsEdge, error) - Friends(ctx context.Context, obj *FriendsConnection) ([]Character, error) + Edges(ctx context.Context, obj *models.FriendsConnection) ([]models.FriendsEdge, error) + Friends(ctx context.Context, obj *models.FriendsConnection) ([]models.Character, error) } type HumanResolver interface { - Friends(ctx context.Context, obj *Human) ([]Character, error) - FriendsConnection(ctx context.Context, obj *Human, first *int, after *string) (*FriendsConnection, error) + Friends(ctx context.Context, obj *models.Human) ([]models.Character, error) + FriendsConnection(ctx context.Context, obj *models.Human, first *int, after *string) (*models.FriendsConnection, error) - Starships(ctx context.Context, obj *Human) ([]Starship, error) + Starships(ctx context.Context, obj *models.Human) ([]models.Starship, error) } type MutationResolver interface { - CreateReview(ctx context.Context, episode Episode, review Review) (*Review, error) + CreateReview(ctx context.Context, episode models.Episode, review models.Review) (*models.Review, error) } type QueryResolver interface { - Hero(ctx context.Context, episode *Episode) (Character, error) - Reviews(ctx context.Context, episode Episode, since *time.Time) ([]Review, error) - Search(ctx context.Context, text string) ([]SearchResult, error) - Character(ctx context.Context, id string) (Character, error) - Droid(ctx context.Context, id string) (*Droid, error) - Human(ctx context.Context, id string) (*Human, error) - Starship(ctx context.Context, id string) (*Starship, error) + Hero(ctx context.Context, episode *models.Episode) (models.Character, error) + Reviews(ctx context.Context, episode models.Episode, since *time.Time) ([]models.Review, error) + Search(ctx context.Context, text string) ([]models.SearchResult, error) + Character(ctx context.Context, id string) (models.Character, error) + Droid(ctx context.Context, id string) (*models.Droid, error) + Human(ctx context.Context, id string) (*models.Human, error) + Starship(ctx context.Context, id string) (*models.Starship, error) } type StarshipResolver interface { - Length(ctx context.Context, obj *Starship, unit *LengthUnit) (float64, error) + Length(ctx context.Context, obj *models.Starship, unit *models.LengthUnit) (float64, error) } type executableSchema struct { @@ -271,7 +272,7 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return 0, false } - return e.complexity.Human.Height(childComplexity, args["unit"].(LengthUnit)), true + return e.complexity.Human.Height(childComplexity, args["unit"].(models.LengthUnit)), true case "Human.Mass": if e.complexity.Human.Mass == nil { @@ -323,7 +324,7 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return 0, false } - return e.complexity.Mutation.CreateReview(childComplexity, args["episode"].(Episode), args["review"].(Review)), true + return e.complexity.Mutation.CreateReview(childComplexity, args["episode"].(models.Episode), args["review"].(models.Review)), true case "PageInfo.StartCursor": if e.complexity.PageInfo.StartCursor == nil { @@ -356,7 +357,7 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return 0, false } - return e.complexity.Query.Hero(childComplexity, args["episode"].(*Episode)), true + return e.complexity.Query.Hero(childComplexity, args["episode"].(*models.Episode)), true case "Query.Reviews": if e.complexity.Query.Reviews == nil { @@ -368,7 +369,7 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return 0, false } - return e.complexity.Query.Reviews(childComplexity, args["episode"].(Episode), args["since"].(*time.Time)), true + return e.complexity.Query.Reviews(childComplexity, args["episode"].(models.Episode), args["since"].(*time.Time)), true case "Query.Search": if e.complexity.Query.Search == nil { @@ -475,7 +476,7 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return 0, false } - return e.complexity.Starship.Length(childComplexity, args["unit"].(*LengthUnit)), true + return e.complexity.Starship.Length(childComplexity, args["unit"].(*models.LengthUnit)), true case "Starship.History": if e.complexity.Starship.History == nil { @@ -746,9 +747,9 @@ func (ec *executionContext) field_Human_friendsConnection_args(ctx context.Conte func (ec *executionContext) field_Human_height_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { var err error args := map[string]interface{}{} - var arg0 LengthUnit + var arg0 models.LengthUnit if tmp, ok := rawArgs["unit"]; ok { - arg0, err = ec.unmarshalOLengthUnit2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚐLengthUnit(ctx, tmp) + arg0, err = ec.unmarshalOLengthUnit2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚋmodelsᚐLengthUnit(ctx, tmp) if err != nil { return nil, err } @@ -760,17 +761,17 @@ func (ec *executionContext) field_Human_height_args(ctx context.Context, rawArgs func (ec *executionContext) field_Mutation_createReview_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { var err error args := map[string]interface{}{} - var arg0 Episode + var arg0 models.Episode if tmp, ok := rawArgs["episode"]; ok { - arg0, err = ec.unmarshalNEpisode2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚐEpisode(ctx, tmp) + arg0, err = ec.unmarshalNEpisode2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚋmodelsᚐEpisode(ctx, tmp) if err != nil { return nil, err } } args["episode"] = arg0 - var arg1 Review + var arg1 models.Review if tmp, ok := rawArgs["review"]; ok { - arg1, err = ec.unmarshalNReviewInput2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚐReview(ctx, tmp) + arg1, err = ec.unmarshalNReviewInput2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚋmodelsᚐReview(ctx, tmp) if err != nil { return nil, err } @@ -824,9 +825,9 @@ func (ec *executionContext) field_Query_droid_args(ctx context.Context, rawArgs func (ec *executionContext) field_Query_hero_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { var err error args := map[string]interface{}{} - var arg0 *Episode + var arg0 *models.Episode if tmp, ok := rawArgs["episode"]; ok { - arg0, err = ec.unmarshalOEpisode2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚐEpisode(ctx, tmp) + arg0, err = ec.unmarshalOEpisode2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚋmodelsᚐEpisode(ctx, tmp) if err != nil { return nil, err } @@ -852,9 +853,9 @@ func (ec *executionContext) field_Query_human_args(ctx context.Context, rawArgs func (ec *executionContext) field_Query_reviews_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { var err error args := map[string]interface{}{} - var arg0 Episode + var arg0 models.Episode if tmp, ok := rawArgs["episode"]; ok { - arg0, err = ec.unmarshalNEpisode2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚐEpisode(ctx, tmp) + arg0, err = ec.unmarshalNEpisode2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚋmodelsᚐEpisode(ctx, tmp) if err != nil { return nil, err } @@ -902,9 +903,9 @@ func (ec *executionContext) field_Query_starship_args(ctx context.Context, rawAr func (ec *executionContext) field_Starship_length_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { var err error args := map[string]interface{}{} - var arg0 *LengthUnit + var arg0 *models.LengthUnit if tmp, ok := rawArgs["unit"]; ok { - arg0, err = ec.unmarshalOLengthUnit2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚐLengthUnit(ctx, tmp) + arg0, err = ec.unmarshalOLengthUnit2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚋmodelsᚐLengthUnit(ctx, tmp) if err != nil { return nil, err } @@ -945,7 +946,7 @@ func (ec *executionContext) field___Type_fields_args(ctx context.Context, rawArg // region **************************** field.gotpl ***************************** -func (ec *executionContext) _Droid_id(ctx context.Context, field graphql.CollectedField, obj *Droid) graphql.Marshaler { +func (ec *executionContext) _Droid_id(ctx context.Context, field graphql.CollectedField, obj *models.Droid) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ @@ -971,7 +972,7 @@ func (ec *executionContext) _Droid_id(ctx context.Context, field graphql.Collect return ec.marshalNID2string(ctx, field.Selections, res) } -func (ec *executionContext) _Droid_name(ctx context.Context, field graphql.CollectedField, obj *Droid) graphql.Marshaler { +func (ec *executionContext) _Droid_name(ctx context.Context, field graphql.CollectedField, obj *models.Droid) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ @@ -997,7 +998,7 @@ func (ec *executionContext) _Droid_name(ctx context.Context, field graphql.Colle return ec.marshalNString2string(ctx, field.Selections, res) } -func (ec *executionContext) _Droid_friends(ctx context.Context, field graphql.CollectedField, obj *Droid) graphql.Marshaler { +func (ec *executionContext) _Droid_friends(ctx context.Context, field graphql.CollectedField, obj *models.Droid) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ @@ -1014,13 +1015,13 @@ func (ec *executionContext) _Droid_friends(ctx context.Context, field graphql.Co if resTmp == nil { return graphql.Null } - res := resTmp.([]Character) + res := resTmp.([]models.Character) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return ec.marshalOCharacter2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚐCharacter(ctx, field.Selections, res) + return ec.marshalOCharacter2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚋmodelsᚐCharacter(ctx, field.Selections, res) } -func (ec *executionContext) _Droid_friendsConnection(ctx context.Context, field graphql.CollectedField, obj *Droid) graphql.Marshaler { +func (ec *executionContext) _Droid_friendsConnection(ctx context.Context, field graphql.CollectedField, obj *models.Droid) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ @@ -1047,13 +1048,13 @@ func (ec *executionContext) _Droid_friendsConnection(ctx context.Context, field } return graphql.Null } - res := resTmp.(*FriendsConnection) + res := resTmp.(*models.FriendsConnection) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return ec.marshalNFriendsConnection2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚐFriendsConnection(ctx, field.Selections, res) + return ec.marshalNFriendsConnection2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚋmodelsᚐFriendsConnection(ctx, field.Selections, res) } -func (ec *executionContext) _Droid_appearsIn(ctx context.Context, field graphql.CollectedField, obj *Droid) graphql.Marshaler { +func (ec *executionContext) _Droid_appearsIn(ctx context.Context, field graphql.CollectedField, obj *models.Droid) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ @@ -1073,13 +1074,13 @@ func (ec *executionContext) _Droid_appearsIn(ctx context.Context, field graphql. } return graphql.Null } - res := resTmp.([]Episode) + res := resTmp.([]models.Episode) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return ec.marshalNEpisode2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚐEpisode(ctx, field.Selections, res) + return ec.marshalNEpisode2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚋmodelsᚐEpisode(ctx, field.Selections, res) } -func (ec *executionContext) _Droid_primaryFunction(ctx context.Context, field graphql.CollectedField, obj *Droid) graphql.Marshaler { +func (ec *executionContext) _Droid_primaryFunction(ctx context.Context, field graphql.CollectedField, obj *models.Droid) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ @@ -1102,7 +1103,7 @@ func (ec *executionContext) _Droid_primaryFunction(ctx context.Context, field gr return ec.marshalOString2string(ctx, field.Selections, res) } -func (ec *executionContext) _FriendsConnection_totalCount(ctx context.Context, field graphql.CollectedField, obj *FriendsConnection) graphql.Marshaler { +func (ec *executionContext) _FriendsConnection_totalCount(ctx context.Context, field graphql.CollectedField, obj *models.FriendsConnection) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ @@ -1128,7 +1129,7 @@ func (ec *executionContext) _FriendsConnection_totalCount(ctx context.Context, f return ec.marshalNInt2int(ctx, field.Selections, res) } -func (ec *executionContext) _FriendsConnection_edges(ctx context.Context, field graphql.CollectedField, obj *FriendsConnection) graphql.Marshaler { +func (ec *executionContext) _FriendsConnection_edges(ctx context.Context, field graphql.CollectedField, obj *models.FriendsConnection) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ @@ -1145,13 +1146,13 @@ func (ec *executionContext) _FriendsConnection_edges(ctx context.Context, field if resTmp == nil { return graphql.Null } - res := resTmp.([]FriendsEdge) + res := resTmp.([]models.FriendsEdge) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return ec.marshalOFriendsEdge2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚐFriendsEdge(ctx, field.Selections, res) + return ec.marshalOFriendsEdge2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚋmodelsᚐFriendsEdge(ctx, field.Selections, res) } -func (ec *executionContext) _FriendsConnection_friends(ctx context.Context, field graphql.CollectedField, obj *FriendsConnection) graphql.Marshaler { +func (ec *executionContext) _FriendsConnection_friends(ctx context.Context, field graphql.CollectedField, obj *models.FriendsConnection) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ @@ -1168,13 +1169,13 @@ func (ec *executionContext) _FriendsConnection_friends(ctx context.Context, fiel if resTmp == nil { return graphql.Null } - res := resTmp.([]Character) + res := resTmp.([]models.Character) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return ec.marshalOCharacter2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚐCharacter(ctx, field.Selections, res) + return ec.marshalOCharacter2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚋmodelsᚐCharacter(ctx, field.Selections, res) } -func (ec *executionContext) _FriendsConnection_pageInfo(ctx context.Context, field graphql.CollectedField, obj *FriendsConnection) graphql.Marshaler { +func (ec *executionContext) _FriendsConnection_pageInfo(ctx context.Context, field graphql.CollectedField, obj *models.FriendsConnection) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ @@ -1194,13 +1195,13 @@ func (ec *executionContext) _FriendsConnection_pageInfo(ctx context.Context, fie } return graphql.Null } - res := resTmp.(PageInfo) + res := resTmp.(models.PageInfo) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return ec.marshalNPageInfo2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚐPageInfo(ctx, field.Selections, res) + return ec.marshalNPageInfo2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚋmodelsᚐPageInfo(ctx, field.Selections, res) } -func (ec *executionContext) _FriendsEdge_cursor(ctx context.Context, field graphql.CollectedField, obj *FriendsEdge) graphql.Marshaler { +func (ec *executionContext) _FriendsEdge_cursor(ctx context.Context, field graphql.CollectedField, obj *models.FriendsEdge) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ @@ -1226,7 +1227,7 @@ func (ec *executionContext) _FriendsEdge_cursor(ctx context.Context, field graph return ec.marshalNID2string(ctx, field.Selections, res) } -func (ec *executionContext) _FriendsEdge_node(ctx context.Context, field graphql.CollectedField, obj *FriendsEdge) graphql.Marshaler { +func (ec *executionContext) _FriendsEdge_node(ctx context.Context, field graphql.CollectedField, obj *models.FriendsEdge) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ @@ -1243,13 +1244,13 @@ func (ec *executionContext) _FriendsEdge_node(ctx context.Context, field graphql if resTmp == nil { return graphql.Null } - res := resTmp.(Character) + res := resTmp.(models.Character) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return ec.marshalOCharacter2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚐCharacter(ctx, field.Selections, res) + return ec.marshalOCharacter2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚋmodelsᚐCharacter(ctx, field.Selections, res) } -func (ec *executionContext) _Human_id(ctx context.Context, field graphql.CollectedField, obj *Human) graphql.Marshaler { +func (ec *executionContext) _Human_id(ctx context.Context, field graphql.CollectedField, obj *models.Human) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ @@ -1275,7 +1276,7 @@ func (ec *executionContext) _Human_id(ctx context.Context, field graphql.Collect return ec.marshalNID2string(ctx, field.Selections, res) } -func (ec *executionContext) _Human_name(ctx context.Context, field graphql.CollectedField, obj *Human) graphql.Marshaler { +func (ec *executionContext) _Human_name(ctx context.Context, field graphql.CollectedField, obj *models.Human) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ @@ -1301,7 +1302,7 @@ func (ec *executionContext) _Human_name(ctx context.Context, field graphql.Colle return ec.marshalNString2string(ctx, field.Selections, res) } -func (ec *executionContext) _Human_height(ctx context.Context, field graphql.CollectedField, obj *Human) graphql.Marshaler { +func (ec *executionContext) _Human_height(ctx context.Context, field graphql.CollectedField, obj *models.Human) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ @@ -1320,7 +1321,7 @@ func (ec *executionContext) _Human_height(ctx context.Context, field graphql.Col ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return obj.Height(args["unit"].(LengthUnit)), nil + return obj.Height(args["unit"].(models.LengthUnit)), nil }) if resTmp == nil { if !ec.HasError(rctx) { @@ -1334,7 +1335,7 @@ func (ec *executionContext) _Human_height(ctx context.Context, field graphql.Col return ec.marshalNFloat2float64(ctx, field.Selections, res) } -func (ec *executionContext) _Human_mass(ctx context.Context, field graphql.CollectedField, obj *Human) graphql.Marshaler { +func (ec *executionContext) _Human_mass(ctx context.Context, field graphql.CollectedField, obj *models.Human) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ @@ -1357,7 +1358,7 @@ func (ec *executionContext) _Human_mass(ctx context.Context, field graphql.Colle return ec.marshalOFloat2float64(ctx, field.Selections, res) } -func (ec *executionContext) _Human_friends(ctx context.Context, field graphql.CollectedField, obj *Human) graphql.Marshaler { +func (ec *executionContext) _Human_friends(ctx context.Context, field graphql.CollectedField, obj *models.Human) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ @@ -1374,13 +1375,13 @@ func (ec *executionContext) _Human_friends(ctx context.Context, field graphql.Co if resTmp == nil { return graphql.Null } - res := resTmp.([]Character) + res := resTmp.([]models.Character) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return ec.marshalOCharacter2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚐCharacter(ctx, field.Selections, res) + return ec.marshalOCharacter2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚋmodelsᚐCharacter(ctx, field.Selections, res) } -func (ec *executionContext) _Human_friendsConnection(ctx context.Context, field graphql.CollectedField, obj *Human) graphql.Marshaler { +func (ec *executionContext) _Human_friendsConnection(ctx context.Context, field graphql.CollectedField, obj *models.Human) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ @@ -1407,13 +1408,13 @@ func (ec *executionContext) _Human_friendsConnection(ctx context.Context, field } return graphql.Null } - res := resTmp.(*FriendsConnection) + res := resTmp.(*models.FriendsConnection) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return ec.marshalNFriendsConnection2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚐFriendsConnection(ctx, field.Selections, res) + return ec.marshalNFriendsConnection2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚋmodelsᚐFriendsConnection(ctx, field.Selections, res) } -func (ec *executionContext) _Human_appearsIn(ctx context.Context, field graphql.CollectedField, obj *Human) graphql.Marshaler { +func (ec *executionContext) _Human_appearsIn(ctx context.Context, field graphql.CollectedField, obj *models.Human) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ @@ -1433,13 +1434,13 @@ func (ec *executionContext) _Human_appearsIn(ctx context.Context, field graphql. } return graphql.Null } - res := resTmp.([]Episode) + res := resTmp.([]models.Episode) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return ec.marshalNEpisode2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚐEpisode(ctx, field.Selections, res) + return ec.marshalNEpisode2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚋmodelsᚐEpisode(ctx, field.Selections, res) } -func (ec *executionContext) _Human_starships(ctx context.Context, field graphql.CollectedField, obj *Human) graphql.Marshaler { +func (ec *executionContext) _Human_starships(ctx context.Context, field graphql.CollectedField, obj *models.Human) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ @@ -1456,10 +1457,10 @@ func (ec *executionContext) _Human_starships(ctx context.Context, field graphql. if resTmp == nil { return graphql.Null } - res := resTmp.([]Starship) + res := resTmp.([]models.Starship) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return ec.marshalOStarship2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚐStarship(ctx, field.Selections, res) + return ec.marshalOStarship2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚋmodelsᚐStarship(ctx, field.Selections, res) } func (ec *executionContext) _Mutation_createReview(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { @@ -1481,18 +1482,18 @@ func (ec *executionContext) _Mutation_createReview(ctx context.Context, field gr ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) resTmp := ec.FieldMiddleware(ctx, nil, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return ec.resolvers.Mutation().CreateReview(rctx, args["episode"].(Episode), args["review"].(Review)) + return ec.resolvers.Mutation().CreateReview(rctx, args["episode"].(models.Episode), args["review"].(models.Review)) }) if resTmp == nil { return graphql.Null } - res := resTmp.(*Review) + res := resTmp.(*models.Review) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return ec.marshalOReview2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚐReview(ctx, field.Selections, res) + return ec.marshalOReview2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚋmodelsᚐReview(ctx, field.Selections, res) } -func (ec *executionContext) _PageInfo_startCursor(ctx context.Context, field graphql.CollectedField, obj *PageInfo) graphql.Marshaler { +func (ec *executionContext) _PageInfo_startCursor(ctx context.Context, field graphql.CollectedField, obj *models.PageInfo) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ @@ -1518,7 +1519,7 @@ func (ec *executionContext) _PageInfo_startCursor(ctx context.Context, field gra return ec.marshalNID2string(ctx, field.Selections, res) } -func (ec *executionContext) _PageInfo_endCursor(ctx context.Context, field graphql.CollectedField, obj *PageInfo) graphql.Marshaler { +func (ec *executionContext) _PageInfo_endCursor(ctx context.Context, field graphql.CollectedField, obj *models.PageInfo) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ @@ -1544,7 +1545,7 @@ func (ec *executionContext) _PageInfo_endCursor(ctx context.Context, field graph return ec.marshalNID2string(ctx, field.Selections, res) } -func (ec *executionContext) _PageInfo_hasNextPage(ctx context.Context, field graphql.CollectedField, obj *PageInfo) graphql.Marshaler { +func (ec *executionContext) _PageInfo_hasNextPage(ctx context.Context, field graphql.CollectedField, obj *models.PageInfo) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ @@ -1589,15 +1590,15 @@ func (ec *executionContext) _Query_hero(ctx context.Context, field graphql.Colle ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) resTmp := ec.FieldMiddleware(ctx, nil, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return ec.resolvers.Query().Hero(rctx, args["episode"].(*Episode)) + return ec.resolvers.Query().Hero(rctx, args["episode"].(*models.Episode)) }) if resTmp == nil { return graphql.Null } - res := resTmp.(Character) + res := resTmp.(models.Character) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return ec.marshalOCharacter2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚐCharacter(ctx, field.Selections, res) + return ec.marshalOCharacter2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚋmodelsᚐCharacter(ctx, field.Selections, res) } func (ec *executionContext) _Query_reviews(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { @@ -1619,7 +1620,7 @@ func (ec *executionContext) _Query_reviews(ctx context.Context, field graphql.Co ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) resTmp := ec.FieldMiddleware(ctx, nil, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return ec.resolvers.Query().Reviews(rctx, args["episode"].(Episode), args["since"].(*time.Time)) + return ec.resolvers.Query().Reviews(rctx, args["episode"].(models.Episode), args["since"].(*time.Time)) }) if resTmp == nil { if !ec.HasError(rctx) { @@ -1627,10 +1628,10 @@ func (ec *executionContext) _Query_reviews(ctx context.Context, field graphql.Co } return graphql.Null } - res := resTmp.([]Review) + res := resTmp.([]models.Review) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return ec.marshalNReview2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚐReview(ctx, field.Selections, res) + return ec.marshalNReview2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚋmodelsᚐReview(ctx, field.Selections, res) } func (ec *executionContext) _Query_search(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { @@ -1660,10 +1661,10 @@ func (ec *executionContext) _Query_search(ctx context.Context, field graphql.Col } return graphql.Null } - res := resTmp.([]SearchResult) + res := resTmp.([]models.SearchResult) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return ec.marshalNSearchResult2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚐSearchResult(ctx, field.Selections, res) + return ec.marshalNSearchResult2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚋmodelsᚐSearchResult(ctx, field.Selections, res) } func (ec *executionContext) _Query_character(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { @@ -1690,10 +1691,10 @@ func (ec *executionContext) _Query_character(ctx context.Context, field graphql. if resTmp == nil { return graphql.Null } - res := resTmp.(Character) + res := resTmp.(models.Character) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return ec.marshalOCharacter2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚐCharacter(ctx, field.Selections, res) + return ec.marshalOCharacter2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚋmodelsᚐCharacter(ctx, field.Selections, res) } func (ec *executionContext) _Query_droid(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { @@ -1720,10 +1721,10 @@ func (ec *executionContext) _Query_droid(ctx context.Context, field graphql.Coll if resTmp == nil { return graphql.Null } - res := resTmp.(*Droid) + res := resTmp.(*models.Droid) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return ec.marshalODroid2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚐDroid(ctx, field.Selections, res) + return ec.marshalODroid2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚋmodelsᚐDroid(ctx, field.Selections, res) } func (ec *executionContext) _Query_human(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { @@ -1750,10 +1751,10 @@ func (ec *executionContext) _Query_human(ctx context.Context, field graphql.Coll if resTmp == nil { return graphql.Null } - res := resTmp.(*Human) + res := resTmp.(*models.Human) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return ec.marshalOHuman2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚐHuman(ctx, field.Selections, res) + return ec.marshalOHuman2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚋmodelsᚐHuman(ctx, field.Selections, res) } func (ec *executionContext) _Query_starship(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { @@ -1780,10 +1781,10 @@ func (ec *executionContext) _Query_starship(ctx context.Context, field graphql.C if resTmp == nil { return graphql.Null } - res := resTmp.(*Starship) + res := resTmp.(*models.Starship) rctx.Result = res ctx = ec.Tracer.StartFieldChildExecution(ctx) - return ec.marshalOStarship2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚐStarship(ctx, field.Selections, res) + return ec.marshalOStarship2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚋmodelsᚐStarship(ctx, field.Selections, res) } func (ec *executionContext) _Query___type(ctx context.Context, field graphql.CollectedField) graphql.Marshaler { @@ -1839,7 +1840,7 @@ func (ec *executionContext) _Query___schema(ctx context.Context, field graphql.C return ec.marshalO__Schema2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐSchema(ctx, field.Selections, res) } -func (ec *executionContext) _Review_stars(ctx context.Context, field graphql.CollectedField, obj *Review) graphql.Marshaler { +func (ec *executionContext) _Review_stars(ctx context.Context, field graphql.CollectedField, obj *models.Review) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ @@ -1865,7 +1866,7 @@ func (ec *executionContext) _Review_stars(ctx context.Context, field graphql.Col return ec.marshalNInt2int(ctx, field.Selections, res) } -func (ec *executionContext) _Review_commentary(ctx context.Context, field graphql.CollectedField, obj *Review) graphql.Marshaler { +func (ec *executionContext) _Review_commentary(ctx context.Context, field graphql.CollectedField, obj *models.Review) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ @@ -1888,7 +1889,7 @@ func (ec *executionContext) _Review_commentary(ctx context.Context, field graphq return ec.marshalOString2ᚖstring(ctx, field.Selections, res) } -func (ec *executionContext) _Review_time(ctx context.Context, field graphql.CollectedField, obj *Review) graphql.Marshaler { +func (ec *executionContext) _Review_time(ctx context.Context, field graphql.CollectedField, obj *models.Review) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ @@ -1911,7 +1912,7 @@ func (ec *executionContext) _Review_time(ctx context.Context, field graphql.Coll return ec.marshalOTime2timeᚐTime(ctx, field.Selections, res) } -func (ec *executionContext) _Starship_id(ctx context.Context, field graphql.CollectedField, obj *Starship) graphql.Marshaler { +func (ec *executionContext) _Starship_id(ctx context.Context, field graphql.CollectedField, obj *models.Starship) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ @@ -1937,7 +1938,7 @@ func (ec *executionContext) _Starship_id(ctx context.Context, field graphql.Coll return ec.marshalNID2string(ctx, field.Selections, res) } -func (ec *executionContext) _Starship_name(ctx context.Context, field graphql.CollectedField, obj *Starship) graphql.Marshaler { +func (ec *executionContext) _Starship_name(ctx context.Context, field graphql.CollectedField, obj *models.Starship) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ @@ -1963,7 +1964,7 @@ func (ec *executionContext) _Starship_name(ctx context.Context, field graphql.Co return ec.marshalNString2string(ctx, field.Selections, res) } -func (ec *executionContext) _Starship_length(ctx context.Context, field graphql.CollectedField, obj *Starship) graphql.Marshaler { +func (ec *executionContext) _Starship_length(ctx context.Context, field graphql.CollectedField, obj *models.Starship) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ @@ -1982,7 +1983,7 @@ func (ec *executionContext) _Starship_length(ctx context.Context, field graphql. ctx = ec.Tracer.StartFieldResolverExecution(ctx, rctx) resTmp := ec.FieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return ec.resolvers.Starship().Length(rctx, obj, args["unit"].(*LengthUnit)) + return ec.resolvers.Starship().Length(rctx, obj, args["unit"].(*models.LengthUnit)) }) if resTmp == nil { if !ec.HasError(rctx) { @@ -1996,7 +1997,7 @@ func (ec *executionContext) _Starship_length(ctx context.Context, field graphql. return ec.marshalNFloat2float64(ctx, field.Selections, res) } -func (ec *executionContext) _Starship_history(ctx context.Context, field graphql.CollectedField, obj *Starship) graphql.Marshaler { +func (ec *executionContext) _Starship_history(ctx context.Context, field graphql.CollectedField, obj *models.Starship) graphql.Marshaler { ctx = ec.Tracer.StartFieldExecution(ctx, field) defer func() { ec.Tracer.EndFieldExecution(ctx) }() rctx := &graphql.ResolverContext{ @@ -2821,8 +2822,8 @@ func (ec *executionContext) ___Type_ofType(ctx context.Context, field graphql.Co // region **************************** input.gotpl ***************************** -func (ec *executionContext) unmarshalInputReviewInput(ctx context.Context, v interface{}) (Review, error) { - var it Review +func (ec *executionContext) unmarshalInputReviewInput(ctx context.Context, v interface{}) (models.Review, error) { + var it models.Review var asMap = v.(map[string]interface{}) for k, v := range asMap { @@ -2855,38 +2856,38 @@ func (ec *executionContext) unmarshalInputReviewInput(ctx context.Context, v int // region ************************** interface.gotpl *************************** -func (ec *executionContext) _Character(ctx context.Context, sel ast.SelectionSet, obj *Character) graphql.Marshaler { +func (ec *executionContext) _Character(ctx context.Context, sel ast.SelectionSet, obj *models.Character) graphql.Marshaler { switch obj := (*obj).(type) { case nil: return graphql.Null - case Human: + case models.Human: return ec._Human(ctx, sel, &obj) - case *Human: + case *models.Human: return ec._Human(ctx, sel, obj) - case Droid: + case models.Droid: return ec._Droid(ctx, sel, &obj) - case *Droid: + case *models.Droid: return ec._Droid(ctx, sel, obj) default: panic(fmt.Errorf("unexpected type %T", obj)) } } -func (ec *executionContext) _SearchResult(ctx context.Context, sel ast.SelectionSet, obj *SearchResult) graphql.Marshaler { +func (ec *executionContext) _SearchResult(ctx context.Context, sel ast.SelectionSet, obj *models.SearchResult) graphql.Marshaler { switch obj := (*obj).(type) { case nil: return graphql.Null - case Human: + case models.Human: return ec._Human(ctx, sel, &obj) - case *Human: + case *models.Human: return ec._Human(ctx, sel, obj) - case Droid: + case models.Droid: return ec._Droid(ctx, sel, &obj) - case *Droid: + case *models.Droid: return ec._Droid(ctx, sel, obj) - case Starship: + case models.Starship: return ec._Starship(ctx, sel, &obj) - case *Starship: + case *models.Starship: return ec._Starship(ctx, sel, obj) default: panic(fmt.Errorf("unexpected type %T", obj)) @@ -2899,7 +2900,7 @@ func (ec *executionContext) _SearchResult(ctx context.Context, sel ast.Selection var droidImplementors = []string{"Droid", "Character", "SearchResult"} -func (ec *executionContext) _Droid(ctx context.Context, sel ast.SelectionSet, obj *Droid) graphql.Marshaler { +func (ec *executionContext) _Droid(ctx context.Context, sel ast.SelectionSet, obj *models.Droid) graphql.Marshaler { fields := graphql.CollectFields(ctx, sel, droidImplementors) out := graphql.NewFieldSet(fields) @@ -2963,7 +2964,7 @@ func (ec *executionContext) _Droid(ctx context.Context, sel ast.SelectionSet, ob var friendsConnectionImplementors = []string{"FriendsConnection"} -func (ec *executionContext) _FriendsConnection(ctx context.Context, sel ast.SelectionSet, obj *FriendsConnection) graphql.Marshaler { +func (ec *executionContext) _FriendsConnection(ctx context.Context, sel ast.SelectionSet, obj *models.FriendsConnection) graphql.Marshaler { fields := graphql.CollectFields(ctx, sel, friendsConnectionImplementors) out := graphql.NewFieldSet(fields) @@ -3017,7 +3018,7 @@ func (ec *executionContext) _FriendsConnection(ctx context.Context, sel ast.Sele var friendsEdgeImplementors = []string{"FriendsEdge"} -func (ec *executionContext) _FriendsEdge(ctx context.Context, sel ast.SelectionSet, obj *FriendsEdge) graphql.Marshaler { +func (ec *executionContext) _FriendsEdge(ctx context.Context, sel ast.SelectionSet, obj *models.FriendsEdge) graphql.Marshaler { fields := graphql.CollectFields(ctx, sel, friendsEdgeImplementors) out := graphql.NewFieldSet(fields) @@ -3046,7 +3047,7 @@ func (ec *executionContext) _FriendsEdge(ctx context.Context, sel ast.SelectionS var humanImplementors = []string{"Human", "Character", "SearchResult"} -func (ec *executionContext) _Human(ctx context.Context, sel ast.SelectionSet, obj *Human) graphql.Marshaler { +func (ec *executionContext) _Human(ctx context.Context, sel ast.SelectionSet, obj *models.Human) graphql.Marshaler { fields := graphql.CollectFields(ctx, sel, humanImplementors) out := graphql.NewFieldSet(fields) @@ -3154,7 +3155,7 @@ func (ec *executionContext) _Mutation(ctx context.Context, sel ast.SelectionSet) var pageInfoImplementors = []string{"PageInfo"} -func (ec *executionContext) _PageInfo(ctx context.Context, sel ast.SelectionSet, obj *PageInfo) graphql.Marshaler { +func (ec *executionContext) _PageInfo(ctx context.Context, sel ast.SelectionSet, obj *models.PageInfo) graphql.Marshaler { fields := graphql.CollectFields(ctx, sel, pageInfoImplementors) out := graphql.NewFieldSet(fields) @@ -3304,7 +3305,7 @@ func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) gr var reviewImplementors = []string{"Review"} -func (ec *executionContext) _Review(ctx context.Context, sel ast.SelectionSet, obj *Review) graphql.Marshaler { +func (ec *executionContext) _Review(ctx context.Context, sel ast.SelectionSet, obj *models.Review) graphql.Marshaler { fields := graphql.CollectFields(ctx, sel, reviewImplementors) out := graphql.NewFieldSet(fields) @@ -3335,7 +3336,7 @@ func (ec *executionContext) _Review(ctx context.Context, sel ast.SelectionSet, o var starshipImplementors = []string{"Starship", "SearchResult"} -func (ec *executionContext) _Starship(ctx context.Context, sel ast.SelectionSet, obj *Starship) graphql.Marshaler { +func (ec *executionContext) _Starship(ctx context.Context, sel ast.SelectionSet, obj *models.Starship) graphql.Marshaler { fields := graphql.CollectFields(ctx, sel, starshipImplementors) out := graphql.NewFieldSet(fields) @@ -3637,20 +3638,20 @@ func (ec *executionContext) marshalNBoolean2bool(ctx context.Context, sel ast.Se return graphql.MarshalBoolean(v) } -func (ec *executionContext) marshalNCharacter2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚐCharacter(ctx context.Context, sel ast.SelectionSet, v Character) graphql.Marshaler { +func (ec *executionContext) marshalNCharacter2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚋmodelsᚐCharacter(ctx context.Context, sel ast.SelectionSet, v models.Character) graphql.Marshaler { return ec._Character(ctx, sel, &v) } -func (ec *executionContext) unmarshalNEpisode2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚐEpisode(ctx context.Context, v interface{}) (Episode, error) { - var res Episode +func (ec *executionContext) unmarshalNEpisode2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚋmodelsᚐEpisode(ctx context.Context, v interface{}) (models.Episode, error) { + var res models.Episode return res, res.UnmarshalGQL(v) } -func (ec *executionContext) marshalNEpisode2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚐEpisode(ctx context.Context, sel ast.SelectionSet, v Episode) graphql.Marshaler { +func (ec *executionContext) marshalNEpisode2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚋmodelsᚐEpisode(ctx context.Context, sel ast.SelectionSet, v models.Episode) graphql.Marshaler { return v } -func (ec *executionContext) unmarshalNEpisode2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚐEpisode(ctx context.Context, v interface{}) ([]Episode, error) { +func (ec *executionContext) unmarshalNEpisode2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚋmodelsᚐEpisode(ctx context.Context, v interface{}) ([]models.Episode, error) { var vSlice []interface{} if v != nil { if tmp1, ok := v.([]interface{}); ok { @@ -3660,9 +3661,9 @@ func (ec *executionContext) unmarshalNEpisode2ᚕgithubᚗcomᚋ99designsᚋgqlg } } var err error - res := make([]Episode, len(vSlice)) + res := make([]models.Episode, len(vSlice)) for i := range vSlice { - res[i], err = ec.unmarshalNEpisode2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚐEpisode(ctx, vSlice[i]) + res[i], err = ec.unmarshalNEpisode2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚋmodelsᚐEpisode(ctx, vSlice[i]) if err != nil { return nil, err } @@ -3670,7 +3671,7 @@ func (ec *executionContext) unmarshalNEpisode2ᚕgithubᚗcomᚋ99designsᚋgqlg return res, nil } -func (ec *executionContext) marshalNEpisode2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚐEpisode(ctx context.Context, sel ast.SelectionSet, v []Episode) graphql.Marshaler { +func (ec *executionContext) marshalNEpisode2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚋmodelsᚐEpisode(ctx context.Context, sel ast.SelectionSet, v []models.Episode) graphql.Marshaler { ret := make(graphql.Array, len(v)) var wg sync.WaitGroup isLen1 := len(v) == 1 @@ -3694,7 +3695,7 @@ func (ec *executionContext) marshalNEpisode2ᚕgithubᚗcomᚋ99designsᚋgqlgen if !isLen1 { defer wg.Done() } - ret[i] = ec.marshalNEpisode2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚐEpisode(ctx, sel, v[i]) + ret[i] = ec.marshalNEpisode2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚋmodelsᚐEpisode(ctx, sel, v[i]) } if isLen1 { f(i) @@ -3715,11 +3716,11 @@ func (ec *executionContext) marshalNFloat2float64(ctx context.Context, sel ast.S return graphql.MarshalFloat(v) } -func (ec *executionContext) marshalNFriendsConnection2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚐFriendsConnection(ctx context.Context, sel ast.SelectionSet, v FriendsConnection) graphql.Marshaler { +func (ec *executionContext) marshalNFriendsConnection2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚋmodelsᚐFriendsConnection(ctx context.Context, sel ast.SelectionSet, v models.FriendsConnection) graphql.Marshaler { return ec._FriendsConnection(ctx, sel, &v) } -func (ec *executionContext) marshalNFriendsConnection2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚐFriendsConnection(ctx context.Context, sel ast.SelectionSet, v *FriendsConnection) graphql.Marshaler { +func (ec *executionContext) marshalNFriendsConnection2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚋmodelsᚐFriendsConnection(ctx context.Context, sel ast.SelectionSet, v *models.FriendsConnection) graphql.Marshaler { if v == nil { if !ec.HasError(graphql.GetResolverContext(ctx)) { ec.Errorf(ctx, "must not be null") @@ -3729,7 +3730,7 @@ func (ec *executionContext) marshalNFriendsConnection2ᚖgithubᚗcomᚋ99design return ec._FriendsConnection(ctx, sel, v) } -func (ec *executionContext) marshalNFriendsEdge2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚐFriendsEdge(ctx context.Context, sel ast.SelectionSet, v FriendsEdge) graphql.Marshaler { +func (ec *executionContext) marshalNFriendsEdge2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚋmodelsᚐFriendsEdge(ctx context.Context, sel ast.SelectionSet, v models.FriendsEdge) graphql.Marshaler { return ec._FriendsEdge(ctx, sel, &v) } @@ -3807,15 +3808,15 @@ func (ec *executionContext) marshalNInt2ᚕᚕint(ctx context.Context, sel ast.S return ret } -func (ec *executionContext) marshalNPageInfo2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚐPageInfo(ctx context.Context, sel ast.SelectionSet, v PageInfo) graphql.Marshaler { +func (ec *executionContext) marshalNPageInfo2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚋmodelsᚐPageInfo(ctx context.Context, sel ast.SelectionSet, v models.PageInfo) graphql.Marshaler { return ec._PageInfo(ctx, sel, &v) } -func (ec *executionContext) marshalNReview2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚐReview(ctx context.Context, sel ast.SelectionSet, v Review) graphql.Marshaler { +func (ec *executionContext) marshalNReview2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚋmodelsᚐReview(ctx context.Context, sel ast.SelectionSet, v models.Review) graphql.Marshaler { return ec._Review(ctx, sel, &v) } -func (ec *executionContext) marshalNReview2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚐReview(ctx context.Context, sel ast.SelectionSet, v []Review) graphql.Marshaler { +func (ec *executionContext) marshalNReview2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚋmodelsᚐReview(ctx context.Context, sel ast.SelectionSet, v []models.Review) graphql.Marshaler { ret := make(graphql.Array, len(v)) var wg sync.WaitGroup isLen1 := len(v) == 1 @@ -3839,7 +3840,7 @@ func (ec *executionContext) marshalNReview2ᚕgithubᚗcomᚋ99designsᚋgqlgen if !isLen1 { defer wg.Done() } - ret[i] = ec.marshalNReview2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚐReview(ctx, sel, v[i]) + ret[i] = ec.marshalNReview2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚋmodelsᚐReview(ctx, sel, v[i]) } if isLen1 { f(i) @@ -3852,15 +3853,15 @@ func (ec *executionContext) marshalNReview2ᚕgithubᚗcomᚋ99designsᚋgqlgen return ret } -func (ec *executionContext) unmarshalNReviewInput2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚐReview(ctx context.Context, v interface{}) (Review, error) { +func (ec *executionContext) unmarshalNReviewInput2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚋmodelsᚐReview(ctx context.Context, v interface{}) (models.Review, error) { return ec.unmarshalInputReviewInput(ctx, v) } -func (ec *executionContext) marshalNSearchResult2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚐSearchResult(ctx context.Context, sel ast.SelectionSet, v SearchResult) graphql.Marshaler { +func (ec *executionContext) marshalNSearchResult2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚋmodelsᚐSearchResult(ctx context.Context, sel ast.SelectionSet, v models.SearchResult) graphql.Marshaler { return ec._SearchResult(ctx, sel, &v) } -func (ec *executionContext) marshalNSearchResult2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚐSearchResult(ctx context.Context, sel ast.SelectionSet, v []SearchResult) graphql.Marshaler { +func (ec *executionContext) marshalNSearchResult2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚋmodelsᚐSearchResult(ctx context.Context, sel ast.SelectionSet, v []models.SearchResult) graphql.Marshaler { ret := make(graphql.Array, len(v)) var wg sync.WaitGroup isLen1 := len(v) == 1 @@ -3884,7 +3885,7 @@ func (ec *executionContext) marshalNSearchResult2ᚕgithubᚗcomᚋ99designsᚋg if !isLen1 { defer wg.Done() } - ret[i] = ec.marshalNSearchResult2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚐSearchResult(ctx, sel, v[i]) + ret[i] = ec.marshalNSearchResult2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚋmodelsᚐSearchResult(ctx, sel, v[i]) } if isLen1 { f(i) @@ -3897,7 +3898,7 @@ func (ec *executionContext) marshalNSearchResult2ᚕgithubᚗcomᚋ99designsᚋg return ret } -func (ec *executionContext) marshalNStarship2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚐStarship(ctx context.Context, sel ast.SelectionSet, v Starship) graphql.Marshaler { +func (ec *executionContext) marshalNStarship2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚋmodelsᚐStarship(ctx context.Context, sel ast.SelectionSet, v models.Starship) graphql.Marshaler { return ec._Starship(ctx, sel, &v) } @@ -4146,11 +4147,11 @@ func (ec *executionContext) marshalOBoolean2ᚖbool(ctx context.Context, sel ast return ec.marshalOBoolean2bool(ctx, sel, *v) } -func (ec *executionContext) marshalOCharacter2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚐCharacter(ctx context.Context, sel ast.SelectionSet, v Character) graphql.Marshaler { +func (ec *executionContext) marshalOCharacter2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚋmodelsᚐCharacter(ctx context.Context, sel ast.SelectionSet, v models.Character) graphql.Marshaler { return ec._Character(ctx, sel, &v) } -func (ec *executionContext) marshalOCharacter2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚐCharacter(ctx context.Context, sel ast.SelectionSet, v []Character) graphql.Marshaler { +func (ec *executionContext) marshalOCharacter2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚋmodelsᚐCharacter(ctx context.Context, sel ast.SelectionSet, v []models.Character) graphql.Marshaler { ret := make(graphql.Array, len(v)) var wg sync.WaitGroup isLen1 := len(v) == 1 @@ -4174,7 +4175,7 @@ func (ec *executionContext) marshalOCharacter2ᚕgithubᚗcomᚋ99designsᚋgqlg if !isLen1 { defer wg.Done() } - ret[i] = ec.marshalNCharacter2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚐCharacter(ctx, sel, v[i]) + ret[i] = ec.marshalNCharacter2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚋmodelsᚐCharacter(ctx, sel, v[i]) } if isLen1 { f(i) @@ -4187,35 +4188,35 @@ func (ec *executionContext) marshalOCharacter2ᚕgithubᚗcomᚋ99designsᚋgqlg return ret } -func (ec *executionContext) marshalODroid2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚐDroid(ctx context.Context, sel ast.SelectionSet, v Droid) graphql.Marshaler { +func (ec *executionContext) marshalODroid2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚋmodelsᚐDroid(ctx context.Context, sel ast.SelectionSet, v models.Droid) graphql.Marshaler { return ec._Droid(ctx, sel, &v) } -func (ec *executionContext) marshalODroid2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚐDroid(ctx context.Context, sel ast.SelectionSet, v *Droid) graphql.Marshaler { +func (ec *executionContext) marshalODroid2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚋmodelsᚐDroid(ctx context.Context, sel ast.SelectionSet, v *models.Droid) graphql.Marshaler { if v == nil { return graphql.Null } return ec._Droid(ctx, sel, v) } -func (ec *executionContext) unmarshalOEpisode2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚐEpisode(ctx context.Context, v interface{}) (Episode, error) { - var res Episode +func (ec *executionContext) unmarshalOEpisode2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚋmodelsᚐEpisode(ctx context.Context, v interface{}) (models.Episode, error) { + var res models.Episode return res, res.UnmarshalGQL(v) } -func (ec *executionContext) marshalOEpisode2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚐEpisode(ctx context.Context, sel ast.SelectionSet, v Episode) graphql.Marshaler { +func (ec *executionContext) marshalOEpisode2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚋmodelsᚐEpisode(ctx context.Context, sel ast.SelectionSet, v models.Episode) graphql.Marshaler { return v } -func (ec *executionContext) unmarshalOEpisode2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚐEpisode(ctx context.Context, v interface{}) (*Episode, error) { +func (ec *executionContext) unmarshalOEpisode2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚋmodelsᚐEpisode(ctx context.Context, v interface{}) (*models.Episode, error) { if v == nil { return nil, nil } - res, err := ec.unmarshalOEpisode2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚐEpisode(ctx, v) + res, err := ec.unmarshalOEpisode2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚋmodelsᚐEpisode(ctx, v) return &res, err } -func (ec *executionContext) marshalOEpisode2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚐEpisode(ctx context.Context, sel ast.SelectionSet, v *Episode) graphql.Marshaler { +func (ec *executionContext) marshalOEpisode2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚋmodelsᚐEpisode(ctx context.Context, sel ast.SelectionSet, v *models.Episode) graphql.Marshaler { if v == nil { return graphql.Null } @@ -4230,7 +4231,7 @@ func (ec *executionContext) marshalOFloat2float64(ctx context.Context, sel ast.S return graphql.MarshalFloat(v) } -func (ec *executionContext) marshalOFriendsEdge2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚐFriendsEdge(ctx context.Context, sel ast.SelectionSet, v []FriendsEdge) graphql.Marshaler { +func (ec *executionContext) marshalOFriendsEdge2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚋmodelsᚐFriendsEdge(ctx context.Context, sel ast.SelectionSet, v []models.FriendsEdge) graphql.Marshaler { ret := make(graphql.Array, len(v)) var wg sync.WaitGroup isLen1 := len(v) == 1 @@ -4254,7 +4255,7 @@ func (ec *executionContext) marshalOFriendsEdge2ᚕgithubᚗcomᚋ99designsᚋgq if !isLen1 { defer wg.Done() } - ret[i] = ec.marshalNFriendsEdge2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚐFriendsEdge(ctx, sel, v[i]) + ret[i] = ec.marshalNFriendsEdge2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚋmodelsᚐFriendsEdge(ctx, sel, v[i]) } if isLen1 { f(i) @@ -4267,11 +4268,11 @@ func (ec *executionContext) marshalOFriendsEdge2ᚕgithubᚗcomᚋ99designsᚋgq return ret } -func (ec *executionContext) marshalOHuman2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚐHuman(ctx context.Context, sel ast.SelectionSet, v Human) graphql.Marshaler { +func (ec *executionContext) marshalOHuman2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚋmodelsᚐHuman(ctx context.Context, sel ast.SelectionSet, v models.Human) graphql.Marshaler { return ec._Human(ctx, sel, &v) } -func (ec *executionContext) marshalOHuman2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚐHuman(ctx context.Context, sel ast.SelectionSet, v *Human) graphql.Marshaler { +func (ec *executionContext) marshalOHuman2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚋmodelsᚐHuman(ctx context.Context, sel ast.SelectionSet, v *models.Human) graphql.Marshaler { if v == nil { return graphql.Null } @@ -4324,46 +4325,46 @@ func (ec *executionContext) marshalOInt2ᚖint(ctx context.Context, sel ast.Sele return ec.marshalOInt2int(ctx, sel, *v) } -func (ec *executionContext) unmarshalOLengthUnit2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚐLengthUnit(ctx context.Context, v interface{}) (LengthUnit, error) { - var res LengthUnit +func (ec *executionContext) unmarshalOLengthUnit2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚋmodelsᚐLengthUnit(ctx context.Context, v interface{}) (models.LengthUnit, error) { + var res models.LengthUnit return res, res.UnmarshalGQL(v) } -func (ec *executionContext) marshalOLengthUnit2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚐLengthUnit(ctx context.Context, sel ast.SelectionSet, v LengthUnit) graphql.Marshaler { +func (ec *executionContext) marshalOLengthUnit2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚋmodelsᚐLengthUnit(ctx context.Context, sel ast.SelectionSet, v models.LengthUnit) graphql.Marshaler { return v } -func (ec *executionContext) unmarshalOLengthUnit2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚐLengthUnit(ctx context.Context, v interface{}) (*LengthUnit, error) { +func (ec *executionContext) unmarshalOLengthUnit2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚋmodelsᚐLengthUnit(ctx context.Context, v interface{}) (*models.LengthUnit, error) { if v == nil { return nil, nil } - res, err := ec.unmarshalOLengthUnit2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚐLengthUnit(ctx, v) + res, err := ec.unmarshalOLengthUnit2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚋmodelsᚐLengthUnit(ctx, v) return &res, err } -func (ec *executionContext) marshalOLengthUnit2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚐLengthUnit(ctx context.Context, sel ast.SelectionSet, v *LengthUnit) graphql.Marshaler { +func (ec *executionContext) marshalOLengthUnit2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚋmodelsᚐLengthUnit(ctx context.Context, sel ast.SelectionSet, v *models.LengthUnit) graphql.Marshaler { if v == nil { return graphql.Null } return v } -func (ec *executionContext) marshalOReview2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚐReview(ctx context.Context, sel ast.SelectionSet, v Review) graphql.Marshaler { +func (ec *executionContext) marshalOReview2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚋmodelsᚐReview(ctx context.Context, sel ast.SelectionSet, v models.Review) graphql.Marshaler { return ec._Review(ctx, sel, &v) } -func (ec *executionContext) marshalOReview2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚐReview(ctx context.Context, sel ast.SelectionSet, v *Review) graphql.Marshaler { +func (ec *executionContext) marshalOReview2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚋmodelsᚐReview(ctx context.Context, sel ast.SelectionSet, v *models.Review) graphql.Marshaler { if v == nil { return graphql.Null } return ec._Review(ctx, sel, v) } -func (ec *executionContext) marshalOStarship2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚐStarship(ctx context.Context, sel ast.SelectionSet, v Starship) graphql.Marshaler { +func (ec *executionContext) marshalOStarship2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚋmodelsᚐStarship(ctx context.Context, sel ast.SelectionSet, v models.Starship) graphql.Marshaler { return ec._Starship(ctx, sel, &v) } -func (ec *executionContext) marshalOStarship2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚐStarship(ctx context.Context, sel ast.SelectionSet, v []Starship) graphql.Marshaler { +func (ec *executionContext) marshalOStarship2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚋmodelsᚐStarship(ctx context.Context, sel ast.SelectionSet, v []models.Starship) graphql.Marshaler { ret := make(graphql.Array, len(v)) var wg sync.WaitGroup isLen1 := len(v) == 1 @@ -4387,7 +4388,7 @@ func (ec *executionContext) marshalOStarship2ᚕgithubᚗcomᚋ99designsᚋgqlge if !isLen1 { defer wg.Done() } - ret[i] = ec.marshalNStarship2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚐStarship(ctx, sel, v[i]) + ret[i] = ec.marshalNStarship2githubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚋmodelsᚐStarship(ctx, sel, v[i]) } if isLen1 { f(i) @@ -4400,7 +4401,7 @@ func (ec *executionContext) marshalOStarship2ᚕgithubᚗcomᚋ99designsᚋgqlge return ret } -func (ec *executionContext) marshalOStarship2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚐStarship(ctx context.Context, sel ast.SelectionSet, v *Starship) graphql.Marshaler { +func (ec *executionContext) marshalOStarship2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋexampleᚋstarwarsᚋmodelsᚐStarship(ctx context.Context, sel ast.SelectionSet, v *models.Starship) graphql.Marshaler { if v == nil { return graphql.Null } diff --git a/example/starwars/models_gen.go b/example/starwars/models/generated.go similarity index 99% rename from example/starwars/models_gen.go rename to example/starwars/models/generated.go index e418cd89e42..2f02272c20e 100644 --- a/example/starwars/models_gen.go +++ b/example/starwars/models/generated.go @@ -1,6 +1,6 @@ // Code generated by github.com/99designs/gqlgen, DO NOT EDIT. -package starwars +package models import ( "fmt" diff --git a/example/starwars/model.go b/example/starwars/models/model.go similarity index 50% rename from example/starwars/model.go rename to example/starwars/models/model.go index fd9e274894f..e3225b743ae 100644 --- a/example/starwars/model.go +++ b/example/starwars/models/model.go @@ -1,11 +1,8 @@ -package starwars +package models import ( - "context" "encoding/base64" "fmt" - "strconv" - "strings" "time" ) @@ -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") } @@ -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))) } diff --git a/example/starwars/resolvers.go b/example/starwars/resolvers.go index 1e000584728..7b1f3f4b5f4 100644 --- a/example/starwars/resolvers.go +++ b/example/starwars/resolvers.go @@ -1,47 +1,54 @@ +//go:generate rm -rf generated //go:generate go run ../../testdata/gqlgen.go package starwars import ( "context" + "encoding/base64" "errors" + "strconv" "strings" "time" + + "github.com/99designs/gqlgen/example/starwars/generated" + + "github.com/99designs/gqlgen/example/starwars/models" ) type Resolver struct { - humans map[string]Human - droid map[string]Droid - starships map[string]Starship - reviews map[Episode][]Review + humans map[string]models.Human + droid map[string]models.Droid + starships map[string]models.Starship + reviews map[models.Episode][]models.Review } -func (r *Resolver) Droid() DroidResolver { +func (r *Resolver) Droid() generated.DroidResolver { return &droidResolver{r} } -func (r *Resolver) FriendsConnection() FriendsConnectionResolver { +func (r *Resolver) FriendsConnection() generated.FriendsConnectionResolver { return &friendsConnectionResolver{r} } -func (r *Resolver) Human() HumanResolver { +func (r *Resolver) Human() generated.HumanResolver { return &humanResolver{r} } -func (r *Resolver) Mutation() MutationResolver { +func (r *Resolver) Mutation() generated.MutationResolver { return &mutationResolver{r} } -func (r *Resolver) Query() QueryResolver { +func (r *Resolver) Query() generated.QueryResolver { return &queryResolver{r} } -func (r *Resolver) Starship() StarshipResolver { +func (r *Resolver) Starship() generated.StarshipResolver { return &starshipResolver{r} } -func (r *Resolver) resolveCharacters(ctx context.Context, ids []string) ([]Character, error) { - var result []Character +func (r *Resolver) resolveCharacters(ctx context.Context, ids []string) ([]models.Character, error) { + var result []models.Character for _, id := range ids { char, err := r.Query().Character(ctx, id) if err != nil { @@ -54,48 +61,77 @@ func (r *Resolver) resolveCharacters(ctx context.Context, ids []string) ([]Chara type droidResolver struct{ *Resolver } -func (r *droidResolver) Friends(ctx context.Context, obj *Droid) ([]Character, error) { +func (r *droidResolver) Friends(ctx context.Context, obj *models.Droid) ([]models.Character, error) { return r.resolveCharacters(ctx, obj.FriendIds) } -func (r *droidResolver) FriendsConnection(ctx context.Context, obj *Droid, first *int, after *string) (*FriendsConnection, error) { +func (r *droidResolver) FriendsConnection(ctx context.Context, obj *models.Droid, first *int, after *string) (*models.FriendsConnection, error) { return r.resolveFriendConnection(ctx, obj.FriendIds, first, after) } type friendsConnectionResolver struct{ *Resolver } -func (r *friendsConnectionResolver) Edges(ctx context.Context, obj *FriendsConnection) ([]FriendsEdge, error) { - friends, err := r.resolveCharacters(ctx, obj.ids) +func (r *Resolver) resolveFriendConnection(ctx context.Context, ids []string, first *int, after *string) (*models.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 &models.FriendsConnection{ + Ids: ids, + From: from, + To: to, + }, nil +} + +func (r *friendsConnectionResolver) Edges(ctx context.Context, obj *models.FriendsConnection) ([]models.FriendsEdge, error) { + friends, err := r.resolveCharacters(ctx, obj.Ids) if err != nil { return nil, err } - edges := make([]FriendsEdge, obj.to-obj.from) + edges := make([]models.FriendsEdge, obj.To-obj.From) for i := range edges { - edges[i] = FriendsEdge{ - Cursor: encodeCursor(obj.from + i), - Node: friends[obj.from+i], + edges[i] = models.FriendsEdge{ + Cursor: models.EncodeCursor(obj.From + i), + Node: friends[obj.From+i], } } return edges, nil } -func (r *friendsConnectionResolver) Friends(ctx context.Context, obj *FriendsConnection) ([]Character, error) { - return r.resolveCharacters(ctx, obj.ids) +func (r *friendsConnectionResolver) Friends(ctx context.Context, obj *models.FriendsConnection) ([]models.Character, error) { + return r.resolveCharacters(ctx, obj.Ids) } type humanResolver struct{ *Resolver } -func (r *humanResolver) Friends(ctx context.Context, obj *Human) ([]Character, error) { +func (r *humanResolver) Friends(ctx context.Context, obj *models.Human) ([]models.Character, error) { return r.resolveCharacters(ctx, obj.FriendIds) } -func (r *humanResolver) FriendsConnection(ctx context.Context, obj *Human, first *int, after *string) (*FriendsConnection, error) { +func (r *humanResolver) FriendsConnection(ctx context.Context, obj *models.Human, first *int, after *string) (*models.FriendsConnection, error) { return r.resolveFriendConnection(ctx, obj.FriendIds, first, after) } -func (r *humanResolver) Starships(ctx context.Context, obj *Human) ([]Starship, error) { - var result []Starship +func (r *humanResolver) Starships(ctx context.Context, obj *models.Human) ([]models.Starship, error) { + var result []models.Starship for _, id := range obj.StarshipIds { char, err := r.Query().Starship(ctx, id) if err != nil { @@ -110,7 +146,7 @@ func (r *humanResolver) Starships(ctx context.Context, obj *Human) ([]Starship, type mutationResolver struct{ *Resolver } -func (r *mutationResolver) CreateReview(ctx context.Context, episode Episode, review Review) (*Review, error) { +func (r *mutationResolver) CreateReview(ctx context.Context, episode models.Episode, review models.Review) (*models.Review, error) { review.Time = time.Now() time.Sleep(1 * time.Second) r.reviews[episode] = append(r.reviews[episode], review) @@ -119,19 +155,19 @@ func (r *mutationResolver) CreateReview(ctx context.Context, episode Episode, re type queryResolver struct{ *Resolver } -func (r *queryResolver) Hero(ctx context.Context, episode *Episode) (Character, error) { - if *episode == EpisodeEmpire { +func (r *queryResolver) Hero(ctx context.Context, episode *models.Episode) (models.Character, error) { + if *episode == models.EpisodeEmpire { return r.humans["1000"], nil } return r.droid["2001"], nil } -func (r *queryResolver) Reviews(ctx context.Context, episode Episode, since *time.Time) ([]Review, error) { +func (r *queryResolver) Reviews(ctx context.Context, episode models.Episode, since *time.Time) ([]models.Review, error) { if since == nil { return r.reviews[episode], nil } - var filtered []Review + var filtered []models.Review for _, rev := range r.reviews[episode] { if rev.Time.After(*since) { filtered = append(filtered, rev) @@ -140,8 +176,8 @@ func (r *queryResolver) Reviews(ctx context.Context, episode Episode, since *tim return filtered, nil } -func (r *queryResolver) Search(ctx context.Context, text string) ([]SearchResult, error) { - var l []SearchResult +func (r *queryResolver) Search(ctx context.Context, text string) ([]models.SearchResult, error) { + var l []models.SearchResult for _, h := range r.humans { if strings.Contains(h.Name, text) { l = append(l, h) @@ -160,7 +196,7 @@ func (r *queryResolver) Search(ctx context.Context, text string) ([]SearchResult return l, nil } -func (r *queryResolver) Character(ctx context.Context, id string) (Character, error) { +func (r *queryResolver) Character(ctx context.Context, id string) (models.Character, error) { if h, ok := r.humans[id]; ok { return &h, nil } @@ -170,21 +206,21 @@ func (r *queryResolver) Character(ctx context.Context, id string) (Character, er return nil, nil } -func (r *queryResolver) Droid(ctx context.Context, id string) (*Droid, error) { +func (r *queryResolver) Droid(ctx context.Context, id string) (*models.Droid, error) { if d, ok := r.droid[id]; ok { return &d, nil } return nil, nil } -func (r *queryResolver) Human(ctx context.Context, id string) (*Human, error) { +func (r *queryResolver) Human(ctx context.Context, id string) (*models.Human, error) { if h, ok := r.humans[id]; ok { return &h, nil } return nil, nil } -func (r *queryResolver) Starship(ctx context.Context, id string) (*Starship, error) { +func (r *queryResolver) Starship(ctx context.Context, id string) (*models.Starship, error) { if s, ok := r.starships[id]; ok { return &s, nil } @@ -193,97 +229,97 @@ func (r *queryResolver) Starship(ctx context.Context, id string) (*Starship, err type starshipResolver struct{ *Resolver } -func (r *starshipResolver) Length(ctx context.Context, obj *Starship, unit *LengthUnit) (float64, error) { +func (r *starshipResolver) Length(ctx context.Context, obj *models.Starship, unit *models.LengthUnit) (float64, error) { switch *unit { - case LengthUnitMeter, "": + case models.LengthUnitMeter, "": return obj.Length, nil - case LengthUnitFoot: + case models.LengthUnitFoot: return obj.Length * 3.28084, nil default: return 0, errors.New("invalid unit") } } -func NewResolver() Config { +func NewResolver() generated.Config { r := Resolver{} - r.humans = map[string]Human{ + r.humans = map[string]models.Human{ "1000": { - CharacterFields: CharacterFields{ + CharacterFields: models.CharacterFields{ ID: "1000", Name: "Luke Skywalker", FriendIds: []string{"1002", "1003", "2000", "2001"}, - AppearsIn: []Episode{EpisodeNewhope, EpisodeEmpire, EpisodeJedi}, + AppearsIn: []models.Episode{models.EpisodeNewhope, models.EpisodeEmpire, models.EpisodeJedi}, }, - heightMeters: 1.72, + HeightMeters: 1.72, Mass: 77, StarshipIds: []string{"3001", "3003"}, }, "1001": { - CharacterFields: CharacterFields{ + CharacterFields: models.CharacterFields{ ID: "1001", Name: "Darth Vader", FriendIds: []string{"1004"}, - AppearsIn: []Episode{EpisodeNewhope, EpisodeEmpire, EpisodeJedi}, + AppearsIn: []models.Episode{models.EpisodeNewhope, models.EpisodeEmpire, models.EpisodeJedi}, }, - heightMeters: 2.02, + HeightMeters: 2.02, Mass: 136, StarshipIds: []string{"3002"}, }, "1002": { - CharacterFields: CharacterFields{ + CharacterFields: models.CharacterFields{ ID: "1002", Name: "Han Solo", FriendIds: []string{"1000", "1003", "2001"}, - AppearsIn: []Episode{EpisodeNewhope, EpisodeEmpire, EpisodeJedi}, + AppearsIn: []models.Episode{models.EpisodeNewhope, models.EpisodeEmpire, models.EpisodeJedi}, }, - heightMeters: 1.8, + HeightMeters: 1.8, Mass: 80, StarshipIds: []string{"3000", "3003"}, }, "1003": { - CharacterFields: CharacterFields{ + CharacterFields: models.CharacterFields{ ID: "1003", Name: "Leia Organa", FriendIds: []string{"1000", "1002", "2000", "2001"}, - AppearsIn: []Episode{EpisodeNewhope, EpisodeEmpire, EpisodeJedi}, + AppearsIn: []models.Episode{models.EpisodeNewhope, models.EpisodeEmpire, models.EpisodeJedi}, }, - heightMeters: 1.5, + HeightMeters: 1.5, Mass: 49, }, "1004": { - CharacterFields: CharacterFields{ + CharacterFields: models.CharacterFields{ ID: "1004", Name: "Wilhuff Tarkin", FriendIds: []string{"1001"}, - AppearsIn: []Episode{EpisodeNewhope}, + AppearsIn: []models.Episode{models.EpisodeNewhope}, }, - heightMeters: 1.8, + HeightMeters: 1.8, Mass: 0, }, } - r.droid = map[string]Droid{ + r.droid = map[string]models.Droid{ "2000": { - CharacterFields: CharacterFields{ + CharacterFields: models.CharacterFields{ ID: "2000", Name: "C-3PO", FriendIds: []string{"1000", "1002", "1003", "2001"}, - AppearsIn: []Episode{EpisodeNewhope, EpisodeEmpire, EpisodeJedi}, + AppearsIn: []models.Episode{models.EpisodeNewhope, models.EpisodeEmpire, models.EpisodeJedi}, }, PrimaryFunction: "Protocol", }, "2001": { - CharacterFields: CharacterFields{ + CharacterFields: models.CharacterFields{ ID: "2001", Name: "R2-D2", FriendIds: []string{"1000", "1002", "1003"}, - AppearsIn: []Episode{EpisodeNewhope, EpisodeEmpire, EpisodeJedi}, + AppearsIn: []models.Episode{models.EpisodeNewhope, models.EpisodeEmpire, models.EpisodeJedi}, }, PrimaryFunction: "Astromech", }, } - r.starships = map[string]Starship{ + r.starships = map[string]models.Starship{ "3000": { ID: "3000", Name: "Millennium Falcon", @@ -330,9 +366,9 @@ func NewResolver() Config { }, } - r.reviews = map[Episode][]Review{} + r.reviews = map[models.Episode][]models.Review{} - return Config{ + return generated.Config{ Resolvers: &r, } } diff --git a/example/starwars/server/server.go b/example/starwars/server/server.go index 20d23cfaf0c..d082d3d92e9 100644 --- a/example/starwars/server/server.go +++ b/example/starwars/server/server.go @@ -7,13 +7,14 @@ import ( "net/http" "github.com/99designs/gqlgen/example/starwars" + "github.com/99designs/gqlgen/example/starwars/generated" "github.com/99designs/gqlgen/graphql" "github.com/99designs/gqlgen/handler" ) func main() { http.Handle("/", handler.Playground("Starwars", "/query")) - http.Handle("/query", handler.GraphQL(starwars.NewExecutableSchema(starwars.NewResolver()), + http.Handle("/query", handler.GraphQL(generated.NewExecutableSchema(starwars.NewResolver()), handler.ResolverMiddleware(func(ctx context.Context, next graphql.Resolver) (res interface{}, err error) { rc := graphql.GetResolverContext(ctx) fmt.Println("Entered", rc.Object, rc.Field.Name) diff --git a/example/starwars/starwars_test.go b/example/starwars/starwars_test.go index 8468c82254a..53f33d34f53 100644 --- a/example/starwars/starwars_test.go +++ b/example/starwars/starwars_test.go @@ -5,13 +5,14 @@ import ( "testing" "github.com/99designs/gqlgen/client" + "github.com/99designs/gqlgen/example/starwars/generated" "github.com/99designs/gqlgen/graphql/introspection" "github.com/99designs/gqlgen/handler" "github.com/stretchr/testify/require" ) func TestStarwars(t *testing.T) { - srv := httptest.NewServer(handler.GraphQL(NewExecutableSchema(NewResolver()))) + srv := httptest.NewServer(handler.GraphQL(generated.NewExecutableSchema(NewResolver()))) c := client.New(srv.URL) t.Run("Lukes starships", func(t *testing.T) { diff --git a/internal/code/imports.go b/internal/code/imports.go index ecfe9dbc9f4..2384e87da95 100644 --- a/internal/code/imports.go +++ b/internal/code/imports.go @@ -1,6 +1,7 @@ package code import ( + "errors" "path/filepath" "sync" @@ -14,12 +15,22 @@ func ImportPathForDir(dir string) string { if v, ok := pathForDirCache.Load(dir); ok { return v.(string) } + p, _ := packages.Load(&packages.Config{ Dir: dir, }, ".") + // If the dir dosent exist yet, keep walking up the directory tree trying to find a match if len(p) != 1 { - return "" + parent, err := filepath.Abs(filepath.Join(dir, "..")) + if err != nil { + panic(err) + } + // Walked all the way to the root and didnt find anything :'( + if parent == dir { + return "" + } + return ImportPathForDir(parent) + "/" + filepath.Base(dir) } pathForDirCache.Store(dir, p[0].PkgPath) @@ -30,6 +41,9 @@ func ImportPathForDir(dir string) string { var nameForPackageCache = sync.Map{} func NameForPackage(importPath string) string { + if importPath == "" { + panic(errors.New("import path can not be empty")) + } if v, ok := nameForPackageCache.Load(importPath); ok { return v.(string) } diff --git a/internal/code/imports_test.go b/internal/code/imports_test.go index b1825749259..b1493375ca1 100644 --- a/internal/code/imports_test.go +++ b/internal/code/imports_test.go @@ -20,7 +20,7 @@ func TestImportPathForDir(t *testing.T) { assert.Equal(t, "github.com/99designs/gqlgen/docs", ImportPathForDir(filepath.Join(wd, "..", "..", "docs"))) // directory does not exist - assert.Equal(t, "", ImportPathForDir(filepath.Join(wd, "..", "..", "dos"))) + assert.Equal(t, "github.com/99designs/gqlgen/dos", ImportPathForDir(filepath.Join(wd, "..", "..", "dos"))) } func TestNameForPackage(t *testing.T) { diff --git a/plugin/stubgen/stubs.go b/plugin/stubgen/stubs.go index 44982b79e59..1dc29ee7da0 100644 --- a/plugin/stubgen/stubs.go +++ b/plugin/stubgen/stubs.go @@ -1,8 +1,11 @@ package stubgen import ( + "path/filepath" "syscall" + "github.com/99designs/gqlgen/internal/code" + "github.com/99designs/gqlgen/codegen" "github.com/99designs/gqlgen/codegen/config" "github.com/99designs/gqlgen/codegen/templates" @@ -31,8 +34,11 @@ func (m *Plugin) MutateConfig(cfg *config.Config) error { } func (m *Plugin) GenerateCode(data *codegen.Data) error { + pkgPath := code.ImportPathForDir(filepath.Dir(m.filename)) + pkgName := code.NameForPackage(pkgPath) + return templates.Render(templates.Options{ - PackageName: data.Config.Exec.Package, + PackageName: pkgName, Filename: m.filename, Data: &ResolverBuild{ Data: data,