diff --git a/examples/mutations/graph/fastgql_schema.resolvers.go b/examples/mutations/graph/fastgql_schema.resolvers.go index 29751a6..16881fd 100644 --- a/examples/mutations/graph/fastgql_schema.resolvers.go +++ b/examples/mutations/graph/fastgql_schema.resolvers.go @@ -38,7 +38,7 @@ func (r *mutationResolver) DeletePosts(ctx context.Context, cascade *bool, filte return nil, err } if err := sql.ExecuteQuery(ctx, r.Executor, func(rows pgx.Rows) error { - return pgxscan.ScanAll(&data, rows) + return pgxscan.ScanOne(&data, rows) }, q, args...); err != nil { return nil, err } @@ -53,7 +53,7 @@ func (r *mutationResolver) UpdatePosts(ctx context.Context, input model.UpdatePo return nil, err } if err := sql.ExecuteQuery(ctx, r.Executor, func(rows pgx.Rows) error { - return pgxscan.ScanAll(&data, rows) + return pgxscan.ScanOne(&data, rows) }, q, args...); err != nil { return nil, err } diff --git a/pkg/execution/driver.go b/pkg/execution/driver.go deleted file mode 100644 index b5639a4..0000000 --- a/pkg/execution/driver.go +++ /dev/null @@ -1,19 +0,0 @@ -package execution - -import ( - "context" -) - -// Scanner builds a query based on GraphQL query and scans data into out -type Scanner interface { - Scan(ctx context.Context, out any) error -} - -type Driver interface { - // Scanner is the main function of all drivers, a scanner will read the GraphQL AST from the context.Context - Scanner - // Close gracefully requests the driver to close - Close() error - // Dialect returns the dialect name of the driver. - Dialect() string -} diff --git a/pkg/execution/execution.go b/pkg/execution/execution.go deleted file mode 100644 index 43b848b..0000000 --- a/pkg/execution/execution.go +++ /dev/null @@ -1,36 +0,0 @@ -package execution - -import ( - "context" - "fmt" -) - -type Dialect string - -// Executor execute based on graphql.FieldContext & graphql.OperationContext -// The executor holds all drivers that support execution -type Executor struct { - drivers map[string]Driver -} - -func NewExecutor(drivers map[string]Driver) Executor { - return Executor{ - drivers: drivers, - } -} - -func (e Executor) Get(dialect string) (Driver, error) { - d, ok := e.drivers[dialect] - if !ok { - return nil, fmt.Errorf("missing dialect driver: %s", dialect) - } - return d, nil -} - -func (e Executor) Scan(ctx context.Context, dialect string, model interface{}) error { - d, err := e.Get(dialect) - if err != nil { - return err - } - return d.Scan(ctx, model) -} diff --git a/pkg/execution/execution_test.go b/pkg/execution/execution_test.go index d89b3cf..829b120 100644 --- a/pkg/execution/execution_test.go +++ b/pkg/execution/execution_test.go @@ -28,10 +28,13 @@ const defaultPGConnection = "postgresql://localhost/postgres?user=postgres&passw // NOTE: run init.sql on the postgres so data will be seeded func TestPostgresGraph(t *testing.T) { tt := []struct { - name string - query *graphql.RawParams - want string - statusCode int + name string + query *graphql.RawParams + want string + statusCode int + cleanupQuery *graphql.RawParams + cleanupCode int + cleanupWant string }{ { name: "BaseQuery", @@ -52,6 +55,15 @@ func TestPostgresGraph(t *testing.T) { want: "{\"data\":{\"posts\":[{\"categories\":[{\"name\":\"News\"},{\"name\":\"Technology\"}],\"_categoriesAggregate\":[{\"count\":1}]},{\"categories\":[{\"name\":\"Technology\"},{\"name\":\"Science\"}],\"_categoriesAggregate\":[{\"count\":0}]},{\"categories\":[{\"name\":\"Science\"},{\"name\":\"Sports\"}],\"_categoriesAggregate\":[{\"count\":0}]},{\"categories\":[{\"name\":\"Sports\"},{\"name\":\"Entertainment\"}],\"_categoriesAggregate\":[{\"count\":0}]},{\"categories\":[{\"name\":\"Entertainment\"},{\"name\":\"News\"}],\"_categoriesAggregate\":[{\"count\":1}]}]}}", statusCode: 200, }, + { + name: "InsertPost", + query: &graphql.RawParams{Query: `mutation { createPosts(inputs: [{id: 66, name: "ron", user_id: 1}]) { rows_affected posts { id name user { id name } }}}`}, + want: "{\"data\":{\"createPosts\":{\"rows_affected\":1,\"posts\":[{\"id\":66,\"name\":\"ron\",\"user\":{\"id\":1,\"name\":\"Alice\"}}]}}}", + statusCode: 200, + cleanupQuery: &graphql.RawParams{Query: `mutation { deletePosts(filter: {id: {eq: 66}}) { rows_affected }}`}, + cleanupCode: 200, + cleanupWant: "{\"data\":{\"deletePosts\":{\"rows_affected\":1}}}", + }, } pool, err := pgxpool.New(context.Background(), defaultPGConnection) @@ -69,14 +81,21 @@ func TestPostgresGraph(t *testing.T) { graphServer := handler.NewDefaultServer(executableSchema) for _, tc := range tt { t.Run(tc.name, func(t *testing.T) { - data, err := json.Marshal(tc.query) - require.Nil(t, err) - request := httptest.NewRequest("POST", "/", bytes.NewBuffer(data)) - request.Header.Add("Content-Type", "application/json") - responseRecorder := httptest.NewRecorder() - graphServer.ServeHTTP(responseRecorder, request) - assert.Equal(t, tc.want, responseRecorder.Body.String()) + testQuery(t, graphServer, tc.query, tc.want, tc.statusCode) + if tc.cleanupQuery != nil { + testQuery(t, graphServer, tc.cleanupQuery, tc.cleanupWant, tc.cleanupCode) + } }) } +} +func testQuery(t *testing.T, server *handler.Server, params *graphql.RawParams, want string, wantCode int) { + data, err := json.Marshal(params) + require.Nil(t, err) + request := httptest.NewRequest("POST", "/", bytes.NewBuffer(data)) + request.Header.Add("Content-Type", "application/json") + responseRecorder := httptest.NewRecorder() + server.ServeHTTP(responseRecorder, request) + assert.Equal(t, want, responseRecorder.Body.String()) + assert.Equal(t, wantCode, responseRecorder.Code) } diff --git a/pkg/execution/test/graph/fastgql_schema.resolvers.go b/pkg/execution/test/graph/fastgql_schema.resolvers.go new file mode 100644 index 0000000..2a0b69a --- /dev/null +++ b/pkg/execution/test/graph/fastgql_schema.resolvers.go @@ -0,0 +1,65 @@ +package graph + +// This file will be automatically regenerated based on the schema, any resolver implementations +// will be copied through when generating and any unknown code will be moved to the end. +// Code generated by github.com/99designs/gqlgen version v0.17.41 + +import ( + "context" + + "github.com/georgysavva/scany/v2/pgxscan" + pgx "github.com/jackc/pgx/v5" + "github.com/roneli/fastgql/pkg/execution/builders/sql" + "github.com/roneli/fastgql/pkg/execution/test/graph/generated" + "github.com/roneli/fastgql/pkg/execution/test/graph/model" +) + +// CreatePosts is the resolver for the createPosts field. +func (r *mutationResolver) CreatePosts(ctx context.Context, inputs []model.CreatePostInput) (*model.PostsPayload, error) { + var data model.PostsPayload + q, args, err := sql.BuildQuery(ctx, sql.NewBuilder(r.Cfg)) + if err != nil { + return nil, err + } + if err := sql.ExecuteQuery(ctx, r.Executor, func(rows pgx.Rows) error { + return pgxscan.ScanOne(&data, rows) + }, q, args...); err != nil { + return nil, err + } + return &data, nil +} + +// DeletePosts is the resolver for the deletePosts field. +func (r *mutationResolver) DeletePosts(ctx context.Context, cascade *bool, filter *model.PostFilterInput) (*model.PostsPayload, error) { + var data model.PostsPayload + q, args, err := sql.BuildQuery(ctx, sql.NewBuilder(r.Cfg)) + if err != nil { + return nil, err + } + if err := sql.ExecuteQuery(ctx, r.Executor, func(rows pgx.Rows) error { + return pgxscan.ScanOne(&data, rows) + }, q, args...); err != nil { + return nil, err + } + return &data, nil +} + +// UpdatePosts is the resolver for the updatePosts field. +func (r *mutationResolver) UpdatePosts(ctx context.Context, input model.UpdatePostInput, filter *model.PostFilterInput) (*model.PostsPayload, error) { + var data model.PostsPayload + q, args, err := sql.BuildQuery(ctx, sql.NewBuilder(r.Cfg)) + if err != nil { + return nil, err + } + if err := sql.ExecuteQuery(ctx, r.Executor, func(rows pgx.Rows) error { + return pgxscan.ScanOne(&data, rows) + }, q, args...); err != nil { + return nil, err + } + return &data, nil +} + +// Mutation returns generated.MutationResolver implementation. +func (r *Resolver) Mutation() generated.MutationResolver { return &mutationResolver{r} } + +type mutationResolver struct{ *Resolver } diff --git a/pkg/execution/test/graph/generated/generated.go b/pkg/execution/test/graph/generated/generated.go index 4d631ad..6257399 100644 --- a/pkg/execution/test/graph/generated/generated.go +++ b/pkg/execution/test/graph/generated/generated.go @@ -38,6 +38,7 @@ type Config struct { } type ResolverRoot interface { + Mutation() MutationResolver Query() QueryResolver } @@ -91,6 +92,12 @@ type ComplexityRoot struct { Type func(childComplexity int) int } + Mutation struct { + CreatePosts func(childComplexity int, inputs []model.CreatePostInput) int + DeletePosts func(childComplexity int, cascade *bool, filter *model.PostFilterInput) int + UpdatePosts func(childComplexity int, input model.UpdatePostInput, filter *model.PostFilterInput) int + } + Post struct { Categories func(childComplexity int, limit *int, offset *int, orderBy []*model.CategoryOrdering, filter *model.CategoryFilterInput) int CategoriesAggregate func(childComplexity int, groupBy []model.CategoryGroupBy, filter *model.CategoryFilterInput) int @@ -114,6 +121,11 @@ type ComplexityRoot struct { Min func(childComplexity int) int } + PostsPayload struct { + Posts func(childComplexity int) int + RowsAffected func(childComplexity int) int + } + Query struct { Animals func(childComplexity int, limit *int, offset *int, orderBy []*model.AnimalOrdering, filter *model.AnimalFilterInput) int AnimalsAggregate func(childComplexity int, groupBy []model.AnimalGroupBy, filter *model.AnimalFilterInput) int @@ -149,6 +161,11 @@ type ComplexityRoot struct { } } +type MutationResolver interface { + CreatePosts(ctx context.Context, inputs []model.CreatePostInput) (*model.PostsPayload, error) + DeletePosts(ctx context.Context, cascade *bool, filter *model.PostFilterInput) (*model.PostsPayload, error) + UpdatePosts(ctx context.Context, input model.UpdatePostInput, filter *model.PostFilterInput) (*model.PostsPayload, error) +} type QueryResolver interface { Posts(ctx context.Context, limit *int, offset *int, orderBy []*model.PostOrdering, filter *model.PostFilterInput) ([]*model.Post, error) Users(ctx context.Context, limit *int, offset *int, orderBy []*model.UserOrdering, filter *model.UserFilterInput) ([]*model.User, error) @@ -340,6 +357,42 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.Dog.Type(childComplexity), true + case "Mutation.createPosts": + if e.complexity.Mutation.CreatePosts == nil { + break + } + + args, err := ec.field_Mutation_createPosts_args(context.TODO(), rawArgs) + if err != nil { + return 0, false + } + + return e.complexity.Mutation.CreatePosts(childComplexity, args["inputs"].([]model.CreatePostInput)), true + + case "Mutation.deletePosts": + if e.complexity.Mutation.DeletePosts == nil { + break + } + + args, err := ec.field_Mutation_deletePosts_args(context.TODO(), rawArgs) + if err != nil { + return 0, false + } + + return e.complexity.Mutation.DeletePosts(childComplexity, args["cascade"].(*bool), args["filter"].(*model.PostFilterInput)), true + + case "Mutation.updatePosts": + if e.complexity.Mutation.UpdatePosts == nil { + break + } + + args, err := ec.field_Mutation_updatePosts_args(context.TODO(), rawArgs) + if err != nil { + return 0, false + } + + return e.complexity.Mutation.UpdatePosts(childComplexity, args["input"].(model.UpdatePostInput), args["filter"].(*model.PostFilterInput)), true + case "Post.categories": if e.complexity.Post.Categories == nil { break @@ -453,6 +506,20 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.PostsAggregate.Min(childComplexity), true + case "PostsPayload.posts": + if e.complexity.PostsPayload.Posts == nil { + break + } + + return e.complexity.PostsPayload.Posts(childComplexity), true + + case "PostsPayload.rows_affected": + if e.complexity.PostsPayload.RowsAffected == nil { + break + } + + return e.complexity.PostsPayload.RowsAffected(childComplexity), true + case "Query.animals": if e.complexity.Query.Animals == nil { break @@ -651,6 +718,7 @@ func (e *executableSchema) Exec(ctx context.Context) graphql.ResponseHandler { ec.unmarshalInputCatFilterInput, ec.unmarshalInputCategoryFilterInput, ec.unmarshalInputCategoryOrdering, + ec.unmarshalInputCreatePostInput, ec.unmarshalInputDogFilterInput, ec.unmarshalInputFloatComparator, ec.unmarshalInputFloatListComparator, @@ -660,6 +728,7 @@ func (e *executableSchema) Exec(ctx context.Context) graphql.ResponseHandler { ec.unmarshalInputPostOrdering, ec.unmarshalInputStringComparator, ec.unmarshalInputStringListComparator, + ec.unmarshalInputUpdatePostInput, ec.unmarshalInputUserFilterInput, ec.unmarshalInputUserOrdering, ) @@ -696,6 +765,21 @@ func (e *executableSchema) Exec(ctx context.Context) graphql.ResponseHandler { return &response } + case ast.Mutation: + return func(ctx context.Context) *graphql.Response { + if !first { + return nil + } + first = false + ctx = graphql.WithUnmarshalerMap(ctx, inputUnmarshalMap) + data := ec._Mutation(ctx, rc.Operation.SelectionSet) + var buf bytes.Buffer + data.MarshalGQL(&buf) + + return &graphql.Response{ + Data: buf.Bytes(), + } + } default: return graphql.OneShot(graphql.ErrorResponse(ctx, "unsupported GraphQL operation")) @@ -947,6 +1031,35 @@ input DogFilterInput { """ NOT: DogFilterInput } +""" +Graphql Mutations +""" +type Mutation { + """ + AutoGenerated input for Post + """ + createPosts(inputs: [CreatePostInput!]!): PostsPayload + """ + AutoGenerated input for Post + """ + deletePosts( + """ + cascade on delete + """ + cascade: Boolean, + """ + Filter deletePosts + """ + filter: PostFilterInput): PostsPayload @generate(filter: true, filterTypeName: "PostFilterInput") + """ + AutoGenerated input for Post + """ + updatePosts(input: UpdatePostInput!, + """ + Filter updatePosts + """ + filter: PostFilterInput): PostsPayload @generate(filter: true, filterTypeName: "PostFilterInput") +} input PostFilterInput { id: IntComparator name: StringComparator @@ -1038,6 +1151,16 @@ type PostsAggregate { """ min: PostMin } +""" +Autogenerated payload object +""" +type PostsPayload { + """ + rows affection by mutation + """ + rows_affected: Int! + posts: [Post] +} input UserFilterInput { id: IntComparator name: StringComparator @@ -1115,6 +1238,22 @@ type UsersAggregate { """ min: UserMin } +""" +AutoGenerated input for Post +""" +input CreatePostInput { + id: Int! + name: String + user_id: Int +} +""" +AutoGenerated update input for Post +""" +input UpdatePostInput { + id: Int + name: String + user_id: Int +} `, BuiltIn: false}, {Name: "../common.graphql", Input: `directive @fastgqlField(skipSelect: Boolean = True) on FIELD_DEFINITION directive @generate(filter: Boolean = True, pagination: Boolean = True, ordering: Boolean = True, aggregate: Boolean = True, recursive: Boolean = True, filterTypeName: String) on FIELD_DEFINITION @@ -1229,7 +1368,7 @@ type Dog implements Animal { type: String! breed: String! } -type Post @generateFilterInput @table(name: "post") { +type Post @generateFilterInput @table(name: "post") @generateMutations { id: Int! name: String categories( @@ -1437,6 +1576,69 @@ func (ec *executionContext) dir_typename_args(ctx context.Context, rawArgs map[s return args, nil } +func (ec *executionContext) field_Mutation_createPosts_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + var arg0 []model.CreatePostInput + if tmp, ok := rawArgs["inputs"]; ok { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("inputs")) + arg0, err = ec.unmarshalNCreatePostInput2ᚕgithubᚗcomᚋroneliᚋfastgqlᚋpkgᚋexecutionᚋtestᚋgraphᚋmodelᚐCreatePostInputᚄ(ctx, tmp) + if err != nil { + return nil, err + } + } + args["inputs"] = arg0 + return args, nil +} + +func (ec *executionContext) field_Mutation_deletePosts_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + var arg0 *bool + if tmp, ok := rawArgs["cascade"]; ok { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("cascade")) + arg0, err = ec.unmarshalOBoolean2ᚖbool(ctx, tmp) + if err != nil { + return nil, err + } + } + args["cascade"] = arg0 + var arg1 *model.PostFilterInput + if tmp, ok := rawArgs["filter"]; ok { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("filter")) + arg1, err = ec.unmarshalOPostFilterInput2ᚖgithubᚗcomᚋroneliᚋfastgqlᚋpkgᚋexecutionᚋtestᚋgraphᚋmodelᚐPostFilterInput(ctx, tmp) + if err != nil { + return nil, err + } + } + args["filter"] = arg1 + return args, nil +} + +func (ec *executionContext) field_Mutation_updatePosts_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + var arg0 model.UpdatePostInput + if tmp, ok := rawArgs["input"]; ok { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("input")) + arg0, err = ec.unmarshalNUpdatePostInput2githubᚗcomᚋroneliᚋfastgqlᚋpkgᚋexecutionᚋtestᚋgraphᚋmodelᚐUpdatePostInput(ctx, tmp) + if err != nil { + return nil, err + } + } + args["input"] = arg0 + var arg1 *model.PostFilterInput + if tmp, ok := rawArgs["filter"]; ok { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("filter")) + arg1, err = ec.unmarshalOPostFilterInput2ᚖgithubᚗcomᚋroneliᚋfastgqlᚋpkgᚋexecutionᚋtestᚋgraphᚋmodelᚐPostFilterInput(ctx, tmp) + if err != nil { + return nil, err + } + } + args["filter"] = arg1 + return args, nil +} + func (ec *executionContext) field_Post__categoriesAggregate_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { var err error args := map[string]interface{}{} @@ -2929,6 +3131,180 @@ func (ec *executionContext) fieldContext_Dog_breed(ctx context.Context, field gr return fc, nil } +func (ec *executionContext) _Mutation_createPosts(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Mutation_createPosts(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.resolvers.Mutation().CreatePosts(rctx, fc.Args["inputs"].([]model.CreatePostInput)) + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*model.PostsPayload) + fc.Result = res + return ec.marshalOPostsPayload2ᚖgithubᚗcomᚋroneliᚋfastgqlᚋpkgᚋexecutionᚋtestᚋgraphᚋmodelᚐPostsPayload(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_Mutation_createPosts(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "Mutation", + Field: field, + IsMethod: true, + IsResolver: true, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "rows_affected": + return ec.fieldContext_PostsPayload_rows_affected(ctx, field) + case "posts": + return ec.fieldContext_PostsPayload_posts(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type PostsPayload", field.Name) + }, + } + defer func() { + if r := recover(); r != nil { + err = ec.Recover(ctx, r) + ec.Error(ctx, err) + } + }() + ctx = graphql.WithFieldContext(ctx, fc) + if fc.Args, err = ec.field_Mutation_createPosts_args(ctx, field.ArgumentMap(ec.Variables)); err != nil { + ec.Error(ctx, err) + return fc, err + } + return fc, nil +} + +func (ec *executionContext) _Mutation_deletePosts(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Mutation_deletePosts(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.resolvers.Mutation().DeletePosts(rctx, fc.Args["cascade"].(*bool), fc.Args["filter"].(*model.PostFilterInput)) + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*model.PostsPayload) + fc.Result = res + return ec.marshalOPostsPayload2ᚖgithubᚗcomᚋroneliᚋfastgqlᚋpkgᚋexecutionᚋtestᚋgraphᚋmodelᚐPostsPayload(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_Mutation_deletePosts(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "Mutation", + Field: field, + IsMethod: true, + IsResolver: true, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "rows_affected": + return ec.fieldContext_PostsPayload_rows_affected(ctx, field) + case "posts": + return ec.fieldContext_PostsPayload_posts(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type PostsPayload", field.Name) + }, + } + defer func() { + if r := recover(); r != nil { + err = ec.Recover(ctx, r) + ec.Error(ctx, err) + } + }() + ctx = graphql.WithFieldContext(ctx, fc) + if fc.Args, err = ec.field_Mutation_deletePosts_args(ctx, field.ArgumentMap(ec.Variables)); err != nil { + ec.Error(ctx, err) + return fc, err + } + return fc, nil +} + +func (ec *executionContext) _Mutation_updatePosts(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Mutation_updatePosts(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.resolvers.Mutation().UpdatePosts(rctx, fc.Args["input"].(model.UpdatePostInput), fc.Args["filter"].(*model.PostFilterInput)) + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*model.PostsPayload) + fc.Result = res + return ec.marshalOPostsPayload2ᚖgithubᚗcomᚋroneliᚋfastgqlᚋpkgᚋexecutionᚋtestᚋgraphᚋmodelᚐPostsPayload(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_Mutation_updatePosts(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "Mutation", + Field: field, + IsMethod: true, + IsResolver: true, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "rows_affected": + return ec.fieldContext_PostsPayload_rows_affected(ctx, field) + case "posts": + return ec.fieldContext_PostsPayload_posts(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type PostsPayload", field.Name) + }, + } + defer func() { + if r := recover(); r != nil { + err = ec.Recover(ctx, r) + ec.Error(ctx, err) + } + }() + ctx = graphql.WithFieldContext(ctx, fc) + if fc.Args, err = ec.field_Mutation_updatePosts_args(ctx, field.ArgumentMap(ec.Variables)); err != nil { + ec.Error(ctx, err) + return fc, err + } + return fc, nil +} + func (ec *executionContext) _Post_id(ctx context.Context, field graphql.CollectedField, obj *model.Post) (ret graphql.Marshaler) { fc, err := ec.fieldContext_Post_id(ctx, field) if err != nil { @@ -3467,8 +3843,101 @@ func (ec *executionContext) fieldContext_PostsAggregate_group(ctx context.Contex return fc, nil } -func (ec *executionContext) _PostsAggregate_count(ctx context.Context, field graphql.CollectedField, obj *model.PostsAggregate) (ret graphql.Marshaler) { - fc, err := ec.fieldContext_PostsAggregate_count(ctx, field) +func (ec *executionContext) _PostsAggregate_count(ctx context.Context, field graphql.CollectedField, obj *model.PostsAggregate) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_PostsAggregate_count(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Count, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(int) + fc.Result = res + return ec.marshalNInt2int(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_PostsAggregate_count(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "PostsAggregate", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type Int does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) _PostsAggregate_max(ctx context.Context, field graphql.CollectedField, obj *model.PostsAggregate) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_PostsAggregate_max(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Max, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*model.PostMin) + fc.Result = res + return ec.marshalOPostMin2ᚖgithubᚗcomᚋroneliᚋfastgqlᚋpkgᚋexecutionᚋtestᚋgraphᚋmodelᚐPostMin(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_PostsAggregate_max(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "PostsAggregate", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "id": + return ec.fieldContext_PostMin_id(ctx, field) + case "name": + return ec.fieldContext_PostMin_name(ctx, field) + case "user_id": + return ec.fieldContext_PostMin_user_id(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type PostMin", field.Name) + }, + } + return fc, nil +} + +func (ec *executionContext) _PostsAggregate_min(ctx context.Context, field graphql.CollectedField, obj *model.PostsAggregate) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_PostsAggregate_min(ctx, field) if err != nil { return graphql.Null } @@ -3481,38 +3950,43 @@ func (ec *executionContext) _PostsAggregate_count(ctx context.Context, field gra }() resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return obj.Count, nil + return obj.Min, nil }) if err != nil { ec.Error(ctx, err) return graphql.Null } if resTmp == nil { - if !graphql.HasFieldError(ctx, fc) { - ec.Errorf(ctx, "must not be null") - } return graphql.Null } - res := resTmp.(int) + res := resTmp.(*model.PostMin) fc.Result = res - return ec.marshalNInt2int(ctx, field.Selections, res) + return ec.marshalOPostMin2ᚖgithubᚗcomᚋroneliᚋfastgqlᚋpkgᚋexecutionᚋtestᚋgraphᚋmodelᚐPostMin(ctx, field.Selections, res) } -func (ec *executionContext) fieldContext_PostsAggregate_count(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { +func (ec *executionContext) fieldContext_PostsAggregate_min(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { fc = &graphql.FieldContext{ Object: "PostsAggregate", Field: field, IsMethod: false, IsResolver: false, Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { - return nil, errors.New("field of type Int does not have child fields") + switch field.Name { + case "id": + return ec.fieldContext_PostMin_id(ctx, field) + case "name": + return ec.fieldContext_PostMin_name(ctx, field) + case "user_id": + return ec.fieldContext_PostMin_user_id(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type PostMin", field.Name) }, } return fc, nil } -func (ec *executionContext) _PostsAggregate_max(ctx context.Context, field graphql.CollectedField, obj *model.PostsAggregate) (ret graphql.Marshaler) { - fc, err := ec.fieldContext_PostsAggregate_max(ctx, field) +func (ec *executionContext) _PostsPayload_rows_affected(ctx context.Context, field graphql.CollectedField, obj *model.PostsPayload) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_PostsPayload_rows_affected(ctx, field) if err != nil { return graphql.Null } @@ -3525,43 +3999,38 @@ func (ec *executionContext) _PostsAggregate_max(ctx context.Context, field graph }() resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return obj.Max, nil + return obj.RowsAffected, nil }) if err != nil { ec.Error(ctx, err) return graphql.Null } if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } - res := resTmp.(*model.PostMin) + res := resTmp.(int) fc.Result = res - return ec.marshalOPostMin2ᚖgithubᚗcomᚋroneliᚋfastgqlᚋpkgᚋexecutionᚋtestᚋgraphᚋmodelᚐPostMin(ctx, field.Selections, res) + return ec.marshalNInt2int(ctx, field.Selections, res) } -func (ec *executionContext) fieldContext_PostsAggregate_max(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { +func (ec *executionContext) fieldContext_PostsPayload_rows_affected(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { fc = &graphql.FieldContext{ - Object: "PostsAggregate", + Object: "PostsPayload", Field: field, IsMethod: false, IsResolver: false, Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { - switch field.Name { - case "id": - return ec.fieldContext_PostMin_id(ctx, field) - case "name": - return ec.fieldContext_PostMin_name(ctx, field) - case "user_id": - return ec.fieldContext_PostMin_user_id(ctx, field) - } - return nil, fmt.Errorf("no field named %q was found under type PostMin", field.Name) + return nil, errors.New("field of type Int does not have child fields") }, } return fc, nil } -func (ec *executionContext) _PostsAggregate_min(ctx context.Context, field graphql.CollectedField, obj *model.PostsAggregate) (ret graphql.Marshaler) { - fc, err := ec.fieldContext_PostsAggregate_min(ctx, field) +func (ec *executionContext) _PostsPayload_posts(ctx context.Context, field graphql.CollectedField, obj *model.PostsPayload) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_PostsPayload_posts(ctx, field) if err != nil { return graphql.Null } @@ -3574,7 +4043,7 @@ func (ec *executionContext) _PostsAggregate_min(ctx context.Context, field graph }() resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return obj.Min, nil + return obj.Posts, nil }) if err != nil { ec.Error(ctx, err) @@ -3583,27 +4052,35 @@ func (ec *executionContext) _PostsAggregate_min(ctx context.Context, field graph if resTmp == nil { return graphql.Null } - res := resTmp.(*model.PostMin) + res := resTmp.([]*model.Post) fc.Result = res - return ec.marshalOPostMin2ᚖgithubᚗcomᚋroneliᚋfastgqlᚋpkgᚋexecutionᚋtestᚋgraphᚋmodelᚐPostMin(ctx, field.Selections, res) + return ec.marshalOPost2ᚕᚖgithubᚗcomᚋroneliᚋfastgqlᚋpkgᚋexecutionᚋtestᚋgraphᚋmodelᚐPost(ctx, field.Selections, res) } -func (ec *executionContext) fieldContext_PostsAggregate_min(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { +func (ec *executionContext) fieldContext_PostsPayload_posts(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { fc = &graphql.FieldContext{ - Object: "PostsAggregate", + Object: "PostsPayload", Field: field, IsMethod: false, IsResolver: false, Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { switch field.Name { case "id": - return ec.fieldContext_PostMin_id(ctx, field) + return ec.fieldContext_Post_id(ctx, field) case "name": - return ec.fieldContext_PostMin_name(ctx, field) + return ec.fieldContext_Post_name(ctx, field) + case "categories": + return ec.fieldContext_Post_categories(ctx, field) case "user_id": - return ec.fieldContext_PostMin_user_id(ctx, field) + return ec.fieldContext_Post_user_id(ctx, field) + case "user": + return ec.fieldContext_Post_user(ctx, field) + case "_categoriesAggregate": + return ec.fieldContext_Post__categoriesAggregate(ctx, field) + case "_userAggregate": + return ec.fieldContext_Post__userAggregate(ctx, field) } - return nil, fmt.Errorf("no field named %q was found under type PostMin", field.Name) + return nil, fmt.Errorf("no field named %q was found under type Post", field.Name) }, } return fc, nil @@ -6921,6 +7398,47 @@ func (ec *executionContext) unmarshalInputCategoryOrdering(ctx context.Context, return it, nil } +func (ec *executionContext) unmarshalInputCreatePostInput(ctx context.Context, obj interface{}) (model.CreatePostInput, error) { + var it model.CreatePostInput + asMap := map[string]interface{}{} + for k, v := range obj.(map[string]interface{}) { + asMap[k] = v + } + + fieldsInOrder := [...]string{"id", "name", "user_id"} + for _, k := range fieldsInOrder { + v, ok := asMap[k] + if !ok { + continue + } + switch k { + case "id": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("id")) + data, err := ec.unmarshalNInt2int(ctx, v) + if err != nil { + return it, err + } + it.ID = data + case "name": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("name")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.Name = data + case "user_id": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("user_id")) + data, err := ec.unmarshalOInt2ᚖint(ctx, v) + if err != nil { + return it, err + } + it.UserID = data + } + } + + return it, nil +} + func (ec *executionContext) unmarshalInputDogFilterInput(ctx context.Context, obj interface{}) (model.DogFilterInput, error) { var it model.DogFilterInput asMap := map[string]interface{}{} @@ -7514,6 +8032,47 @@ func (ec *executionContext) unmarshalInputStringListComparator(ctx context.Conte return it, nil } +func (ec *executionContext) unmarshalInputUpdatePostInput(ctx context.Context, obj interface{}) (model.UpdatePostInput, error) { + var it model.UpdatePostInput + asMap := map[string]interface{}{} + for k, v := range obj.(map[string]interface{}) { + asMap[k] = v + } + + fieldsInOrder := [...]string{"id", "name", "user_id"} + for _, k := range fieldsInOrder { + v, ok := asMap[k] + if !ok { + continue + } + switch k { + case "id": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("id")) + data, err := ec.unmarshalOInt2ᚖint(ctx, v) + if err != nil { + return it, err + } + it.ID = data + case "name": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("name")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.Name = data + case "user_id": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("user_id")) + data, err := ec.unmarshalOInt2ᚖint(ctx, v) + if err != nil { + return it, err + } + it.UserID = data + } + } + + return it, nil +} + func (ec *executionContext) unmarshalInputUserFilterInput(ctx context.Context, obj interface{}) (model.UserFilterInput, error) { var it model.UserFilterInput asMap := map[string]interface{}{} @@ -7973,6 +8532,60 @@ func (ec *executionContext) _Dog(ctx context.Context, sel ast.SelectionSet, obj return out } +var mutationImplementors = []string{"Mutation"} + +func (ec *executionContext) _Mutation(ctx context.Context, sel ast.SelectionSet) graphql.Marshaler { + fields := graphql.CollectFields(ec.OperationContext, sel, mutationImplementors) + ctx = graphql.WithFieldContext(ctx, &graphql.FieldContext{ + Object: "Mutation", + }) + + out := graphql.NewFieldSet(fields) + deferred := make(map[string]*graphql.FieldSet) + for i, field := range fields { + innerCtx := graphql.WithRootFieldContext(ctx, &graphql.RootFieldContext{ + Object: field.Name, + Field: field, + }) + + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("Mutation") + case "createPosts": + out.Values[i] = ec.OperationContext.RootResolverMiddleware(innerCtx, func(ctx context.Context) (res graphql.Marshaler) { + return ec._Mutation_createPosts(ctx, field) + }) + case "deletePosts": + out.Values[i] = ec.OperationContext.RootResolverMiddleware(innerCtx, func(ctx context.Context) (res graphql.Marshaler) { + return ec._Mutation_deletePosts(ctx, field) + }) + case "updatePosts": + out.Values[i] = ec.OperationContext.RootResolverMiddleware(innerCtx, func(ctx context.Context) (res graphql.Marshaler) { + return ec._Mutation_updatePosts(ctx, field) + }) + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch(ctx) + if out.Invalids > 0 { + return graphql.Null + } + + atomic.AddInt32(&ec.deferred, int32(len(deferred))) + + for label, dfs := range deferred { + ec.processDeferredGroup(graphql.DeferredGroup{ + Label: label, + Path: graphql.GetPath(ctx), + FieldSet: dfs, + Context: ctx, + }) + } + + return out +} + var postImplementors = []string{"Post"} func (ec *executionContext) _Post(ctx context.Context, sel ast.SelectionSet, obj *model.Post) graphql.Marshaler { @@ -8124,6 +8737,47 @@ func (ec *executionContext) _PostsAggregate(ctx context.Context, sel ast.Selecti return out } +var postsPayloadImplementors = []string{"PostsPayload"} + +func (ec *executionContext) _PostsPayload(ctx context.Context, sel ast.SelectionSet, obj *model.PostsPayload) graphql.Marshaler { + fields := graphql.CollectFields(ec.OperationContext, sel, postsPayloadImplementors) + + out := graphql.NewFieldSet(fields) + deferred := make(map[string]*graphql.FieldSet) + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("PostsPayload") + case "rows_affected": + out.Values[i] = ec._PostsPayload_rows_affected(ctx, field, obj) + if out.Values[i] == graphql.Null { + out.Invalids++ + } + case "posts": + out.Values[i] = ec._PostsPayload_posts(ctx, field, obj) + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch(ctx) + if out.Invalids > 0 { + return graphql.Null + } + + atomic.AddInt32(&ec.deferred, int32(len(deferred))) + + for label, dfs := range deferred { + ec.processDeferredGroup(graphql.DeferredGroup{ + Label: label, + Path: graphql.GetPath(ctx), + FieldSet: dfs, + Context: ctx, + }) + } + + return out +} + var queryImplementors = []string{"Query"} func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) graphql.Marshaler { @@ -8974,6 +9628,28 @@ func (ec *executionContext) marshalNCategoryGroupBy2githubᚗcomᚋroneliᚋfast return v } +func (ec *executionContext) unmarshalNCreatePostInput2githubᚗcomᚋroneliᚋfastgqlᚋpkgᚋexecutionᚋtestᚋgraphᚋmodelᚐCreatePostInput(ctx context.Context, v interface{}) (model.CreatePostInput, error) { + res, err := ec.unmarshalInputCreatePostInput(ctx, v) + return res, graphql.ErrorOnPath(ctx, err) +} + +func (ec *executionContext) unmarshalNCreatePostInput2ᚕgithubᚗcomᚋroneliᚋfastgqlᚋpkgᚋexecutionᚋtestᚋgraphᚋmodelᚐCreatePostInputᚄ(ctx context.Context, v interface{}) ([]model.CreatePostInput, error) { + var vSlice []interface{} + if v != nil { + vSlice = graphql.CoerceList(v) + } + var err error + res := make([]model.CreatePostInput, len(vSlice)) + for i := range vSlice { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithIndex(i)) + res[i], err = ec.unmarshalNCreatePostInput2githubᚗcomᚋroneliᚋfastgqlᚋpkgᚋexecutionᚋtestᚋgraphᚋmodelᚐCreatePostInput(ctx, vSlice[i]) + if err != nil { + return nil, err + } + } + return res, nil +} + func (ec *executionContext) unmarshalNInt2int(ctx context.Context, v interface{}) (int, error) { res, err := graphql.UnmarshalInt(v) return res, graphql.ErrorOnPath(ctx, err) @@ -9094,6 +9770,11 @@ func (ec *executionContext) marshalNString2ᚕstringᚄ(ctx context.Context, sel return ret } +func (ec *executionContext) unmarshalNUpdatePostInput2githubᚗcomᚋroneliᚋfastgqlᚋpkgᚋexecutionᚋtestᚋgraphᚋmodelᚐUpdatePostInput(ctx context.Context, v interface{}) (model.UpdatePostInput, error) { + res, err := ec.unmarshalInputUpdatePostInput(ctx, v) + return res, graphql.ErrorOnPath(ctx, err) +} + func (ec *executionContext) unmarshalNUserGroupBy2githubᚗcomᚋroneliᚋfastgqlᚋpkgᚋexecutionᚋtestᚋgraphᚋmodelᚐUserGroupBy(ctx context.Context, v interface{}) (model.UserGroupBy, error) { var res model.UserGroupBy err := res.UnmarshalGQL(v) @@ -10183,6 +10864,13 @@ func (ec *executionContext) unmarshalOPostOrdering2ᚖgithubᚗcomᚋroneliᚋfa return &res, graphql.ErrorOnPath(ctx, err) } +func (ec *executionContext) marshalOPostsPayload2ᚖgithubᚗcomᚋroneliᚋfastgqlᚋpkgᚋexecutionᚋtestᚋgraphᚋmodelᚐPostsPayload(ctx context.Context, sel ast.SelectionSet, v *model.PostsPayload) graphql.Marshaler { + if v == nil { + return graphql.Null + } + return ec._PostsPayload(ctx, sel, v) +} + func (ec *executionContext) unmarshalOString2ᚕᚖstring(ctx context.Context, v interface{}) ([]*string, error) { if v == nil { return nil, nil diff --git a/pkg/execution/test/graph/model/models_gen.go b/pkg/execution/test/graph/model/models_gen.go index 7d69a41..cf088ea 100644 --- a/pkg/execution/test/graph/model/models_gen.go +++ b/pkg/execution/test/graph/model/models_gen.go @@ -145,6 +145,13 @@ type CategoryOrdering struct { Name *OrderingTypes `json:"name,omitempty" db:"name"` } +// AutoGenerated input for Post +type CreatePostInput struct { + ID int `json:"id" db:"id"` + Name *string `json:"name,omitempty" db:"name"` + UserID *int `json:"user_id,omitempty" db:"user_id"` +} + type Dog struct { ID int `json:"id" db:"id"` Name string `json:"name" db:"name"` @@ -266,6 +273,13 @@ type PostsAggregate struct { Min *PostMin `json:"min,omitempty" db:"min"` } +// Autogenerated payload object +type PostsPayload struct { + // rows affection by mutation + RowsAffected int `json:"rows_affected" db:"rows_affected"` + Posts []*Post `json:"posts,omitempty" db:"posts"` +} + type StringComparator struct { Eq *string `json:"eq,omitempty" db:"eq"` Neq *string `json:"neq,omitempty" db:"neq"` @@ -287,6 +301,13 @@ type StringListComparator struct { IsNull *bool `json:"isNull,omitempty" db:"is_null"` } +// AutoGenerated update input for Post +type UpdatePostInput struct { + ID *int `json:"id,omitempty" db:"id"` + Name *string `json:"name,omitempty" db:"name"` + UserID *int `json:"user_id,omitempty" db:"user_id"` +} + type User struct { ID int `json:"id" db:"id"` Name string `json:"name" db:"name"` diff --git a/pkg/execution/test/graph/schema.graphql b/pkg/execution/test/graph/schema.graphql index 82c16a6..2d127a0 100644 --- a/pkg/execution/test/graph/schema.graphql +++ b/pkg/execution/test/graph/schema.graphql @@ -19,7 +19,7 @@ type Dog implements Animal { type: String! breed: String! } -type Post @generateFilterInput @table(name: "post") { +type Post @generateFilterInput @table(name: "post") @generateMutations { id: Int! name: String categories: [Category] @relation(type: MANY_TO_MANY, fields: ["id"], references: ["id"], manyToManyTable: "posts_to_categories", manyToManyFields: ["post_id"], manyToManyReferences: ["category_id"])