Skip to content

Commit

Permalink
Merge 1647ebb into c7a4981
Browse files Browse the repository at this point in the history
  • Loading branch information
damour committed Jan 25, 2019
2 parents c7a4981 + 1647ebb commit f29e4c3
Show file tree
Hide file tree
Showing 17 changed files with 510 additions and 159 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,14 +135,15 @@ proto2gql:
"methodName": # method name
alias: "methodAlias"
request_type: "QUERY" # method type in GraphQL Schema (QUERY|MUTATION)
unwrap_response_field: true # In proto we can't use primitive or repeated type in method response.
# If unwrap_response_field = true unpack response gql object with 1 field.
messages: # messages settings
- "Request$": # message name match regex
unwrap_field: true # unpack input message field. Useful for google.protobuf.wrappers.
fields:
"ip_address":
context_key: "ip" # context key, where unmarshaller will get this field from
- "Response$":
unwrap_field: true # In proto we can't use primitive or repeated type in method response.
# If unwrap_field = true unpack response gql object with 1 field.
error_field: "Error" # name of payload error field
- ...
- ...
Expand Down
2 changes: 1 addition & 1 deletion generator/plugins/dataloader/templates.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions generator/plugins/graphql/templates.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion generator/plugins/graphql/templates/types_body.gohtml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func {{$resolver.FunctionName}}(ctx {{ctxPkg}}.Context, i interface{}) (_ {{goTy
if i == nil {
return nil, nil
}
args := i.(map[string]interface{})
args, _ := i.(map[string]interface{})
_ = args
var result = new({{goTypeForNew $resolver.OutputGoType}})
{{ range $field := $resolver.Fields -}}
Expand Down
8 changes: 4 additions & 4 deletions generator/plugins/proto2gql/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ type MessageConfig struct {
ErrorField string `mapstructure:"error_field"`
Fields map[string]FieldsConfig `mapstructure:"fields"`
DataLoaders []dataloader.FieldConfig `mapstructure:"data_loaders"`
UnwrapField bool `mapstructure:"unwrap_field"`
}
type MethodConfig struct {
Alias string `mapstructure:"alias"`
RequestType string `mapstructure:"request_type"` // QUERY | MUTATION
DataLoaderProvider dataloader.ProviderConfig `mapstructure:"data_loader_provider"`
UnwrapResponseField bool `mapstructure:"unwrap_response_field"`
Alias string `mapstructure:"alias"`
RequestType string `mapstructure:"request_type"` // QUERY | MUTATION
DataLoaderProvider dataloader.ProviderConfig `mapstructure:"data_loader_provider"`
}
type ServiceConfig struct {
ServiceName string `mapstructure:"service_name"`
Expand Down
51 changes: 25 additions & 26 deletions generator/plugins/proto2gql/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,28 +63,15 @@ func (g *Proto2GraphQL) parsedFile(file *parser.File) (*parsedFile, error) {
return f, nil
}
}
outPath, err := g.fileOutputPath(nil, file)
if err != nil {
return nil, errors.Wrapf(err, "failed to resolve file '%s' output path", file.FilePath)
}
outPkgName, outPkg, err := g.fileOutputPackage(nil, file)
if err != nil {
return nil, errors.Wrapf(err, "failed to resolve file '%s' output Go package", file.FilePath)
}
grpcPkg, err := g.fileGRPCSourcesPackage(nil, file)

parsedFile, err := g.createParsedFile(file, nil)

if err != nil {
return nil, errors.Wrapf(err, "failed to resolve file '%s' GRPC sources Go package", file.FilePath)
}
res := &parsedFile{
File: file,
Config: nil,
OutputPath: outPath,
OutputPkg: outPkg,
OutputPkgName: outPkgName,
GRPCSourcesPkg: grpcPkg,
return nil, err
}
g.ParsedFiles = append(g.ParsedFiles, res)
return res, nil

g.ParsedFiles = append(g.ParsedFiles, parsedFile)
return parsedFile, nil

}
func (g *Proto2GraphQL) prepareFile(file *parsedFile) (*graphql.TypesFile, error) {
Expand Down Expand Up @@ -206,25 +193,37 @@ func (g *Proto2GraphQL) AddSourceByConfig(config *ProtoFileConfig) error {
if err != nil {
return errors.Wrap(err, "failed to parse proto file")
}

parsedFile, err := g.createParsedFile(file, config)

if err != nil {
return err
}

g.ParsedFiles = append(g.ParsedFiles, parsedFile)
return nil
}

func (g *Proto2GraphQL) createParsedFile(file *parser.File, config *ProtoFileConfig) (*parsedFile, error) {
outPath, err := g.fileOutputPath(config, file)
if err != nil {
return errors.Wrapf(err, "failed to resolve file '%s' output path", file.FilePath)
return nil, errors.Wrapf(err, "failed to resolve file '%s' output path", file.FilePath)
}
outPkgName, outPkg, err := g.fileOutputPackage(config, file)
if err != nil {
return errors.Wrapf(err, "failed to resolve file '%s' output Go package", file.FilePath)
return nil, errors.Wrapf(err, "failed to resolve file '%s' output Go package", file.FilePath)
}
grpcPkg, err := g.fileGRPCSourcesPackage(config, file)
if err != nil {
return errors.Wrapf(err, "failed to resolve file '%s' GRPC sources Go package", file.FilePath)
return nil, errors.Wrapf(err, "failed to resolve file '%s' GRPC sources Go package", file.FilePath)
}
g.ParsedFiles = append(g.ParsedFiles, &parsedFile{

return &parsedFile{
File: file,
Config: config,
OutputPath: outPath,
OutputPkg: outPkg,
OutputPkgName: outPkgName,
GRPCSourcesPkg: grpcPkg,
})
return nil
}, nil
}
Loading

0 comments on commit f29e4c3

Please sign in to comment.