github.com/kyma-incubator/compass/components/director@v0.0.0-20230623144113-d764f56ff805/pkg/graphql/graphqlizer/graphqlizer.go (about)

     1  package graphqlizer
     2  
     3  import (
     4  	"bytes"
     5  	"encoding/json"
     6  	"reflect"
     7  	"strconv"
     8  	"text/template"
     9  
    10  	"github.com/Masterminds/sprig/v3"
    11  	"github.com/kyma-incubator/compass/components/director/pkg/graphql"
    12  	"github.com/pkg/errors"
    13  )
    14  
    15  // Graphqlizer is responsible for converting Go objects to input arguments in graphql format
    16  type Graphqlizer struct{}
    17  
    18  // ApplicationRegisterInputToGQL missing godoc
    19  func (g *Graphqlizer) ApplicationRegisterInputToGQL(in graphql.ApplicationRegisterInput) (string, error) {
    20  	return g.genericToGQL(in, `{
    21  		name: "{{.Name}}",
    22  		{{- if .ProviderName }}
    23  		providerName: "{{ .ProviderName }}",
    24  		{{- end }}
    25  		{{- if .Description }}
    26  		description: "{{ .Description }}",
    27  		{{- end }}
    28  		{{- if .LocalTenantID }}
    29  		localTenantID: "{{ .LocalTenantID }}",
    30  		{{- end }}
    31          {{- if .Labels }}
    32  		labels: {{ LabelsToGQL .Labels}},
    33  		{{- end }}
    34  		{{- if .Webhooks }}
    35  		webhooks: [
    36  			{{- range $i, $e := .Webhooks }}
    37  				{{- if $i}}, {{- end}} {{ WebhookInputToGQL $e }}
    38  			{{- end }} ],
    39  		{{- end}}
    40  		{{- if .HealthCheckURL }}
    41  		healthCheckURL: "{{ .HealthCheckURL }}",
    42  		{{- end }}
    43  		{{- if .Bundles }}
    44  		bundles: [
    45  			{{- range $i, $e := .Bundles }}
    46  				{{- if $i}}, {{- end}} {{- BundleCreateInputToGQL $e }}
    47  			{{- end }} ],
    48  		{{- end }}
    49  		{{- if .IntegrationSystemID }}
    50  		integrationSystemID: "{{ .IntegrationSystemID }}",
    51  		{{- end }}
    52  		{{- if .StatusCondition }}
    53  		statusCondition: {{ .StatusCondition }},
    54  		{{- end }}
    55  		{{- if .BaseURL }}
    56  		baseUrl: "{{ .BaseURL }}"
    57  		{{- end }}
    58  		{{- if .ApplicationNamespace }}
    59  		applicationNamespace: "{{ .ApplicationNamespace }}"
    60  		{{- end }}
    61  	}`)
    62  }
    63  
    64  // ApplicationJSONInputToGQL missing godoc
    65  func (g *Graphqlizer) ApplicationJSONInputToGQL(in graphql.ApplicationJSONInput) (string, error) {
    66  	return g.genericToGQL(in, `{
    67  		name: "{{.Name}}",
    68  		{{- if .ProviderName }}
    69  		providerName: "{{ .ProviderName }}",
    70  		{{- end }}
    71  		{{- if .Description }}
    72  		description: "{{ .Description }}",
    73  		{{- end }}
    74  		{{- if .LocalTenantID }}
    75  		localTenantID: "{{ .LocalTenantID }}",
    76  		{{- end }}
    77          {{- if .Labels }}
    78  		labels: {{ LabelsToGQL .Labels}},
    79  		{{- end }}
    80  		{{- if .Webhooks }}
    81  		webhooks: [
    82  			{{- range $i, $e := .Webhooks }}
    83  				{{- if $i}}, {{- end}} {{ WebhookInputToGQL $e }}
    84  			{{- end }} ],
    85  		{{- end}}
    86  		{{- if .HealthCheckURL }}
    87  		healthCheckURL: "{{ .HealthCheckURL }}",
    88  		{{- end }}
    89  		{{- if .Bundles }}
    90  		bundles: [
    91  			{{- range $i, $e := .Bundles }}
    92  				{{- if $i}}, {{- end}} {{- BundleCreateInputToGQL $e }}
    93  			{{- end }} ],
    94  		{{- end }}
    95  		{{- if .IntegrationSystemID }}
    96  		integrationSystemID: "{{ .IntegrationSystemID }}",
    97  		{{- end }}
    98  		{{- if .StatusCondition }}
    99  		statusCondition: {{ .StatusCondition }},
   100  		{{- end }}
   101  		{{- if .BaseURL }}
   102  		baseUrl: "{{ .BaseURL }}"
   103  		{{- end }}
   104  		{{- if .ApplicationNamespace }}
   105  		applicationNamespace: "{{ .ApplicationNamespace }}"
   106  		{{- end }}
   107  	}`)
   108  }
   109  
   110  // ApplicationUpdateInputToGQL missing godoc
   111  func (g *Graphqlizer) ApplicationUpdateInputToGQL(in graphql.ApplicationUpdateInput) (string, error) {
   112  	return g.genericToGQL(in, `{
   113  		{{- if .ProviderName }}
   114  		providerName: "{{ .ProviderName }}",
   115  		{{- end }}
   116  		{{- if .Description }}
   117  		description: "{{.Description}}",
   118  		{{- end }}
   119  		{{- if .LocalTenantID }}
   120  		localTenantID: "{{ .LocalTenantID }}",
   121  		{{- end }}
   122  		{{- if .HealthCheckURL }}
   123  		healthCheckURL: "{{ .HealthCheckURL }}",
   124  		{{- end }}
   125  		{{- if .BaseURL }}
   126  		baseUrl: "{{ .BaseURL }}",
   127  		{{- end }}
   128  		{{- if .IntegrationSystemID }}
   129  		integrationSystemID: "{{ .IntegrationSystemID }}",
   130  		{{- end }}
   131  		{{- if .StatusCondition }}
   132  		statusCondition: {{ .StatusCondition }}
   133  		{{- end }}
   134  		{{- if .ApplicationNamespace }}
   135  		applicationNamespace: "{{ .ApplicationNamespace }}"
   136  		{{- end }}
   137  	}`)
   138  }
   139  
   140  // ApplicationTemplateInputToGQL missing godoc
   141  func (g *Graphqlizer) ApplicationTemplateInputToGQL(in graphql.ApplicationTemplateInput) (string, error) {
   142  	return g.genericToGQL(in, `{
   143  		name: "{{.Name}}",
   144  		{{- if .Description }}
   145  		description: "{{.Description}}",
   146  		{{- end }}
   147  		{{- if .ApplicationNamespace }}
   148  		applicationNamespace: "{{.ApplicationNamespace}}",
   149  		{{- end }}
   150  		applicationInput: {{ ApplicationJSONInputToGQL .ApplicationInput}},
   151  		{{- if .Placeholders }}
   152  		placeholders: [
   153  			{{- range $i, $e := .Placeholders }}
   154  				{{- if $i}}, {{- end}} {{ PlaceholderDefinitionInputToGQL $e }}
   155  			{{- end }} ],
   156  		{{- end }}
   157  		accessLevel: {{.AccessLevel}},
   158  		{{- if .Labels }}
   159  		labels: {{ LabelsToGQL .Labels}},
   160  		{{- end }}
   161  		{{- if .Webhooks }}
   162  		webhooks: [
   163  			{{- range $i, $e := .Webhooks }}
   164  				{{- if $i}}, {{- end}} {{ WebhookInputToGQL $e }}
   165  			{{- end }} ],
   166  		{{- end}}
   167  	}`)
   168  }
   169  
   170  // ApplicationTemplateUpdateInputToGQL missing godoc
   171  func (g *Graphqlizer) ApplicationTemplateUpdateInputToGQL(in graphql.ApplicationTemplateUpdateInput) (string, error) {
   172  	return g.genericToGQL(in, `{
   173  		name: "{{.Name}}",
   174  		{{- if .Description }}
   175  		description: "{{.Description}}",
   176  		{{- end }}
   177  		{{- if .ApplicationNamespace }}
   178  		applicationNamespace: "{{.ApplicationNamespace}}",
   179  		{{- end }}
   180  		applicationInput: {{ ApplicationJSONInputToGQL .ApplicationInput}},
   181  		{{- if .Placeholders }}
   182  		placeholders: [
   183  			{{- range $i, $e := .Placeholders }}
   184  				{{- if $i}}, {{- end}} {{ PlaceholderDefinitionInputToGQL $e }}
   185  			{{- end }} ],
   186  		{{- end }}
   187  		accessLevel: {{.AccessLevel}},
   188  		{{- if .Labels }}
   189  		labels: {{ LabelsToGQL .Labels}},
   190  		{{- end }}
   191  		{{- if .Webhooks }}
   192  		webhooks: [
   193  			{{- range $i, $e := .Webhooks }}
   194  				{{- if $i}}, {{- end}} {{ WebhookInputToGQL $e }}
   195  			{{- end }} ],
   196  		{{- end}}
   197  	}`)
   198  }
   199  
   200  // DocumentInputToGQL missing godoc
   201  func (g *Graphqlizer) DocumentInputToGQL(in *graphql.DocumentInput) (string, error) {
   202  	return g.genericToGQL(in, `{
   203  		title: "{{.Title}}",
   204  		displayName: "{{.DisplayName}}",
   205  		description: "{{.Description}}",
   206  		format: {{.Format}},
   207  		{{- if .Kind }}
   208  		kind: "{{.Kind}}",
   209  		{{- end}}
   210  		{{- if .Data }}
   211  		data: "{{.Data}}",
   212  		{{- end}}
   213  		{{- if .FetchRequest }}
   214  		fetchRequest: {{- FetchRequesstInputToGQL .FetchRequest }},
   215  		{{- end}}
   216  }`)
   217  }
   218  
   219  // FetchRequestInputToGQL missing godoc
   220  func (g *Graphqlizer) FetchRequestInputToGQL(in *graphql.FetchRequestInput) (string, error) {
   221  	return g.genericToGQL(in, `{
   222  		url: "{{.URL}}",
   223  		{{- if .Auth }}
   224  		auth: {{- AuthInputToGQL .Auth }},
   225  		{{- end }}
   226  		{{- if .Mode }}
   227  		mode: {{.Mode}},
   228  		{{- end}}
   229  		{{- if .Filter}}
   230  		filter: "{{.Filter}}",
   231  		{{- end}}
   232  	}`)
   233  }
   234  
   235  // CredentialRequestAuthInputToGQL missing godoc
   236  func (g *Graphqlizer) CredentialRequestAuthInputToGQL(in *graphql.CredentialRequestAuthInput) (string, error) {
   237  	return g.genericToGQL(in, `{
   238  		{{- if .Csrf }}
   239  		csrf: {{ CSRFTokenCredentialRequestAuthInputToGQL .Csrf }},
   240  		{{- end }}
   241  	}`)
   242  }
   243  
   244  // CredentialDataInputToGQL missing godoc
   245  func (g *Graphqlizer) CredentialDataInputToGQL(in *graphql.CredentialDataInput) (string, error) {
   246  	return g.genericToGQL(in, ` {
   247  			{{- if .Basic }}
   248  			basic: {
   249  				username: "{{ .Basic.Username }}",
   250  				password: "{{ .Basic.Password }}",
   251  			},
   252  			{{- end }}
   253  			{{- if .Oauth }}
   254  			oauth: {
   255  				clientId: "{{ .Oauth.ClientID }}",
   256  				clientSecret: "{{ .Oauth.ClientSecret }}",
   257  				url: "{{ .Oauth.URL }}",
   258  			},
   259  			{{- end }}
   260  			{{- if .CertificateOAuth }}
   261  			certificateOAuth: {
   262  				clientId: "{{ .CertificateOAuth.ClientID }}",
   263  				certificate: "{{ .CertificateOAuth.Certificate }}",
   264  				url: "{{ .CertificateOAuth.URL }}",
   265  			},
   266  			{{- end }}
   267  	}`)
   268  }
   269  
   270  // OneTimeTokenInputToGQL missing godoc
   271  func (g *Graphqlizer) OneTimeTokenInputToGQL(in *graphql.OneTimeTokenInput) (string, error) {
   272  	return g.genericToGQL(in, ` {
   273  			token: "{{ .Token }}",
   274  			{{- if .ConnectorURL }}
   275  			connectorURL: {{ .ConnectorURL }},
   276  			{{- end }}
   277  			used: "{{ .Used }}"
   278  			expiresAt: "{{ .ExpiresAt }}",
   279  			createdAt: "{{ .CreatedAt }}",
   280  			usedAt: "{{ .UsedAt }}",
   281  			{{- if .Raw }}
   282  			raw: "{{ .Raw }}",
   283  			{{- end }}
   284  			{{- if .RawEncoded }}
   285  			rawEncoded: "{{ .RawEncoded }}",
   286  			{{- end }}
   287  			{{- if .Type }}
   288  			type: {{ .Type }},
   289  			{{- end }}
   290  	}`)
   291  }
   292  
   293  // CSRFTokenCredentialRequestAuthInputToGQL missing godoc
   294  func (g *Graphqlizer) CSRFTokenCredentialRequestAuthInputToGQL(in *graphql.CSRFTokenCredentialRequestAuthInput) (string, error) {
   295  	in.AdditionalHeadersSerialized = quoteHTTPHeadersSerialized(in.AdditionalHeadersSerialized)
   296  	in.AdditionalQueryParamsSerialized = quoteQueryParamsSerialized(in.AdditionalQueryParamsSerialized)
   297  
   298  	return g.genericToGQL(in, `{
   299  			tokenEndpointURL: "{{ .TokenEndpointURL }}",
   300  			{{- if .Credential }}
   301  			credential: {{ CredentialDataInputToGQL .Credential }},
   302  			{{- end }}
   303  			{{- if .AdditionalHeaders }}
   304  			additionalHeaders: {{ HTTPHeadersToGQL .AdditionalHeaders }},
   305  			{{- end }}
   306  			{{- if .AdditionalHeadersSerialized }}
   307  			additionalHeadersSerialized: {{ .AdditionalHeadersSerialized }},
   308  			{{- end }}
   309  			{{- if .AdditionalQueryParams }}
   310  			additionalQueryParams: {{ QueryParamsToGQL .AdditionalQueryParams }},
   311  			{{- end }}
   312  			{{- if .AdditionalQueryParamsSerialized }}
   313  			additionalQueryParamsSerialized: {{ .AdditionalQueryParamsSerialized }},
   314  			{{- end }}
   315  	}`)
   316  }
   317  
   318  // AuthInputToGQL missing godoc
   319  func (g *Graphqlizer) AuthInputToGQL(in *graphql.AuthInput) (string, error) {
   320  	in.AdditionalHeadersSerialized = quoteHTTPHeadersSerialized(in.AdditionalHeadersSerialized)
   321  	in.AdditionalQueryParamsSerialized = quoteQueryParamsSerialized(in.AdditionalQueryParamsSerialized)
   322  
   323  	return g.genericToGQL(in, `{
   324  		{{- if .Credential }}
   325  		credential: {{ CredentialDataInputToGQL .Credential }},
   326  		{{- end }}
   327  		{{- if .AccessStrategy }}
   328  		accessStrategy: "{{ .AccessStrategy }}",
   329  		{{- end }}
   330  		{{- if .AdditionalHeaders }}
   331  		additionalHeaders: {{ HTTPHeadersToGQL .AdditionalHeaders }},
   332  		{{- end }}
   333  		{{- if .AdditionalHeadersSerialized }}
   334  		additionalHeadersSerialized: {{ .AdditionalHeadersSerialized }},
   335  		{{- end }}
   336  		{{- if .AdditionalQueryParams }}
   337  		additionalQueryParams: {{ QueryParamsToGQL .AdditionalQueryParams}},
   338  		{{- end }}
   339  		{{- if .AdditionalQueryParamsSerialized }}
   340  		additionalQueryParamsSerialized: {{ .AdditionalQueryParamsSerialized }},
   341  		{{- end }}
   342  		{{- if .RequestAuth }}
   343  		requestAuth: {{ CredentialRequestAuthInputToGQL .RequestAuth }},
   344  		{{- end }}
   345  		{{- if .CertCommonName }}
   346  		requestAuth: {{ .CertCommonName }},
   347  		{{- end }}
   348  		{{- if .OneTimeToken }}
   349  		oneTimeToken: {{ OneTimeTokenInputToGQL .OneTimeToken }}
   350  		{{- end }}
   351  	}`)
   352  }
   353  
   354  // LabelsToGQL missing godoc
   355  func (g *Graphqlizer) LabelsToGQL(in graphql.Labels) (string, error) {
   356  	return g.marshal(in), nil
   357  }
   358  
   359  // HTTPHeadersToGQL missing godoc
   360  func (g *Graphqlizer) HTTPHeadersToGQL(in graphql.HTTPHeaders) (string, error) {
   361  	return g.genericToGQL(in, `{
   362  		{{- range $k,$v := . }}
   363  			{{$k}}: [
   364  				{{- range $i,$j := $v }}
   365  					{{- if $i}},{{- end}}"{{$j}}"
   366  				{{- end }} ],
   367  		{{- end}}
   368  	}`)
   369  }
   370  
   371  // QueryParamsToGQL missing godoc
   372  func (g *Graphqlizer) QueryParamsToGQL(in graphql.QueryParams) (string, error) {
   373  	return g.genericToGQL(in, `{
   374  		{{- range $k,$v := . }}
   375  			{{$k}}: [
   376  				{{- range $i,$j := $v }}
   377  					{{- if $i}},{{- end}}"{{$j}}"
   378  				{{- end }} ],
   379  		{{- end}}
   380  	}`)
   381  }
   382  
   383  // WebhookInputToGQL missing godoc
   384  func (g *Graphqlizer) WebhookInputToGQL(in *graphql.WebhookInput) (string, error) {
   385  	return g.genericToGQL(in, `{
   386  		type: {{.Type}},
   387  		{{- if .URL }}
   388  		url: "{{.URL }}",
   389  		{{- end }}
   390  		{{- if .Auth }}
   391  		auth: {{- AuthInputToGQL .Auth }},
   392  		{{- end }}
   393  		{{- if .Mode }}
   394  		mode: {{.Mode }},
   395  		{{- end }}
   396  		{{- if .Version }}
   397  		version: "{{.Version}}",
   398  		{{- end }}
   399  		{{- if .CorrelationIDKey }}
   400  		correlationIdKey: "{{.CorrelationIDKey }}",
   401  		{{- end }}
   402  		{{- if .RetryInterval }}
   403  		retryInterval: {{.RetryInterval }},
   404  		{{- end }}
   405  		{{- if .Timeout }}
   406  		timeout: {{.Timeout }},
   407  		{{- end }}
   408  		{{- if .URLTemplate }}
   409  		urlTemplate: "{{.URLTemplate }}",
   410  		{{- end }}
   411  		{{- if .InputTemplate }}
   412  		inputTemplate: "{{.InputTemplate }}",
   413  		{{- end }}
   414  		{{- if .HeaderTemplate }}
   415  		headerTemplate: "{{.HeaderTemplate }}",
   416  		{{- end }}
   417  		{{- if .OutputTemplate }}
   418  		outputTemplate: "{{.OutputTemplate }}",
   419  		{{- end }}
   420  		{{- if .StatusTemplate }}
   421  		statusTemplate: "{{.StatusTemplate }}",
   422  		{{- end }}
   423  	}`)
   424  }
   425  
   426  // APIDefinitionInputToGQL missing godoc
   427  func (g *Graphqlizer) APIDefinitionInputToGQL(in graphql.APIDefinitionInput) (string, error) {
   428  	return g.genericToGQL(in, `{
   429  		name: "{{ .Name}}",
   430  		{{- if .Description }}
   431  		description: "{{.Description}}",
   432  		{{- end}}
   433  		targetURL: "{{.TargetURL}}",
   434  		{{- if .Group }}
   435  		group: "{{.Group}}",
   436  		{{- end }}
   437  		{{- if .Spec }}
   438  		spec: {{- APISpecInputToGQL .Spec }},
   439  		{{- end }}
   440  		{{- if .Version }}
   441  		version: {{- VersionInputToGQL .Version }},
   442  		{{- end}}
   443  	}`)
   444  }
   445  
   446  // EventDefinitionInputToGQL missing godoc
   447  func (g *Graphqlizer) EventDefinitionInputToGQL(in graphql.EventDefinitionInput) (string, error) {
   448  	return g.genericToGQL(in, `{
   449  		name: "{{.Name}}",
   450  		{{- if .Description }}
   451  		description: "{{.Description}}",
   452  		{{- end }}
   453  		{{- if .Spec }}
   454  		spec: {{ EventAPISpecInputToGQL .Spec }},
   455  		{{- end }}
   456  		{{- if .Group }}
   457  		group: "{{.Group}}",
   458  		{{- end }}
   459  		{{- if .Version }}
   460  		version: {{- VersionInputToGQL .Version }},
   461  		{{- end}}
   462  	}`)
   463  }
   464  
   465  // EventAPISpecInputToGQL missing godoc
   466  func (g *Graphqlizer) EventAPISpecInputToGQL(in graphql.EventSpecInput) (string, error) {
   467  	in.Data = quoteCLOB(in.Data)
   468  	return g.genericToGQL(in, `{
   469  		{{- if .Data }}
   470  		data: {{.Data}},
   471  		{{- end }}
   472  		type: {{.Type}},
   473  		{{- if .FetchRequest }}
   474  		fetchRequest: {{- FetchRequesstInputToGQL .FetchRequest }},
   475  		{{- end }}
   476  		format: {{.Format}},
   477  	}`)
   478  }
   479  
   480  // APISpecInputToGQL missing godoc
   481  func (g *Graphqlizer) APISpecInputToGQL(in graphql.APISpecInput) (string, error) {
   482  	in.Data = quoteCLOB(in.Data)
   483  	return g.genericToGQL(in, `{
   484  		{{- if .Data}}
   485  		data: {{.Data}},
   486  		{{- end}}
   487  		type: {{.Type}},
   488  		format: {{.Format}},
   489  		{{- if .FetchRequest }}
   490  		fetchRequest: {{- FetchRequesstInputToGQL .FetchRequest }},
   491  		{{- end }}
   492  	}`)
   493  }
   494  
   495  // VersionInputToGQL missing godoc
   496  func (g *Graphqlizer) VersionInputToGQL(in graphql.VersionInput) (string, error) {
   497  	return g.genericToGQL(in, `{
   498  		value: "{{.Value}}",
   499  		{{- if .Deprecated }}
   500  		deprecated: {{.Deprecated}},
   501  		{{- end}}
   502  		{{- if .DeprecatedSince }}
   503  		deprecatedSince: "{{.DeprecatedSince}}",
   504  		{{- end}}
   505  		{{- if .ForRemoval }}
   506  		forRemoval: {{.ForRemoval }},
   507  		{{- end }}
   508  	}`)
   509  }
   510  
   511  // RuntimeRegisterInputToGQL missing godoc
   512  func (g *Graphqlizer) RuntimeRegisterInputToGQL(in graphql.RuntimeRegisterInput) (string, error) {
   513  	return g.genericToGQL(in, `{
   514  		name: "{{.Name}}",
   515  		{{- if .Description }}
   516  		description: "{{.Description}}",
   517  		{{- end }}
   518  		{{- if .Labels }}
   519  		labels: {{ LabelsToGQL .Labels}},
   520  		{{- end }}
   521  		{{- if .Webhooks }}
   522  		webhooks: [
   523  			{{- range $i, $e := .Webhooks }}
   524  				{{- if $i}}, {{- end}} {{ WebhookInputToGQL $e }}
   525  			{{- end }} ],
   526  		{{- end}}
   527  		{{- if .StatusCondition }}
   528  		statusCondition: {{ .StatusCondition }},
   529  		{{- end }}
   530  		{{- if .ApplicationNamespace }}
   531  		applicationNamespace: "{{.ApplicationNamespace}}",
   532  		{{- end }}
   533  	}`)
   534  }
   535  
   536  // RuntimeUpdateInputToGQL missing godoc
   537  func (g *Graphqlizer) RuntimeUpdateInputToGQL(in graphql.RuntimeUpdateInput) (string, error) {
   538  	return g.genericToGQL(in, `{
   539  		name: "{{.Name}}",
   540  		{{- if .Description }}
   541  		description: "{{.Description}}",
   542  		{{- end }}
   543  		{{- if .Labels }}
   544  		labels: {{ LabelsToGQL .Labels}},
   545  		{{- end }}
   546  		{{- if .StatusCondition }}
   547  		statusCondition: {{ .StatusCondition }},
   548  		{{- end }}
   549  		{{- if .ApplicationNamespace }}
   550  		applicationNamespace: "{{.ApplicationNamespace}}",
   551  		{{- end }}
   552  	}`)
   553  }
   554  
   555  // RuntimeContextInputToGQL missing godoc
   556  func (g *Graphqlizer) RuntimeContextInputToGQL(in graphql.RuntimeContextInput) (string, error) {
   557  	return g.genericToGQL(in, `{
   558  		key: "{{.Key}}",
   559  		value: "{{.Value}}",
   560  	}`)
   561  }
   562  
   563  // LabelDefinitionInputToGQL missing godoc
   564  func (g *Graphqlizer) LabelDefinitionInputToGQL(in graphql.LabelDefinitionInput) (string, error) {
   565  	return g.genericToGQL(in, `{
   566  		key: "{{.Key}}",
   567  		{{- if .Schema }}
   568  		schema: {{.Schema}},
   569  		{{- end }}
   570  	}`)
   571  }
   572  
   573  // LabelFilterToGQL missing godoc
   574  func (g *Graphqlizer) LabelFilterToGQL(in graphql.LabelFilter) (string, error) {
   575  	return g.genericToGQL(in, `{
   576  		key: "{{.Key}}",
   577  		{{- if .Query }}
   578  		query: "{{- js .Query -}}",
   579  		{{- end }}
   580  	}`)
   581  }
   582  
   583  // IntegrationSystemInputToGQL missing godoc
   584  func (g *Graphqlizer) IntegrationSystemInputToGQL(in graphql.IntegrationSystemInput) (string, error) {
   585  	return g.genericToGQL(in, `{
   586  		name: "{{.Name}}",
   587  		{{- if .Description }}
   588  		description: "{{.Description}}",
   589  		{{- end }}
   590  	}`)
   591  }
   592  
   593  // PlaceholderDefinitionInputToGQL missing godoc
   594  func (g *Graphqlizer) PlaceholderDefinitionInputToGQL(in graphql.PlaceholderDefinitionInput) (string, error) {
   595  	return g.genericToGQL(in, `{
   596  		name: "{{.Name}}",
   597  		{{- if .Description }}
   598  		description: "{{.Description}}",
   599  		{{- end }}
   600  		{{- if .JSONPath }}
   601  		jsonPath: "{{.JSONPath}}",
   602  		{{- end }}
   603  	}`)
   604  }
   605  
   606  // TemplateValueInputToGQL missing godoc
   607  func (g *Graphqlizer) TemplateValueInputToGQL(in graphql.TemplateValueInput) (string, error) {
   608  	return g.genericToGQL(in, `{
   609  		placeholder: "{{.Placeholder}}"
   610  		value: "{{.Value}}"
   611  	}`)
   612  }
   613  
   614  // FormationInputToGQL converts go formation input structure into graphql format
   615  func (g *Graphqlizer) FormationInputToGQL(in graphql.FormationInput) (string, error) {
   616  	return g.genericToGQL(in, `{
   617  		name: "{{.Name}}",
   618  		templateName: "{{.TemplateName}}"
   619  	}`)
   620  }
   621  
   622  // FormationTemplateInputToGQL missing godoc
   623  func (g *Graphqlizer) FormationTemplateInputToGQL(in graphql.FormationTemplateInput) (string, error) {
   624  	return g.genericToGQL(in, `{
   625  		name: "{{.Name}}"
   626  		applicationTypes: [
   627  			{{- range $i, $e := .ApplicationTypes}}
   628  				{{- if $i}}, {{- end}} {{ marshal $e }}
   629  			{{- end }} ],
   630  		runtimeTypes:  [
   631  			{{- range $i, $e := .RuntimeTypes}}
   632  				{{- if $i}}, {{- end}} {{ marshal $e }}
   633  			{{- end }} ],
   634          {{- if .RuntimeTypeDisplayName }}
   635  		runtimeTypeDisplayName: "{{.RuntimeTypeDisplayName}}"
   636  		{{- end }}
   637          {{- if .RuntimeArtifactKind }}
   638  		runtimeArtifactKind: {{.RuntimeArtifactKind}}
   639  		{{- end }}
   640  		{{- if .LeadingProductIDs }} 
   641  		leadingProductIDs: [
   642  			{{- range $i, $e := .LeadingProductIDs }}
   643  				{{- if $i}}, {{- end}} {{ marshal $e }}
   644  			{{- end }} ],
   645  		{{- end}}
   646  		{{- if .Webhooks }}
   647  		webhooks: [
   648  			{{- range $i, $e := .Webhooks }}
   649  				{{- if $i}}, {{- end}} {{ WebhookInputToGQL $e }}
   650  			{{- end }} ],
   651  		{{- end}}
   652  	}`)
   653  }
   654  
   655  // FormationConstraintInputToGQL missing godoc
   656  func (g *Graphqlizer) FormationConstraintInputToGQL(in graphql.FormationConstraintInput) (string, error) {
   657  	return g.genericToGQL(in, `{
   658  		name: "{{.Name}}"
   659  		constraintType: {{.ConstraintType}}
   660  		targetOperation: {{.TargetOperation}}
   661  		operator: "{{.Operator}}"
   662  		resourceType: {{.ResourceType}}
   663  		resourceSubtype: "{{.ResourceSubtype}}"
   664  		inputTemplate: "{{.InputTemplate}}"
   665  		constraintScope: {{.ConstraintScope}}
   666  	}`)
   667  }
   668  
   669  // FormationConstraintUpdateInputToGQL creates formation constraint update input
   670  func (g *Graphqlizer) FormationConstraintUpdateInputToGQL(in graphql.FormationConstraintUpdateInput) (string, error) {
   671  	return g.genericToGQL(in, `{
   672  		inputTemplate: "{{.InputTemplate}}"
   673  	}`)
   674  }
   675  
   676  // FormationTemplateConstraintReferenceToGQL missing godoc
   677  func (g *Graphqlizer) FormationTemplateConstraintReferenceToGQL(in graphql.ConstraintReference) (string, error) {
   678  	return g.genericToGQL(in, `{
   679  		constraintId: "{{.ConstraintID}}"
   680  		formationTemplateId: {{.formationTemplateID}}
   681  	}`)
   682  }
   683  
   684  // ApplicationFromTemplateInputToGQL missing godoc
   685  func (g *Graphqlizer) ApplicationFromTemplateInputToGQL(in graphql.ApplicationFromTemplateInput) (string, error) {
   686  	return g.genericToGQL(in, `{
   687  		templateName: "{{.TemplateName}}"
   688  		{{- if .Values }}
   689  		values: [
   690  			{{- range $i, $e := .Values }}
   691  				{{- if $i}}, {{- end}} {{ TemplateValueInput $e }}
   692  			{{- end }} ],
   693  		{{- end }}
   694  		{{- if .PlaceholdersPayload }}
   695  		placeholdersPayload:  "{{.PlaceholdersPayload}}"
   696  		{{- end }}
   697  	}`)
   698  }
   699  
   700  // ApplicationFromTemplateInputWithTemplateIDToGQL missing godoc
   701  func (g *Graphqlizer) ApplicationFromTemplateInputWithTemplateIDToGQL(in graphql.ApplicationFromTemplateInput) (string, error) {
   702  	return g.genericToGQL(in, `{
   703  		{{- if .ID }}
   704  		id: "{{ .ID }}"
   705  		{{- end }}
   706  		templateName: "{{.TemplateName}}"
   707  		{{- if .Values }}
   708  		values: [
   709  			{{- range $i, $e := .Values }}
   710  				{{- if $i}}, {{- end}} {{ TemplateValueInput $e }}
   711  			{{- end }} ],
   712  		{{- end }}
   713  		{{- if .PlaceholdersPayload }}
   714  		placeholdersPayload:  "{{.PlaceholdersPayload}}"
   715  		{{- end }}
   716  	}`)
   717  }
   718  
   719  // BundleCreateInputToGQL missing godoc
   720  func (g *Graphqlizer) BundleCreateInputToGQL(in graphql.BundleCreateInput) (string, error) {
   721  	return g.genericToGQL(in, `{
   722  		name: "{{ .Name }}"
   723  		{{- if .Description }}
   724  		description: "{{ .Description }}"
   725  		{{- end }}
   726  		{{- if .InstanceAuthRequestInputSchema }}
   727  		instanceAuthRequestInputSchema: {{ .InstanceAuthRequestInputSchema }}
   728  		{{- end }}
   729  		{{- if .DefaultInstanceAuth }}
   730  		defaultInstanceAuth: {{- AuthInputToGQL .DefaultInstanceAuth }}
   731  		{{- end }}
   732  		{{- if .APIDefinitions }}
   733  		apiDefinitions: [
   734  			{{- range $i, $e := .APIDefinitions }}
   735  				{{- if $i}}, {{- end}} {{ APIDefinitionInputToGQL $e }}
   736  			{{- end }}],
   737  		{{- end }}
   738  		{{- if .EventDefinitions }}
   739  		eventDefinitions: [
   740  			{{- range $i, $e := .EventDefinitions }}
   741  				{{- if $i}}, {{- end}} {{ EventDefinitionInputToGQL $e }}
   742  			{{- end }}],
   743  		{{- end }}
   744  		{{- if .Documents }}
   745  		documents: [
   746  			{{- range $i, $e := .Documents }}
   747  				{{- if $i}}, {{- end}} {{- DocumentInputToGQL $e }}
   748  			{{- end }} ],
   749  		{{- end }}
   750  		{{- if .CorrelationIDs }}
   751  		correlationIDs: [
   752  			{{- range $i, $e := .CorrelationIDs }}
   753  				{{- if $i}}, {{- end}} "{{$e}}"
   754  			{{- end }} ]
   755  		{{- end }}
   756  	}`)
   757  }
   758  
   759  // BundleUpdateInputToGQL missing godoc
   760  func (g *Graphqlizer) BundleUpdateInputToGQL(in graphql.BundleUpdateInput) (string, error) {
   761  	return g.genericToGQL(in, `{
   762  		name: "{{ .Name }}"
   763  		{{- if .Description }}
   764  		description: "{{ .Description }}"
   765  		{{- end }}
   766  		{{- if .InstanceAuthRequestInputSchema }}
   767  		instanceAuthRequestInputSchema: {{ .InstanceAuthRequestInputSchema }}
   768  		{{- end }}
   769  		{{- if .DefaultInstanceAuth }}
   770  		defaultInstanceAuth: {{- AuthInputToGQL .DefaultInstanceAuth }}
   771  		{{- end }}
   772  	}`)
   773  }
   774  
   775  // BundleInstanceAuthStatusInputToGQL missing godoc
   776  func (g *Graphqlizer) BundleInstanceAuthStatusInputToGQL(in graphql.BundleInstanceAuthStatusInput) (string, error) {
   777  	return g.genericToGQL(in, `{
   778  		condition: {{ .Condition }}
   779  		{{- if .Message }}
   780  		message: "{{ .Message }}"
   781  		{{- end }}
   782  		{{- if .Reason }}
   783  		reason: "{{ .Reason }}"
   784  		{{- end }}
   785  	}`)
   786  }
   787  
   788  // BundleInstanceAuthRequestInputToGQL missing godoc
   789  func (g *Graphqlizer) BundleInstanceAuthRequestInputToGQL(in graphql.BundleInstanceAuthRequestInput) (string, error) {
   790  	return g.genericToGQL(in, `{
   791  		{{- if .ID }}
   792  		id: "{{ .ID }}"
   793  		{{- end }}
   794  		{{- if .Context }}
   795  		context: {{ .Context }}
   796  		{{- end }}
   797  		{{- if .InputParams }}
   798  		inputParams: {{ .InputParams }}
   799  		{{- end }}
   800  	}`)
   801  }
   802  
   803  // BundleInstanceAuthCreateInputToGQL converts graphql.BundleInstanceAuthCreateInput to input arguments in graphql format
   804  func (g *Graphqlizer) BundleInstanceAuthCreateInputToGQL(in graphql.BundleInstanceAuthCreateInput) (string, error) {
   805  	return g.genericToGQL(in, `{
   806  		{{- if .Context }}
   807  		context: {{ .Context }}
   808  		{{- end }}
   809  		{{- if .Auth }}
   810  		auth: {{- AuthInputToGQL .Auth}}
   811  		{{- end }}
   812  		{{- if .InputParams }}
   813  		inputParams: {{ .InputParams }}
   814  		{{- end }}
   815  		{{- if .RuntimeID }}
   816  		runtimeID: "{{ .RuntimeID }}"
   817  		{{- end }}
   818  		{{- if .RuntimeContextID }}
   819  		runtimeContextID: "{{ .RuntimeContextID }}"
   820  		{{- end }}
   821  	}`)
   822  }
   823  
   824  // BundleInstanceAuthUpdateInputToGQL converts graphql.BundleInstanceAuthUpdateInput to input arguments in graphql format
   825  func (g *Graphqlizer) BundleInstanceAuthUpdateInputToGQL(in graphql.BundleInstanceAuthUpdateInput) (string, error) {
   826  	return g.genericToGQL(in, `{
   827  		{{- if .Context }}
   828  		context: {{ .Context }}
   829  		{{- end }}
   830  		{{- if .Auth }}
   831  		auth: {{- AuthInputToGQL .Auth}}
   832  		{{- end }}
   833  		{{- if .InputParams }}
   834  		inputParams: {{ .InputParams }}
   835  		{{- end }}
   836  	}`)
   837  }
   838  
   839  // BundleInstanceAuthSetInputToGQL missing godoc
   840  func (g *Graphqlizer) BundleInstanceAuthSetInputToGQL(in graphql.BundleInstanceAuthSetInput) (string, error) {
   841  	return g.genericToGQL(in, `{
   842  		{{- if .Auth }}
   843  		auth: {{- AuthInputToGQL .Auth}}
   844  		{{- end }}
   845  		{{- if .Status }}
   846  		status: {{- BundleInstanceAuthStatusInputToGQL .Status }}
   847  		{{- end }}
   848  	}`)
   849  }
   850  
   851  // LabelSelectorInputToGQL missing godoc
   852  func (g *Graphqlizer) LabelSelectorInputToGQL(in graphql.LabelSelectorInput) (string, error) {
   853  	return g.genericToGQL(in, `{
   854  		key: "{{ .Key }}"
   855  		value: "{{ .Value }}"
   856  	}`)
   857  }
   858  
   859  // WriteTenantsInputToGQL creates tenant input for writeTenants mutation from multiple tenants
   860  func (g *Graphqlizer) WriteTenantsInputToGQL(in []graphql.BusinessTenantMappingInput) (string, error) {
   861  	return g.genericToGQL(in, `
   862  		{{ $n := (len .) }}
   863  		{{ range $i, $tenant := . }}
   864  			{{- if $i }}, {{- end }}
   865  			{
   866  				name: {{ quote $tenant.Name }},
   867   				externalTenant: {{ quote $tenant.ExternalTenant }},
   868  				{{- if $tenant.Parent }}
   869  				parent: {{ quote $tenant.Parent }},
   870  				{{- end }}
   871  				{{- if $tenant.Region }}
   872  				region: {{ quote $tenant.Region }},
   873  				{{- end }}
   874  				{{- if $tenant.Subdomain }}
   875  				subdomain: {{ quote $tenant.Subdomain }},
   876  				{{- end }}
   877  				{{- if $tenant.LicenseType }}
   878  				licenseType: {{ quote $tenant.LicenseType }},
   879  				{{- end }}
   880  				type: {{ quote $tenant.Type }},
   881  				provider: {{ quote $tenant.Provider }}
   882  			}
   883  		{{ end }}`)
   884  }
   885  
   886  // WriteTenantInputToGQL creates tenant input for writeTenant mutation from single tenant
   887  func (g *Graphqlizer) WriteTenantInputToGQL(in graphql.BusinessTenantMappingInput) (string, error) {
   888  	return g.genericToGQL(in, `{
   889  		name: {{ quote .Name }},
   890  		externalTenant: {{ quote .ExternalTenant }},
   891  		{{- if .Parent }}
   892  		parent: {{ quote .Parent }},
   893  		{{- end }}
   894  		{{- if .Region }}
   895  		region: {{ quote .Region }},
   896  		{{- end }}
   897  		{{- if .Subdomain }}
   898  		subdomain: {{ quote .Subdomain }},
   899  		{{- end }}
   900  		{{- if $.LicenseType }}
   901  		licenseType: {{ quote .LicenseType }},
   902  		{{- end }}
   903  		type: {{ quote .Type }},
   904  		provider: {{ quote .Provider }}
   905  	}`)
   906  }
   907  
   908  // DeleteTenantsInputToGQL creates tenant input for deleteTenants mutation from multiple external tenant ids
   909  func (g *Graphqlizer) DeleteTenantsInputToGQL(in []graphql.BusinessTenantMappingInput) (string, error) {
   910  	return g.genericToGQL(in, `
   911  		{{ $n := (len .) }}
   912  		{{ range $i, $tenant := . }}
   913  			{{- if $i }}, {{- end }}
   914  			{{ quote $tenant.ExternalTenant }}
   915  		{{ end }}`)
   916  }
   917  
   918  // UpdateTenantsInputToGQL creates tenant input for updateTenant
   919  func (g *Graphqlizer) UpdateTenantsInputToGQL(in graphql.BusinessTenantMappingInput) (string, error) {
   920  	return g.genericToGQL(in, `
   921  		{
   922  			name: {{ quote .Name }},
   923   			externalTenant: {{ quote .ExternalTenant }},
   924  			{{- if .Parent }}
   925  			parent: {{ quote .Parent }},
   926  			{{- end }}
   927  			{{- if .Region }}
   928  			region: {{ quote .Region }},
   929  			{{- end }}
   930  			{{- if .Subdomain }}
   931  			subdomain: {{ quote .Subdomain }},
   932  			{{- end }}
   933  			{{- if .LicenseType }}
   934  			licenseType: {{ quote .LicenseType }},
   935  			{{- end }}
   936  			type: {{ quote .Type }},
   937  			provider: {{ quote .Provider }}
   938  		}`)
   939  }
   940  
   941  // CertificateSubjectMappingInputToGQL creates certificate subject mapping graphql input
   942  func (g *Graphqlizer) CertificateSubjectMappingInputToGQL(in graphql.CertificateSubjectMappingInput) (string, error) {
   943  	return g.genericToGQL(in, `{
   944  		subject: "{{.Subject}}"
   945  		consumerType: "{{.ConsumerType}}"
   946          {{- if .InternalConsumerID }}
   947  		internalConsumerID: "{{.InternalConsumerID}}",
   948  		{{- end}}
   949  		tenantAccessLevels: [
   950  			{{- range $i, $e := .TenantAccessLevels}}
   951  				{{- if $i}}, {{- end}} {{ marshal $e }}
   952  			{{- end }} ],
   953  	}`)
   954  }
   955  
   956  // TenantAccessInputToGQL creates tenant access graphql input
   957  func (g *Graphqlizer) TenantAccessInputToGQL(in graphql.TenantAccessInput) (string, error) {
   958  	return g.genericToGQL(in, `{
   959  		tenantID: "{{.TenantID}}"
   960  		resourceID: "{{.ResourceID}}"
   961          resourceType: {{.ResourceType}}
   962  		owner: {{.Owner}}
   963  	}`)
   964  }
   965  
   966  func (g *Graphqlizer) marshal(obj interface{}) string {
   967  	var out string
   968  
   969  	val := reflect.ValueOf(obj)
   970  
   971  	switch val.Kind() {
   972  	case reflect.Map:
   973  		s, err := g.genericToGQL(obj, `{ {{- range $k, $v := . }}{{ $k }}:{{ marshal $v }},{{ end -}} }`)
   974  		if err != nil {
   975  			return ""
   976  		}
   977  		out = s
   978  	case reflect.Slice, reflect.Array:
   979  		s, err := g.genericToGQL(obj, `[{{ range $i, $e := . }}{{ if $i }},{{ end }}{{ marshal $e }}{{ end }}]`)
   980  		if err != nil {
   981  			return ""
   982  		}
   983  		out = s
   984  	default:
   985  		marshalled, err := json.Marshal(obj)
   986  		if err != nil {
   987  			return ""
   988  		}
   989  		out = string(marshalled)
   990  	}
   991  
   992  	return out
   993  }
   994  
   995  func (g *Graphqlizer) genericToGQL(obj interface{}, tmpl string) (string, error) {
   996  	fm := sprig.TxtFuncMap()
   997  	fm["marshal"] = g.marshal
   998  	fm["ApplicationRegisterInputToGQL"] = g.ApplicationRegisterInputToGQL
   999  	fm["ApplicationJSONInputToGQL"] = g.ApplicationJSONInputToGQL
  1000  	fm["DocumentInputToGQL"] = g.DocumentInputToGQL
  1001  	fm["FetchRequesstInputToGQL"] = g.FetchRequestInputToGQL
  1002  	fm["AuthInputToGQL"] = g.AuthInputToGQL
  1003  	fm["LabelsToGQL"] = g.LabelsToGQL
  1004  	fm["WebhookInputToGQL"] = g.WebhookInputToGQL
  1005  	fm["APIDefinitionInputToGQL"] = g.APIDefinitionInputToGQL
  1006  	fm["EventDefinitionInputToGQL"] = g.EventDefinitionInputToGQL
  1007  	fm["APISpecInputToGQL"] = g.APISpecInputToGQL
  1008  	fm["VersionInputToGQL"] = g.VersionInputToGQL
  1009  	fm["HTTPHeadersToGQL"] = g.HTTPHeadersToGQL
  1010  	fm["QueryParamsToGQL"] = g.QueryParamsToGQL
  1011  	fm["EventAPISpecInputToGQL"] = g.EventAPISpecInputToGQL
  1012  	fm["CredentialDataInputToGQL"] = g.CredentialDataInputToGQL
  1013  	fm["CSRFTokenCredentialRequestAuthInputToGQL"] = g.CSRFTokenCredentialRequestAuthInputToGQL
  1014  	fm["CredentialRequestAuthInputToGQL"] = g.CredentialRequestAuthInputToGQL
  1015  	fm["PlaceholderDefinitionInputToGQL"] = g.PlaceholderDefinitionInputToGQL
  1016  	fm["TemplateValueInput"] = g.TemplateValueInputToGQL
  1017  	fm["BundleInstanceAuthStatusInputToGQL"] = g.BundleInstanceAuthStatusInputToGQL
  1018  	fm["BundleCreateInputToGQL"] = g.BundleCreateInputToGQL
  1019  	fm["LabelSelectorInputToGQL"] = g.LabelSelectorInputToGQL
  1020  	fm["OneTimeTokenInputToGQL"] = g.OneTimeTokenInputToGQL
  1021  	fm["quote"] = strconv.Quote
  1022  
  1023  	t, err := template.New("tmpl").Funcs(fm).Parse(tmpl)
  1024  	if err != nil {
  1025  		return "", errors.Wrapf(err, "while parsing template")
  1026  	}
  1027  
  1028  	var b bytes.Buffer
  1029  
  1030  	if err := t.Execute(&b, obj); err != nil {
  1031  		return "", errors.Wrap(err, "while executing template")
  1032  	}
  1033  	return b.String(), nil
  1034  }
  1035  
  1036  func quoteCLOB(in *graphql.CLOB) *graphql.CLOB {
  1037  	if in == nil {
  1038  		return nil
  1039  	}
  1040  
  1041  	quoted := strconv.Quote(string(*in))
  1042  	return (*graphql.CLOB)(&quoted)
  1043  }
  1044  
  1045  func quoteHTTPHeadersSerialized(in *graphql.HTTPHeadersSerialized) *graphql.HTTPHeadersSerialized {
  1046  	if in == nil {
  1047  		return nil
  1048  	}
  1049  
  1050  	quoted := strconv.Quote(string(*in))
  1051  	return (*graphql.HTTPHeadersSerialized)(&quoted)
  1052  }
  1053  
  1054  func quoteQueryParamsSerialized(in *graphql.QueryParamsSerialized) *graphql.QueryParamsSerialized {
  1055  	if in == nil {
  1056  		return nil
  1057  	}
  1058  
  1059  	quoted := strconv.Quote(string(*in))
  1060  	return (*graphql.QueryParamsSerialized)(&quoted)
  1061  }