()
| 74 | } |
| 75 | |
| 76 | func (o *actionsCreateOptions) run() error { |
| 77 | var op errors.Op = "commands.actionsCreateOptions.run" |
| 78 | var introSchema hasura.IntrospectionSchema |
| 79 | var err error |
| 80 | if o.deriveFrom != "" { |
| 81 | o.deriveFrom = strings.TrimSpace(o.deriveFrom) |
| 82 | o.EC.Spin("Deriving a Hasura operation...") |
| 83 | introSchema, err = o.EC.APIClient.V1Graphql.GetIntrospectionSchema() |
| 84 | if err != nil { |
| 85 | return errors.E(op, fmt.Errorf("error in fetching introspection schema: %w", err)) |
| 86 | } |
| 87 | o.EC.Spinner.Stop() |
| 88 | } |
| 89 | |
| 90 | // create new action |
| 91 | o.EC.Spin("Creating the action...") |
| 92 | actionCfg := actions.New(o.EC, o.EC.MetadataDir) |
| 93 | o.EC.Spinner.Stop() |
| 94 | err = actionCfg.Create(o.name, introSchema, o.deriveFrom) |
| 95 | if err != nil { |
| 96 | return errors.E(op, fmt.Errorf("error in creating action: %w", err)) |
| 97 | } |
| 98 | opts := &MetadataApplyOptions{ |
| 99 | EC: o.EC, |
| 100 | } |
| 101 | err = opts.Run() |
| 102 | if err != nil { |
| 103 | return errors.E(op, fmt.Errorf("error in applying metadata: %w", err)) |
| 104 | } |
| 105 | o.EC.Logger.WithField("name", o.name).Infoln("action created") |
| 106 | |
| 107 | // if codegen config not present, skip codegen |
| 108 | if o.EC.Config.ActionConfig.Codegen.Framework == "" { |
| 109 | if o.withCodegen { |
| 110 | return errors.E(op, fmt.Errorf(`could not find codegen config. For adding codegen config, run: |
| 111 | |
| 112 | hasura actions use-codegen`)) |
| 113 | } |
| 114 | return nil |
| 115 | } |
| 116 | |
| 117 | // if with-codegen flag not present, ask them if they want to codegen |
| 118 | var confirmation bool |
| 119 | if !o.withCodegen { |
| 120 | confirmation, err = util.GetYesNoPrompt("Do you want to generate " + o.EC.Config.ActionConfig.Codegen.Framework + " code for this action and the custom types?") |
| 121 | if err != nil { |
| 122 | return errors.E(op, fmt.Errorf("error in getting user input: %w", err)) |
| 123 | } |
| 124 | } |
| 125 | |
| 126 | if !confirmation { |
| 127 | infoMsg := fmt.Sprintf(`You skipped codegen. For getting codegen for this action, run: |
| 128 | |
| 129 | hasura actions codegen %s |
| 130 | `, o.name) |
| 131 | o.EC.Logger.Info(infoMsg) |
| 132 | return nil |
| 133 | } |
no test coverage detected