diff --git a/internal/graph/generated.go b/internal/graph/generated.go index 310c637..722cd66 100644 --- a/internal/graph/generated.go +++ b/internal/graph/generated.go @@ -45,6 +45,14 @@ type DirectiveRoot struct { } type ComplexityRoot struct { + ColumnInfo struct { + Default func(childComplexity int) int + Key func(childComplexity int) int + Name func(childComplexity int) int + Nullable func(childComplexity int) int + Type func(childComplexity int) int + } + CreateTableResponse struct { Created func(childComplexity int) int } @@ -52,7 +60,7 @@ type ComplexityRoot struct { Mutation struct { AddColumn func(childComplexity int, tableName string, data model.AddUpdateColumnData) int CreateDatabase func(childComplexity int, name string) int - CreateTable func(childComplexity int, name string, data []*model.CreateTableData) int + CreateTable func(childComplexity int, name string, data []*model.CreateColumnData) int DeleteColumn func(childComplexity int, tableName string, data *model.DeleteColumnData) int DeleteTable func(childComplexity int, name string) int ModifyColumn func(childComplexity int, tableName string, data model.AddUpdateColumnData) int @@ -67,19 +75,11 @@ type ComplexityRoot struct { SuccessResponse struct { Success func(childComplexity int) int } - - TableInfo struct { - Default func(childComplexity int) int - Key func(childComplexity int) int - Name func(childComplexity int) int - Nullable func(childComplexity int) int - Type func(childComplexity int) int - } } type MutationResolver interface { CreateDatabase(ctx context.Context, name string) (*model.SuccessResponse, error) - CreateTable(ctx context.Context, name string, data []*model.CreateTableData) (*model.CreateTableResponse, error) + CreateTable(ctx context.Context, name string, data []*model.CreateColumnData) (*model.CreateTableResponse, error) DeleteTable(ctx context.Context, name string) (*model.SuccessResponse, error) AddColumn(ctx context.Context, tableName string, data model.AddUpdateColumnData) (*model.SuccessResponse, error) ModifyColumn(ctx context.Context, tableName string, data model.AddUpdateColumnData) (*model.SuccessResponse, error) @@ -88,7 +88,7 @@ type MutationResolver interface { type QueryResolver interface { Databases(ctx context.Context) ([]*string, error) Tables(ctx context.Context) ([]*string, error) - Table(ctx context.Context, name *string) ([]*model.TableInfo, error) + Table(ctx context.Context, name *string) ([]*model.ColumnInfo, error) } type executableSchema struct { @@ -106,6 +106,41 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in _ = ec switch typeName + "." + field { + case "ColumnInfo.default": + if e.complexity.ColumnInfo.Default == nil { + break + } + + return e.complexity.ColumnInfo.Default(childComplexity), true + + case "ColumnInfo.key": + if e.complexity.ColumnInfo.Key == nil { + break + } + + return e.complexity.ColumnInfo.Key(childComplexity), true + + case "ColumnInfo.name": + if e.complexity.ColumnInfo.Name == nil { + break + } + + return e.complexity.ColumnInfo.Name(childComplexity), true + + case "ColumnInfo.nullable": + if e.complexity.ColumnInfo.Nullable == nil { + break + } + + return e.complexity.ColumnInfo.Nullable(childComplexity), true + + case "ColumnInfo.type": + if e.complexity.ColumnInfo.Type == nil { + break + } + + return e.complexity.ColumnInfo.Type(childComplexity), true + case "CreateTableResponse.created": if e.complexity.CreateTableResponse.Created == nil { break @@ -147,7 +182,7 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return 0, false } - return e.complexity.Mutation.CreateTable(childComplexity, args["name"].(string), args["data"].([]*model.CreateTableData)), true + return e.complexity.Mutation.CreateTable(childComplexity, args["name"].(string), args["data"].([]*model.CreateColumnData)), true case "Mutation.deleteColumn": if e.complexity.Mutation.DeleteColumn == nil { @@ -218,41 +253,6 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.SuccessResponse.Success(childComplexity), true - case "TableInfo.default": - if e.complexity.TableInfo.Default == nil { - break - } - - return e.complexity.TableInfo.Default(childComplexity), true - - case "TableInfo.key": - if e.complexity.TableInfo.Key == nil { - break - } - - return e.complexity.TableInfo.Key(childComplexity), true - - case "TableInfo.name": - if e.complexity.TableInfo.Name == nil { - break - } - - return e.complexity.TableInfo.Name(childComplexity), true - - case "TableInfo.nullable": - if e.complexity.TableInfo.Nullable == nil { - break - } - - return e.complexity.TableInfo.Nullable(childComplexity), true - - case "TableInfo.type": - if e.complexity.TableInfo.Type == nil { - break - } - - return e.complexity.TableInfo.Type(childComplexity), true - } return 0, false } @@ -262,7 +262,7 @@ func (e *executableSchema) Exec(ctx context.Context) graphql.ResponseHandler { ec := executionContext{rc, e, 0, 0, make(chan graphql.DeferredResult)} inputUnmarshalMap := graphql.BuildUnmarshalerMap( ec.unmarshalInputAddUpdateColumnData, - ec.unmarshalInputCreateTableData, + ec.unmarshalInputCreateColumnData, ec.unmarshalInputDeleteColumnData, ) first := true @@ -431,10 +431,10 @@ func (ec *executionContext) field_Mutation_createTable_args(ctx context.Context, } } args["name"] = arg0 - var arg1 []*model.CreateTableData + var arg1 []*model.CreateColumnData if tmp, ok := rawArgs["data"]; ok { ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("data")) - arg1, err = ec.unmarshalNCreateTableData2ᚕᚖgithubᚗcomᚋkareemmahleesᚋmetaᚑxᚋinternalᚋgraphᚋmodelᚐCreateTableDataᚄ(ctx, tmp) + arg1, err = ec.unmarshalNCreateColumnData2ᚕᚖgithubᚗcomᚋkareemmahleesᚋmetaᚑxᚋinternalᚋgraphᚋmodelᚐCreateColumnDataᚄ(ctx, tmp) if err != nil { return nil, err } @@ -574,8 +574,8 @@ func (ec *executionContext) field___Type_fields_args(ctx context.Context, rawArg // region **************************** field.gotpl ***************************** -func (ec *executionContext) _CreateTableResponse_created(ctx context.Context, field graphql.CollectedField, obj *model.CreateTableResponse) (ret graphql.Marshaler) { - fc, err := ec.fieldContext_CreateTableResponse_created(ctx, field) +func (ec *executionContext) _ColumnInfo_name(ctx context.Context, field graphql.CollectedField, obj *model.ColumnInfo) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_ColumnInfo_name(ctx, field) if err != nil { return graphql.Null } @@ -588,26 +588,23 @@ func (ec *executionContext) _CreateTableResponse_created(ctx context.Context, fi }() resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return obj.Created, nil + return obj.Name, 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.(string) + res := resTmp.(*string) fc.Result = res - return ec.marshalNString2string(ctx, field.Selections, res) + return ec.marshalOString2ᚖstring(ctx, field.Selections, res) } -func (ec *executionContext) fieldContext_CreateTableResponse_created(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { +func (ec *executionContext) fieldContext_ColumnInfo_name(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { fc = &graphql.FieldContext{ - Object: "CreateTableResponse", + Object: "ColumnInfo", Field: field, IsMethod: false, IsResolver: false, @@ -618,8 +615,8 @@ func (ec *executionContext) fieldContext_CreateTableResponse_created(ctx context return fc, nil } -func (ec *executionContext) _Mutation_createDatabase(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { - fc, err := ec.fieldContext_Mutation_createDatabase(ctx, field) +func (ec *executionContext) _ColumnInfo_type(ctx context.Context, field graphql.CollectedField, obj *model.ColumnInfo) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_ColumnInfo_type(ctx, field) if err != nil { return graphql.Null } @@ -632,7 +629,7 @@ func (ec *executionContext) _Mutation_createDatabase(ctx context.Context, field }() resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return ec.resolvers.Mutation().CreateDatabase(rctx, fc.Args["name"].(string)) + return obj.Type, nil }) if err != nil { ec.Error(ctx, err) @@ -641,41 +638,26 @@ func (ec *executionContext) _Mutation_createDatabase(ctx context.Context, field if resTmp == nil { return graphql.Null } - res := resTmp.(*model.SuccessResponse) + res := resTmp.(*string) fc.Result = res - return ec.marshalOSuccessResponse2ᚖgithubᚗcomᚋkareemmahleesᚋmetaᚑxᚋinternalᚋgraphᚋmodelᚐSuccessResponse(ctx, field.Selections, res) + return ec.marshalOString2ᚖstring(ctx, field.Selections, res) } -func (ec *executionContext) fieldContext_Mutation_createDatabase(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { +func (ec *executionContext) fieldContext_ColumnInfo_type(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { fc = &graphql.FieldContext{ - Object: "Mutation", + Object: "ColumnInfo", Field: field, - IsMethod: true, - IsResolver: true, + IsMethod: false, + IsResolver: false, Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { - switch field.Name { - case "success": - return ec.fieldContext_SuccessResponse_success(ctx, field) - } - return nil, fmt.Errorf("no field named %q was found under type SuccessResponse", field.Name) + return nil, errors.New("field of type String does not have child fields") }, } - 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_createDatabase_args(ctx, field.ArgumentMap(ec.Variables)); err != nil { - ec.Error(ctx, err) - return fc, err - } return fc, nil } -func (ec *executionContext) _Mutation_createTable(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { - fc, err := ec.fieldContext_Mutation_createTable(ctx, field) +func (ec *executionContext) _ColumnInfo_nullable(ctx context.Context, field graphql.CollectedField, obj *model.ColumnInfo) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_ColumnInfo_nullable(ctx, field) if err != nil { return graphql.Null } @@ -688,7 +670,7 @@ func (ec *executionContext) _Mutation_createTable(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 ec.resolvers.Mutation().CreateTable(rctx, fc.Args["name"].(string), fc.Args["data"].([]*model.CreateTableData)) + return obj.Nullable, nil }) if err != nil { ec.Error(ctx, err) @@ -697,41 +679,26 @@ func (ec *executionContext) _Mutation_createTable(ctx context.Context, field gra if resTmp == nil { return graphql.Null } - res := resTmp.(*model.CreateTableResponse) + res := resTmp.(*string) fc.Result = res - return ec.marshalOCreateTableResponse2ᚖgithubᚗcomᚋkareemmahleesᚋmetaᚑxᚋinternalᚋgraphᚋmodelᚐCreateTableResponse(ctx, field.Selections, res) + return ec.marshalOString2ᚖstring(ctx, field.Selections, res) } -func (ec *executionContext) fieldContext_Mutation_createTable(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { +func (ec *executionContext) fieldContext_ColumnInfo_nullable(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { fc = &graphql.FieldContext{ - Object: "Mutation", + Object: "ColumnInfo", Field: field, - IsMethod: true, - IsResolver: true, + IsMethod: false, + IsResolver: false, Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { - switch field.Name { - case "created": - return ec.fieldContext_CreateTableResponse_created(ctx, field) - } - return nil, fmt.Errorf("no field named %q was found under type CreateTableResponse", field.Name) + return nil, errors.New("field of type String does not have child fields") }, } - 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_createTable_args(ctx, field.ArgumentMap(ec.Variables)); err != nil { - ec.Error(ctx, err) - return fc, err - } return fc, nil } -func (ec *executionContext) _Mutation_deleteTable(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { - fc, err := ec.fieldContext_Mutation_deleteTable(ctx, field) +func (ec *executionContext) _ColumnInfo_key(ctx context.Context, field graphql.CollectedField, obj *model.ColumnInfo) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_ColumnInfo_key(ctx, field) if err != nil { return graphql.Null } @@ -744,7 +711,7 @@ func (ec *executionContext) _Mutation_deleteTable(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 ec.resolvers.Mutation().DeleteTable(rctx, fc.Args["name"].(string)) + return obj.Key, nil }) if err != nil { ec.Error(ctx, err) @@ -753,41 +720,26 @@ func (ec *executionContext) _Mutation_deleteTable(ctx context.Context, field gra if resTmp == nil { return graphql.Null } - res := resTmp.(*model.SuccessResponse) + res := resTmp.(interface{}) fc.Result = res - return ec.marshalOSuccessResponse2ᚖgithubᚗcomᚋkareemmahleesᚋmetaᚑxᚋinternalᚋgraphᚋmodelᚐSuccessResponse(ctx, field.Selections, res) + return ec.marshalOAny2interface(ctx, field.Selections, res) } -func (ec *executionContext) fieldContext_Mutation_deleteTable(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { +func (ec *executionContext) fieldContext_ColumnInfo_key(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { fc = &graphql.FieldContext{ - Object: "Mutation", + Object: "ColumnInfo", Field: field, - IsMethod: true, - IsResolver: true, + IsMethod: false, + IsResolver: false, Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { - switch field.Name { - case "success": - return ec.fieldContext_SuccessResponse_success(ctx, field) - } - return nil, fmt.Errorf("no field named %q was found under type SuccessResponse", field.Name) + return nil, errors.New("field of type Any does not have child fields") }, } - 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_deleteTable_args(ctx, field.ArgumentMap(ec.Variables)); err != nil { - ec.Error(ctx, err) - return fc, err - } return fc, nil } -func (ec *executionContext) _Mutation_addColumn(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { - fc, err := ec.fieldContext_Mutation_addColumn(ctx, field) +func (ec *executionContext) _ColumnInfo_default(ctx context.Context, field graphql.CollectedField, obj *model.ColumnInfo) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_ColumnInfo_default(ctx, field) if err != nil { return graphql.Null } @@ -800,7 +752,7 @@ func (ec *executionContext) _Mutation_addColumn(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 ec.resolvers.Mutation().AddColumn(rctx, fc.Args["tableName"].(string), fc.Args["data"].(model.AddUpdateColumnData)) + return obj.Default, nil }) if err != nil { ec.Error(ctx, err) @@ -809,41 +761,26 @@ func (ec *executionContext) _Mutation_addColumn(ctx context.Context, field graph if resTmp == nil { return graphql.Null } - res := resTmp.(*model.SuccessResponse) + res := resTmp.(interface{}) fc.Result = res - return ec.marshalOSuccessResponse2ᚖgithubᚗcomᚋkareemmahleesᚋmetaᚑxᚋinternalᚋgraphᚋmodelᚐSuccessResponse(ctx, field.Selections, res) + return ec.marshalOAny2interface(ctx, field.Selections, res) } -func (ec *executionContext) fieldContext_Mutation_addColumn(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { +func (ec *executionContext) fieldContext_ColumnInfo_default(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { fc = &graphql.FieldContext{ - Object: "Mutation", + Object: "ColumnInfo", Field: field, - IsMethod: true, - IsResolver: true, + IsMethod: false, + IsResolver: false, Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { - switch field.Name { - case "success": - return ec.fieldContext_SuccessResponse_success(ctx, field) - } - return nil, fmt.Errorf("no field named %q was found under type SuccessResponse", field.Name) + return nil, errors.New("field of type Any does not have child fields") }, } - 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_addColumn_args(ctx, field.ArgumentMap(ec.Variables)); err != nil { - ec.Error(ctx, err) - return fc, err - } return fc, nil } -func (ec *executionContext) _Mutation_modifyColumn(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { - fc, err := ec.fieldContext_Mutation_modifyColumn(ctx, field) +func (ec *executionContext) _CreateTableResponse_created(ctx context.Context, field graphql.CollectedField, obj *model.CreateTableResponse) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_CreateTableResponse_created(ctx, field) if err != nil { return graphql.Null } @@ -856,50 +793,38 @@ func (ec *executionContext) _Mutation_modifyColumn(ctx context.Context, field gr }() resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return ec.resolvers.Mutation().ModifyColumn(rctx, fc.Args["tableName"].(string), fc.Args["data"].(model.AddUpdateColumnData)) + return obj.Created, 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.SuccessResponse) + res := resTmp.(string) fc.Result = res - return ec.marshalOSuccessResponse2ᚖgithubᚗcomᚋkareemmahleesᚋmetaᚑxᚋinternalᚋgraphᚋmodelᚐSuccessResponse(ctx, field.Selections, res) + return ec.marshalNString2string(ctx, field.Selections, res) } -func (ec *executionContext) fieldContext_Mutation_modifyColumn(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { +func (ec *executionContext) fieldContext_CreateTableResponse_created(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { fc = &graphql.FieldContext{ - Object: "Mutation", + Object: "CreateTableResponse", Field: field, - IsMethod: true, - IsResolver: true, + IsMethod: false, + IsResolver: false, Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { - switch field.Name { - case "success": - return ec.fieldContext_SuccessResponse_success(ctx, field) - } - return nil, fmt.Errorf("no field named %q was found under type SuccessResponse", field.Name) + return nil, errors.New("field of type String does not have child fields") }, } - 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_modifyColumn_args(ctx, field.ArgumentMap(ec.Variables)); err != nil { - ec.Error(ctx, err) - return fc, err - } return fc, nil } -func (ec *executionContext) _Mutation_deleteColumn(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { - fc, err := ec.fieldContext_Mutation_deleteColumn(ctx, field) +func (ec *executionContext) _Mutation_createDatabase(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Mutation_createDatabase(ctx, field) if err != nil { return graphql.Null } @@ -912,7 +837,7 @@ func (ec *executionContext) _Mutation_deleteColumn(ctx context.Context, field gr }() resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return ec.resolvers.Mutation().DeleteColumn(rctx, fc.Args["tableName"].(string), fc.Args["data"].(*model.DeleteColumnData)) + return ec.resolvers.Mutation().CreateDatabase(rctx, fc.Args["name"].(string)) }) if err != nil { ec.Error(ctx, err) @@ -926,7 +851,7 @@ func (ec *executionContext) _Mutation_deleteColumn(ctx context.Context, field gr return ec.marshalOSuccessResponse2ᚖgithubᚗcomᚋkareemmahleesᚋmetaᚑxᚋinternalᚋgraphᚋmodelᚐSuccessResponse(ctx, field.Selections, res) } -func (ec *executionContext) fieldContext_Mutation_deleteColumn(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { +func (ec *executionContext) fieldContext_Mutation_createDatabase(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { fc = &graphql.FieldContext{ Object: "Mutation", Field: field, @@ -947,15 +872,15 @@ func (ec *executionContext) fieldContext_Mutation_deleteColumn(ctx context.Conte } }() ctx = graphql.WithFieldContext(ctx, fc) - if fc.Args, err = ec.field_Mutation_deleteColumn_args(ctx, field.ArgumentMap(ec.Variables)); err != nil { + if fc.Args, err = ec.field_Mutation_createDatabase_args(ctx, field.ArgumentMap(ec.Variables)); err != nil { ec.Error(ctx, err) return fc, err } return fc, nil } -func (ec *executionContext) _Query_databases(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { - fc, err := ec.fieldContext_Query_databases(ctx, field) +func (ec *executionContext) _Mutation_createTable(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Mutation_createTable(ctx, field) if err != nil { return graphql.Null } @@ -968,7 +893,7 @@ func (ec *executionContext) _Query_databases(ctx context.Context, field graphql. }() resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return ec.resolvers.Query().Databases(rctx) + return ec.resolvers.Mutation().CreateTable(rctx, fc.Args["name"].(string), fc.Args["data"].([]*model.CreateColumnData)) }) if err != nil { ec.Error(ctx, err) @@ -977,26 +902,41 @@ func (ec *executionContext) _Query_databases(ctx context.Context, field graphql. if resTmp == nil { return graphql.Null } - res := resTmp.([]*string) + res := resTmp.(*model.CreateTableResponse) fc.Result = res - return ec.marshalOString2ᚕᚖstring(ctx, field.Selections, res) + return ec.marshalOCreateTableResponse2ᚖgithubᚗcomᚋkareemmahleesᚋmetaᚑxᚋinternalᚋgraphᚋmodelᚐCreateTableResponse(ctx, field.Selections, res) } -func (ec *executionContext) fieldContext_Query_databases(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { +func (ec *executionContext) fieldContext_Mutation_createTable(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { fc = &graphql.FieldContext{ - Object: "Query", + Object: "Mutation", Field: field, IsMethod: true, IsResolver: true, Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { - return nil, errors.New("field of type String does not have child fields") + switch field.Name { + case "created": + return ec.fieldContext_CreateTableResponse_created(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type CreateTableResponse", 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_createTable_args(ctx, field.ArgumentMap(ec.Variables)); err != nil { + ec.Error(ctx, err) + return fc, err + } return fc, nil } -func (ec *executionContext) _Query_tables(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { - fc, err := ec.fieldContext_Query_tables(ctx, field) +func (ec *executionContext) _Mutation_deleteTable(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Mutation_deleteTable(ctx, field) if err != nil { return graphql.Null } @@ -1009,7 +949,7 @@ func (ec *executionContext) _Query_tables(ctx context.Context, field graphql.Col }() resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return ec.resolvers.Query().Tables(rctx) + return ec.resolvers.Mutation().DeleteTable(rctx, fc.Args["name"].(string)) }) if err != nil { ec.Error(ctx, err) @@ -1018,26 +958,41 @@ func (ec *executionContext) _Query_tables(ctx context.Context, field graphql.Col if resTmp == nil { return graphql.Null } - res := resTmp.([]*string) + res := resTmp.(*model.SuccessResponse) fc.Result = res - return ec.marshalOString2ᚕᚖstring(ctx, field.Selections, res) + return ec.marshalOSuccessResponse2ᚖgithubᚗcomᚋkareemmahleesᚋmetaᚑxᚋinternalᚋgraphᚋmodelᚐSuccessResponse(ctx, field.Selections, res) } -func (ec *executionContext) fieldContext_Query_tables(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { +func (ec *executionContext) fieldContext_Mutation_deleteTable(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { fc = &graphql.FieldContext{ - Object: "Query", + Object: "Mutation", Field: field, IsMethod: true, IsResolver: true, Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { - return nil, errors.New("field of type String does not have child fields") + switch field.Name { + case "success": + return ec.fieldContext_SuccessResponse_success(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type SuccessResponse", 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_deleteTable_args(ctx, field.ArgumentMap(ec.Variables)); err != nil { + ec.Error(ctx, err) + return fc, err + } return fc, nil } -func (ec *executionContext) _Query_table(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { - fc, err := ec.fieldContext_Query_table(ctx, field) +func (ec *executionContext) _Mutation_addColumn(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Mutation_addColumn(ctx, field) if err != nil { return graphql.Null } @@ -1050,7 +1005,7 @@ func (ec *executionContext) _Query_table(ctx context.Context, field graphql.Coll }() resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return ec.resolvers.Query().Table(rctx, fc.Args["name"].(*string)) + return ec.resolvers.Mutation().AddColumn(rctx, fc.Args["tableName"].(string), fc.Args["data"].(model.AddUpdateColumnData)) }) if err != nil { ec.Error(ctx, err) @@ -1059,31 +1014,23 @@ func (ec *executionContext) _Query_table(ctx context.Context, field graphql.Coll if resTmp == nil { return graphql.Null } - res := resTmp.([]*model.TableInfo) + res := resTmp.(*model.SuccessResponse) fc.Result = res - return ec.marshalOTableInfo2ᚕᚖgithubᚗcomᚋkareemmahleesᚋmetaᚑxᚋinternalᚋgraphᚋmodelᚐTableInfo(ctx, field.Selections, res) + return ec.marshalOSuccessResponse2ᚖgithubᚗcomᚋkareemmahleesᚋmetaᚑxᚋinternalᚋgraphᚋmodelᚐSuccessResponse(ctx, field.Selections, res) } -func (ec *executionContext) fieldContext_Query_table(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { +func (ec *executionContext) fieldContext_Mutation_addColumn(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { fc = &graphql.FieldContext{ - Object: "Query", + Object: "Mutation", Field: field, IsMethod: true, IsResolver: true, Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { switch field.Name { - case "name": - return ec.fieldContext_TableInfo_name(ctx, field) - case "type": - return ec.fieldContext_TableInfo_type(ctx, field) - case "nullable": - return ec.fieldContext_TableInfo_nullable(ctx, field) - case "key": - return ec.fieldContext_TableInfo_key(ctx, field) - case "default": - return ec.fieldContext_TableInfo_default(ctx, field) + case "success": + return ec.fieldContext_SuccessResponse_success(ctx, field) } - return nil, fmt.Errorf("no field named %q was found under type TableInfo", field.Name) + return nil, fmt.Errorf("no field named %q was found under type SuccessResponse", field.Name) }, } defer func() { @@ -1093,15 +1040,15 @@ func (ec *executionContext) fieldContext_Query_table(ctx context.Context, field } }() ctx = graphql.WithFieldContext(ctx, fc) - if fc.Args, err = ec.field_Query_table_args(ctx, field.ArgumentMap(ec.Variables)); err != nil { + if fc.Args, err = ec.field_Mutation_addColumn_args(ctx, field.ArgumentMap(ec.Variables)); err != nil { ec.Error(ctx, err) return fc, err } return fc, nil } -func (ec *executionContext) _Query___type(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { - fc, err := ec.fieldContext_Query___type(ctx, field) +func (ec *executionContext) _Mutation_modifyColumn(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Mutation_modifyColumn(ctx, field) if err != nil { return graphql.Null } @@ -1114,7 +1061,7 @@ func (ec *executionContext) _Query___type(ctx context.Context, field graphql.Col }() resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return ec.introspectType(fc.Args["name"].(string)) + return ec.resolvers.Mutation().ModifyColumn(rctx, fc.Args["tableName"].(string), fc.Args["data"].(model.AddUpdateColumnData)) }) if err != nil { ec.Error(ctx, err) @@ -1123,41 +1070,23 @@ func (ec *executionContext) _Query___type(ctx context.Context, field graphql.Col if resTmp == nil { return graphql.Null } - res := resTmp.(*introspection.Type) + res := resTmp.(*model.SuccessResponse) fc.Result = res - return ec.marshalO__Type2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, field.Selections, res) + return ec.marshalOSuccessResponse2ᚖgithubᚗcomᚋkareemmahleesᚋmetaᚑxᚋinternalᚋgraphᚋmodelᚐSuccessResponse(ctx, field.Selections, res) } -func (ec *executionContext) fieldContext_Query___type(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { +func (ec *executionContext) fieldContext_Mutation_modifyColumn(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { fc = &graphql.FieldContext{ - Object: "Query", + Object: "Mutation", Field: field, IsMethod: true, - IsResolver: false, + IsResolver: true, Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { switch field.Name { - case "kind": - return ec.fieldContext___Type_kind(ctx, field) - case "name": - return ec.fieldContext___Type_name(ctx, field) - case "description": - return ec.fieldContext___Type_description(ctx, field) - case "fields": - return ec.fieldContext___Type_fields(ctx, field) - case "interfaces": - return ec.fieldContext___Type_interfaces(ctx, field) - case "possibleTypes": - return ec.fieldContext___Type_possibleTypes(ctx, field) - case "enumValues": - return ec.fieldContext___Type_enumValues(ctx, field) - case "inputFields": - return ec.fieldContext___Type_inputFields(ctx, field) - case "ofType": - return ec.fieldContext___Type_ofType(ctx, field) - case "specifiedByURL": - return ec.fieldContext___Type_specifiedByURL(ctx, field) + case "success": + return ec.fieldContext_SuccessResponse_success(ctx, field) } - return nil, fmt.Errorf("no field named %q was found under type __Type", field.Name) + return nil, fmt.Errorf("no field named %q was found under type SuccessResponse", field.Name) }, } defer func() { @@ -1167,15 +1096,15 @@ func (ec *executionContext) fieldContext_Query___type(ctx context.Context, field } }() ctx = graphql.WithFieldContext(ctx, fc) - if fc.Args, err = ec.field_Query___type_args(ctx, field.ArgumentMap(ec.Variables)); err != nil { + if fc.Args, err = ec.field_Mutation_modifyColumn_args(ctx, field.ArgumentMap(ec.Variables)); err != nil { ec.Error(ctx, err) return fc, err } return fc, nil } -func (ec *executionContext) _Query___schema(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { - fc, err := ec.fieldContext_Query___schema(ctx, field) +func (ec *executionContext) _Mutation_deleteColumn(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Mutation_deleteColumn(ctx, field) if err != nil { return graphql.Null } @@ -1188,7 +1117,7 @@ func (ec *executionContext) _Query___schema(ctx context.Context, field graphql.C }() resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return ec.introspectSchema() + return ec.resolvers.Mutation().DeleteColumn(rctx, fc.Args["tableName"].(string), fc.Args["data"].(*model.DeleteColumnData)) }) if err != nil { ec.Error(ctx, err) @@ -1197,40 +1126,41 @@ func (ec *executionContext) _Query___schema(ctx context.Context, field graphql.C if resTmp == nil { return graphql.Null } - res := resTmp.(*introspection.Schema) + res := resTmp.(*model.SuccessResponse) fc.Result = res - return ec.marshalO__Schema2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐSchema(ctx, field.Selections, res) + return ec.marshalOSuccessResponse2ᚖgithubᚗcomᚋkareemmahleesᚋmetaᚑxᚋinternalᚋgraphᚋmodelᚐSuccessResponse(ctx, field.Selections, res) } -func (ec *executionContext) fieldContext_Query___schema(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { +func (ec *executionContext) fieldContext_Mutation_deleteColumn(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { fc = &graphql.FieldContext{ - Object: "Query", + Object: "Mutation", Field: field, IsMethod: true, - IsResolver: false, + IsResolver: true, Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { switch field.Name { - case "description": - return ec.fieldContext___Schema_description(ctx, field) - case "types": - return ec.fieldContext___Schema_types(ctx, field) - case "queryType": - return ec.fieldContext___Schema_queryType(ctx, field) - case "mutationType": - return ec.fieldContext___Schema_mutationType(ctx, field) - case "subscriptionType": - return ec.fieldContext___Schema_subscriptionType(ctx, field) - case "directives": - return ec.fieldContext___Schema_directives(ctx, field) + case "success": + return ec.fieldContext_SuccessResponse_success(ctx, field) } - return nil, fmt.Errorf("no field named %q was found under type __Schema", field.Name) + return nil, fmt.Errorf("no field named %q was found under type SuccessResponse", 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_deleteColumn_args(ctx, field.ArgumentMap(ec.Variables)); err != nil { + ec.Error(ctx, err) + return fc, err + } return fc, nil } -func (ec *executionContext) _SuccessResponse_success(ctx context.Context, field graphql.CollectedField, obj *model.SuccessResponse) (ret graphql.Marshaler) { - fc, err := ec.fieldContext_SuccessResponse_success(ctx, field) +func (ec *executionContext) _Query_databases(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Query_databases(ctx, field) if err != nil { return graphql.Null } @@ -1243,38 +1173,35 @@ func (ec *executionContext) _SuccessResponse_success(ctx context.Context, field }() resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return obj.Success, nil + return ec.resolvers.Query().Databases(rctx) }) 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.(bool) + res := resTmp.([]*string) fc.Result = res - return ec.marshalNBoolean2bool(ctx, field.Selections, res) + return ec.marshalOString2ᚕᚖstring(ctx, field.Selections, res) } -func (ec *executionContext) fieldContext_SuccessResponse_success(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { +func (ec *executionContext) fieldContext_Query_databases(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { fc = &graphql.FieldContext{ - Object: "SuccessResponse", + Object: "Query", Field: field, - IsMethod: false, - IsResolver: false, + IsMethod: true, + IsResolver: true, Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { - return nil, errors.New("field of type Boolean does not have child fields") + return nil, errors.New("field of type String does not have child fields") }, } return fc, nil } -func (ec *executionContext) _TableInfo_name(ctx context.Context, field graphql.CollectedField, obj *model.TableInfo) (ret graphql.Marshaler) { - fc, err := ec.fieldContext_TableInfo_name(ctx, field) +func (ec *executionContext) _Query_tables(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Query_tables(ctx, field) if err != nil { return graphql.Null } @@ -1287,7 +1214,7 @@ func (ec *executionContext) _TableInfo_name(ctx context.Context, field graphql.C }() resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return obj.Name, nil + return ec.resolvers.Query().Tables(rctx) }) if err != nil { ec.Error(ctx, err) @@ -1296,17 +1223,17 @@ func (ec *executionContext) _TableInfo_name(ctx context.Context, field graphql.C if resTmp == nil { return graphql.Null } - res := resTmp.(*string) + res := resTmp.([]*string) fc.Result = res - return ec.marshalOString2ᚖstring(ctx, field.Selections, res) + return ec.marshalOString2ᚕᚖstring(ctx, field.Selections, res) } -func (ec *executionContext) fieldContext_TableInfo_name(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { +func (ec *executionContext) fieldContext_Query_tables(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { fc = &graphql.FieldContext{ - Object: "TableInfo", + Object: "Query", Field: field, - IsMethod: false, - IsResolver: false, + IsMethod: true, + IsResolver: true, Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { return nil, errors.New("field of type String does not have child fields") }, @@ -1314,8 +1241,8 @@ func (ec *executionContext) fieldContext_TableInfo_name(ctx context.Context, fie return fc, nil } -func (ec *executionContext) _TableInfo_type(ctx context.Context, field graphql.CollectedField, obj *model.TableInfo) (ret graphql.Marshaler) { - fc, err := ec.fieldContext_TableInfo_type(ctx, field) +func (ec *executionContext) _Query_table(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Query_table(ctx, field) if err != nil { return graphql.Null } @@ -1328,7 +1255,7 @@ func (ec *executionContext) _TableInfo_type(ctx context.Context, field graphql.C }() resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return obj.Type, nil + return ec.resolvers.Query().Table(rctx, fc.Args["name"].(*string)) }) if err != nil { ec.Error(ctx, err) @@ -1337,26 +1264,49 @@ func (ec *executionContext) _TableInfo_type(ctx context.Context, field graphql.C if resTmp == nil { return graphql.Null } - res := resTmp.(*string) + res := resTmp.([]*model.ColumnInfo) fc.Result = res - return ec.marshalOString2ᚖstring(ctx, field.Selections, res) + return ec.marshalOColumnInfo2ᚕᚖgithubᚗcomᚋkareemmahleesᚋmetaᚑxᚋinternalᚋgraphᚋmodelᚐColumnInfo(ctx, field.Selections, res) } -func (ec *executionContext) fieldContext_TableInfo_type(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { +func (ec *executionContext) fieldContext_Query_table(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { fc = &graphql.FieldContext{ - Object: "TableInfo", + Object: "Query", Field: field, - IsMethod: false, - IsResolver: false, + IsMethod: true, + IsResolver: true, Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { - return nil, errors.New("field of type String does not have child fields") + switch field.Name { + case "name": + return ec.fieldContext_ColumnInfo_name(ctx, field) + case "type": + return ec.fieldContext_ColumnInfo_type(ctx, field) + case "nullable": + return ec.fieldContext_ColumnInfo_nullable(ctx, field) + case "key": + return ec.fieldContext_ColumnInfo_key(ctx, field) + case "default": + return ec.fieldContext_ColumnInfo_default(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type ColumnInfo", 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_Query_table_args(ctx, field.ArgumentMap(ec.Variables)); err != nil { + ec.Error(ctx, err) + return fc, err + } return fc, nil } -func (ec *executionContext) _TableInfo_nullable(ctx context.Context, field graphql.CollectedField, obj *model.TableInfo) (ret graphql.Marshaler) { - fc, err := ec.fieldContext_TableInfo_nullable(ctx, field) +func (ec *executionContext) _Query___type(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Query___type(ctx, field) if err != nil { return graphql.Null } @@ -1369,7 +1319,7 @@ func (ec *executionContext) _TableInfo_nullable(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.Nullable, nil + return ec.introspectType(fc.Args["name"].(string)) }) if err != nil { ec.Error(ctx, err) @@ -1378,26 +1328,59 @@ func (ec *executionContext) _TableInfo_nullable(ctx context.Context, field graph if resTmp == nil { return graphql.Null } - res := resTmp.(*string) + res := resTmp.(*introspection.Type) fc.Result = res - return ec.marshalOString2ᚖstring(ctx, field.Selections, res) + return ec.marshalO__Type2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, field.Selections, res) } -func (ec *executionContext) fieldContext_TableInfo_nullable(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { +func (ec *executionContext) fieldContext_Query___type(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { fc = &graphql.FieldContext{ - Object: "TableInfo", + Object: "Query", Field: field, - IsMethod: false, + IsMethod: true, IsResolver: false, Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { - return nil, errors.New("field of type String does not have child fields") + switch field.Name { + case "kind": + return ec.fieldContext___Type_kind(ctx, field) + case "name": + return ec.fieldContext___Type_name(ctx, field) + case "description": + return ec.fieldContext___Type_description(ctx, field) + case "fields": + return ec.fieldContext___Type_fields(ctx, field) + case "interfaces": + return ec.fieldContext___Type_interfaces(ctx, field) + case "possibleTypes": + return ec.fieldContext___Type_possibleTypes(ctx, field) + case "enumValues": + return ec.fieldContext___Type_enumValues(ctx, field) + case "inputFields": + return ec.fieldContext___Type_inputFields(ctx, field) + case "ofType": + return ec.fieldContext___Type_ofType(ctx, field) + case "specifiedByURL": + return ec.fieldContext___Type_specifiedByURL(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type __Type", 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_Query___type_args(ctx, field.ArgumentMap(ec.Variables)); err != nil { + ec.Error(ctx, err) + return fc, err + } return fc, nil } -func (ec *executionContext) _TableInfo_key(ctx context.Context, field graphql.CollectedField, obj *model.TableInfo) (ret graphql.Marshaler) { - fc, err := ec.fieldContext_TableInfo_key(ctx, field) +func (ec *executionContext) _Query___schema(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Query___schema(ctx, field) if err != nil { return graphql.Null } @@ -1410,7 +1393,7 @@ func (ec *executionContext) _TableInfo_key(ctx context.Context, field graphql.Co }() resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return obj.Key, nil + return ec.introspectSchema() }) if err != nil { ec.Error(ctx, err) @@ -1419,26 +1402,40 @@ func (ec *executionContext) _TableInfo_key(ctx context.Context, field graphql.Co if resTmp == nil { return graphql.Null } - res := resTmp.(interface{}) + res := resTmp.(*introspection.Schema) fc.Result = res - return ec.marshalOAny2interface(ctx, field.Selections, res) + return ec.marshalO__Schema2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐSchema(ctx, field.Selections, res) } -func (ec *executionContext) fieldContext_TableInfo_key(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { +func (ec *executionContext) fieldContext_Query___schema(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { fc = &graphql.FieldContext{ - Object: "TableInfo", + Object: "Query", Field: field, - IsMethod: false, + IsMethod: true, IsResolver: false, Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { - return nil, errors.New("field of type Any does not have child fields") + switch field.Name { + case "description": + return ec.fieldContext___Schema_description(ctx, field) + case "types": + return ec.fieldContext___Schema_types(ctx, field) + case "queryType": + return ec.fieldContext___Schema_queryType(ctx, field) + case "mutationType": + return ec.fieldContext___Schema_mutationType(ctx, field) + case "subscriptionType": + return ec.fieldContext___Schema_subscriptionType(ctx, field) + case "directives": + return ec.fieldContext___Schema_directives(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type __Schema", field.Name) }, } return fc, nil } -func (ec *executionContext) _TableInfo_default(ctx context.Context, field graphql.CollectedField, obj *model.TableInfo) (ret graphql.Marshaler) { - fc, err := ec.fieldContext_TableInfo_default(ctx, field) +func (ec *executionContext) _SuccessResponse_success(ctx context.Context, field graphql.CollectedField, obj *model.SuccessResponse) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_SuccessResponse_success(ctx, field) if err != nil { return graphql.Null } @@ -1451,28 +1448,31 @@ func (ec *executionContext) _TableInfo_default(ctx context.Context, field graphq }() resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return obj.Default, nil + return obj.Success, 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.(interface{}) + res := resTmp.(bool) fc.Result = res - return ec.marshalOAny2interface(ctx, field.Selections, res) + return ec.marshalNBoolean2bool(ctx, field.Selections, res) } -func (ec *executionContext) fieldContext_TableInfo_default(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { +func (ec *executionContext) fieldContext_SuccessResponse_success(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { fc = &graphql.FieldContext{ - Object: "TableInfo", + Object: "SuccessResponse", Field: field, IsMethod: false, IsResolver: false, Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { - return nil, errors.New("field of type Any does not have child fields") + return nil, errors.New("field of type Boolean does not have child fields") }, } return fc, nil @@ -3289,8 +3289,8 @@ func (ec *executionContext) unmarshalInputAddUpdateColumnData(ctx context.Contex return it, nil } -func (ec *executionContext) unmarshalInputCreateTableData(ctx context.Context, obj interface{}) (model.CreateTableData, error) { - var it model.CreateTableData +func (ec *executionContext) unmarshalInputCreateColumnData(ctx context.Context, obj interface{}) (model.CreateColumnData, error) { + var it model.CreateColumnData asMap := map[string]interface{}{} for k, v := range obj.(map[string]interface{}) { asMap[k] = v @@ -3391,6 +3391,50 @@ func (ec *executionContext) unmarshalInputDeleteColumnData(ctx context.Context, // region **************************** object.gotpl **************************** +var columnInfoImplementors = []string{"ColumnInfo"} + +func (ec *executionContext) _ColumnInfo(ctx context.Context, sel ast.SelectionSet, obj *model.ColumnInfo) graphql.Marshaler { + fields := graphql.CollectFields(ec.OperationContext, sel, columnInfoImplementors) + + 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("ColumnInfo") + case "name": + out.Values[i] = ec._ColumnInfo_name(ctx, field, obj) + case "type": + out.Values[i] = ec._ColumnInfo_type(ctx, field, obj) + case "nullable": + out.Values[i] = ec._ColumnInfo_nullable(ctx, field, obj) + case "key": + out.Values[i] = ec._ColumnInfo_key(ctx, field, obj) + case "default": + out.Values[i] = ec._ColumnInfo_default(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 createTableResponseImplementors = []string{"CreateTableResponse"} func (ec *executionContext) _CreateTableResponse(ctx context.Context, sel ast.SelectionSet, obj *model.CreateTableResponse) graphql.Marshaler { @@ -3642,50 +3686,6 @@ func (ec *executionContext) _SuccessResponse(ctx context.Context, sel ast.Select return out } -var tableInfoImplementors = []string{"TableInfo"} - -func (ec *executionContext) _TableInfo(ctx context.Context, sel ast.SelectionSet, obj *model.TableInfo) graphql.Marshaler { - fields := graphql.CollectFields(ec.OperationContext, sel, tableInfoImplementors) - - 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("TableInfo") - case "name": - out.Values[i] = ec._TableInfo_name(ctx, field, obj) - case "type": - out.Values[i] = ec._TableInfo_type(ctx, field, obj) - case "nullable": - out.Values[i] = ec._TableInfo_nullable(ctx, field, obj) - case "key": - out.Values[i] = ec._TableInfo_key(ctx, field, obj) - case "default": - out.Values[i] = ec._TableInfo_default(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 __DirectiveImplementors = []string{"__Directive"} func (ec *executionContext) ___Directive(ctx context.Context, sel ast.SelectionSet, obj *introspection.Directive) graphql.Marshaler { @@ -4032,16 +4032,16 @@ func (ec *executionContext) marshalNBoolean2bool(ctx context.Context, sel ast.Se return res } -func (ec *executionContext) unmarshalNCreateTableData2ᚕᚖgithubᚗcomᚋkareemmahleesᚋmetaᚑxᚋinternalᚋgraphᚋmodelᚐCreateTableDataᚄ(ctx context.Context, v interface{}) ([]*model.CreateTableData, error) { +func (ec *executionContext) unmarshalNCreateColumnData2ᚕᚖgithubᚗcomᚋkareemmahleesᚋmetaᚑxᚋinternalᚋgraphᚋmodelᚐCreateColumnDataᚄ(ctx context.Context, v interface{}) ([]*model.CreateColumnData, error) { var vSlice []interface{} if v != nil { vSlice = graphql.CoerceList(v) } var err error - res := make([]*model.CreateTableData, len(vSlice)) + res := make([]*model.CreateColumnData, len(vSlice)) for i := range vSlice { ctx := graphql.WithPathContext(ctx, graphql.NewPathWithIndex(i)) - res[i], err = ec.unmarshalNCreateTableData2ᚖgithubᚗcomᚋkareemmahleesᚋmetaᚑxᚋinternalᚋgraphᚋmodelᚐCreateTableData(ctx, vSlice[i]) + res[i], err = ec.unmarshalNCreateColumnData2ᚖgithubᚗcomᚋkareemmahleesᚋmetaᚑxᚋinternalᚋgraphᚋmodelᚐCreateColumnData(ctx, vSlice[i]) if err != nil { return nil, err } @@ -4049,8 +4049,8 @@ func (ec *executionContext) unmarshalNCreateTableData2ᚕᚖgithubᚗcomᚋkaree return res, nil } -func (ec *executionContext) unmarshalNCreateTableData2ᚖgithubᚗcomᚋkareemmahleesᚋmetaᚑxᚋinternalᚋgraphᚋmodelᚐCreateTableData(ctx context.Context, v interface{}) (*model.CreateTableData, error) { - res, err := ec.unmarshalInputCreateTableData(ctx, v) +func (ec *executionContext) unmarshalNCreateColumnData2ᚖgithubᚗcomᚋkareemmahleesᚋmetaᚑxᚋinternalᚋgraphᚋmodelᚐCreateColumnData(ctx context.Context, v interface{}) (*model.CreateColumnData, error) { + res, err := ec.unmarshalInputCreateColumnData(ctx, v) return &res, graphql.ErrorOnPath(ctx, err) } @@ -4364,6 +4364,54 @@ func (ec *executionContext) marshalOBoolean2ᚖbool(ctx context.Context, sel ast return res } +func (ec *executionContext) marshalOColumnInfo2ᚕᚖgithubᚗcomᚋkareemmahleesᚋmetaᚑxᚋinternalᚋgraphᚋmodelᚐColumnInfo(ctx context.Context, sel ast.SelectionSet, v []*model.ColumnInfo) graphql.Marshaler { + if v == nil { + return graphql.Null + } + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + for i := range v { + i := i + fc := &graphql.FieldContext{ + Index: &i, + Result: &v[i], + } + ctx := graphql.WithFieldContext(ctx, fc) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() + } + ret[i] = ec.marshalOColumnInfo2ᚖgithubᚗcomᚋkareemmahleesᚋmetaᚑxᚋinternalᚋgraphᚋmodelᚐColumnInfo(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } + + } + wg.Wait() + + return ret +} + +func (ec *executionContext) marshalOColumnInfo2ᚖgithubᚗcomᚋkareemmahleesᚋmetaᚑxᚋinternalᚋgraphᚋmodelᚐColumnInfo(ctx context.Context, sel ast.SelectionSet, v *model.ColumnInfo) graphql.Marshaler { + if v == nil { + return graphql.Null + } + return ec._ColumnInfo(ctx, sel, v) +} + func (ec *executionContext) marshalOCreateTableResponse2ᚖgithubᚗcomᚋkareemmahleesᚋmetaᚑxᚋinternalᚋgraphᚋmodelᚐCreateTableResponse(ctx context.Context, sel ast.SelectionSet, v *model.CreateTableResponse) graphql.Marshaler { if v == nil { return graphql.Null @@ -4434,54 +4482,6 @@ func (ec *executionContext) marshalOSuccessResponse2ᚖgithubᚗcomᚋkareemmahl return ec._SuccessResponse(ctx, sel, v) } -func (ec *executionContext) marshalOTableInfo2ᚕᚖgithubᚗcomᚋkareemmahleesᚋmetaᚑxᚋinternalᚋgraphᚋmodelᚐTableInfo(ctx context.Context, sel ast.SelectionSet, v []*model.TableInfo) graphql.Marshaler { - if v == nil { - return graphql.Null - } - ret := make(graphql.Array, len(v)) - var wg sync.WaitGroup - isLen1 := len(v) == 1 - if !isLen1 { - wg.Add(len(v)) - } - for i := range v { - i := i - fc := &graphql.FieldContext{ - Index: &i, - Result: &v[i], - } - ctx := graphql.WithFieldContext(ctx, fc) - f := func(i int) { - defer func() { - if r := recover(); r != nil { - ec.Error(ctx, ec.Recover(ctx, r)) - ret = nil - } - }() - if !isLen1 { - defer wg.Done() - } - ret[i] = ec.marshalOTableInfo2ᚖgithubᚗcomᚋkareemmahleesᚋmetaᚑxᚋinternalᚋgraphᚋmodelᚐTableInfo(ctx, sel, v[i]) - } - if isLen1 { - f(i) - } else { - go f(i) - } - - } - wg.Wait() - - return ret -} - -func (ec *executionContext) marshalOTableInfo2ᚖgithubᚗcomᚋkareemmahleesᚋmetaᚑxᚋinternalᚋgraphᚋmodelᚐTableInfo(ctx context.Context, sel ast.SelectionSet, v *model.TableInfo) graphql.Marshaler { - if v == nil { - return graphql.Null - } - return ec._TableInfo(ctx, sel, v) -} - func (ec *executionContext) marshalO__EnumValue2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐEnumValueᚄ(ctx context.Context, sel ast.SelectionSet, v []introspection.EnumValue) graphql.Marshaler { if v == nil { return graphql.Null diff --git a/internal/graph/model/models_gen.go b/internal/graph/model/models_gen.go index 43f3f1d..007b0e2 100644 --- a/internal/graph/model/models_gen.go +++ b/internal/graph/model/models_gen.go @@ -2,37 +2,54 @@ package model +// Data used when adding or updating a column type AddUpdateColumnData struct { + // Column name ColName *string `json:"colName,omitempty"` - Type *string `json:"type,omitempty"` + // Column data type + Type *string `json:"type,omitempty"` } -type CreateTableData struct { - ColName *string `json:"colName,omitempty"` - Type *string `json:"type,omitempty"` - Nullable *bool `json:"nullable,omitempty"` - Default interface{} `json:"default,omitempty"` - Unique *bool `json:"unique,omitempty"` +// Several info about a table column +type ColumnInfo struct { + // Column name + Name *string `json:"name,omitempty"` + // Column data type + Type *string `json:"type,omitempty"` + // If the table accepts null values or not + Nullable *string `json:"nullable,omitempty"` + // Constraint name of the column, e.g PRI + Key interface{} `json:"key,omitempty"` + // Column default value + Default interface{} `json:"default,omitempty"` } +// General data about the column to create +type CreateColumnData struct { + // Column name + ColName *string `json:"colName,omitempty"` + // Data type of the column + Type *string `json:"type,omitempty"` + // Wether the column accepts null values + Nullable *bool `json:"nullable,omitempty"` + // Default value of the column + Default interface{} `json:"default,omitempty"` + // Wether to add unique constraint on the column + Unique *bool `json:"unique,omitempty"` +} + +// Table created successfully type CreateTableResponse struct { - // name of created table + // Name of created table Created string `json:"created"` } type DeleteColumnData struct { + // Deleted column name ColName *string `json:"colName,omitempty"` } +// Generic operation success response type SuccessResponse struct { Success bool `json:"success"` } - -// Table info like field name returned from table query -type TableInfo struct { - Name *string `json:"name,omitempty"` - Type *string `json:"type,omitempty"` - Nullable *string `json:"nullable,omitempty"` - Key interface{} `json:"key,omitempty"` - Default interface{} `json:"default,omitempty"` -} diff --git a/internal/graph/schema.graphql b/internal/graph/schema.graphql index 6533d60..3c3e59d 100644 --- a/internal/graph/schema.graphql +++ b/internal/graph/schema.graphql @@ -26,43 +26,58 @@ type ColumnInfo { } type Mutation { - "creates a database with the specified name" + "Creates a database with the specified name" createDatabase(name: String!): SuccessResponse - "creates a table with the specified name" - createTable(name: String!, data: [CreateTableData!]!): CreateTableResponse - "deletes the table by name" + "Creates a table with the specified name and columns info" + createTable(name: String!, data: [CreateColumnData!]!): CreateTableResponse + "Deletes specified table" deleteTable(name: String!): SuccessResponse - "updated the table by name" # updateTable(name: String!, prop: UpdateTableData): SuccessResponse + "Add a new column to the table" addColumn(tableName: String!, data: AddUpdateColumnData!): SuccessResponse + "Modifies a column datatype" modifyColumn(tableName: String!, data: AddUpdateColumnData!): SuccessResponse + "Deletes a column" deleteColumn(tableName: String!, data: DeleteColumnData): SuccessResponse } -input CreateTableData { +"General data about the column to create" +input CreateColumnData { + "Column name" colName: String + "Data type of the column" type: String + "Wether the column accepts null values" nullable: Boolean + "Default value of the column" default: Any + "Wether to add unique constraint on the column" unique: Boolean } +"Table created successfully" type CreateTableResponse { - "name of created table" + "Name of created table" created: String! } +"Data used when adding or updating a column" input AddUpdateColumnData { + "Column name" colName: String + "Column data type" type: String } input DeleteColumnData { + "Deleted column name" colName: String } +"Generic operation success response" type SuccessResponse { success: Boolean! } +"The `Any` scalar type represent any value/data-type" scalar Any diff --git a/internal/graph/schema.resolvers.go b/internal/graph/schema.resolvers.go index 48cb4e3..eb2c3f8 100644 --- a/internal/graph/schema.resolvers.go +++ b/internal/graph/schema.resolvers.go @@ -23,7 +23,7 @@ func (r *mutationResolver) CreateDatabase(ctx context.Context, name string) (*mo } // CreateTable is the resolver for the createTable field. -func (r *mutationResolver) CreateTable(ctx context.Context, name string, data []*model.CreateTableData) (*model.CreateTableResponse, error) { +func (r *mutationResolver) CreateTable(ctx context.Context, name string, data []*model.CreateColumnData) (*model.CreateTableResponse, error) { convertedData := []models.CreateTablePayload{} for _, props := range data { convertedData = append(convertedData, models.CreateTablePayload{ @@ -113,18 +113,18 @@ func (r *queryResolver) Tables(ctx context.Context) ([]*string, error) { } // Table is the resolver for the table field. -func (r *queryResolver) Table(ctx context.Context, name *string) ([]*model.TableInfo, error) { +func (r *queryResolver) Table(ctx context.Context, name *string) ([]*model.ColumnInfo, error) { result, err := r.Storage.GetTable(*name) if err != nil { return nil, err } - var tableInfo []*model.TableInfo + var tableInfo []*model.ColumnInfo for _, info := range result { name := info.Name dataType := info.Type nullable := info.Nullable key := info.Key - mod := &model.TableInfo{ + mod := &model.ColumnInfo{ Name: &name, Type: &dataType, Nullable: &nullable,