Skip to content

Commit

Permalink
feat: add support for --set-graphql
Browse files Browse the repository at this point in the history
  • Loading branch information
micovery committed Apr 15, 2024
1 parent 9d18cca commit db9547c
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions pkg/flags/setgraphql.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// Copyright 2024 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package flags

import (
"fmt"
"github.com/go-errors/errors"
"github.com/micovery/apigee-yaml-toolkit/pkg/parser"
"github.com/micovery/apigee-yaml-toolkit/pkg/values"
"strings"
)

type SetGraphQL struct {
Data *values.Map
}

func NewSetGraphQL(data *values.Map) SetGraphQL {
return SetGraphQL{Data: data}
}

func (v *SetGraphQL) String() string {
return fmt.Sprintf("%v", v.Data)
}

func (v *SetGraphQL) Set(entry string) error {
key, filePath, found := strings.Cut(entry, "=")
if !found {
return errors.Errorf("missing file path in set-graphql for key=%s", key)
}

parserResult, schemaBytes, err := parser.ParseGraphQLSchema(filePath)
if err != nil {
return err
}

schema := *parserResult
schemaFileText := string(schemaBytes)

v.Data.Set(key, schema)
v.Data.Set(fmt.Sprintf("%s_string", key), schemaFileText)

return nil
}

0 comments on commit db9547c

Please sign in to comment.