Skip to content

Commit

Permalink
Fix default scalars
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Scarr committed Mar 11, 2019
1 parent d7b5dc2 commit 30d235b
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 6 deletions.
85 changes: 85 additions & 0 deletions codegen/testserver/generated.go

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

4 changes: 4 additions & 0 deletions codegen/testserver/models-gen.go

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

4 changes: 4 additions & 0 deletions codegen/testserver/scalar_default.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,7 @@ extend type Query {

""" This doesnt have an implementation in the typemap, so it should act like a string """
scalar DefaultScalarImplementation

type EmbeddedDefaultScalar {
value: DefaultScalarImplementation
}
22 changes: 16 additions & 6 deletions plugin/modelgen/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,22 @@ func (m *Plugin) MutateConfig(cfg *config.Config) error {
return err
}
} else {
// no user defined model, must reference another generated model
typ = types.NewNamed(
types.NewTypeName(0, cfg.Model.Pkg(), templates.ToGo(field.Type.Name()), nil),
nil,
nil,
)
fieldDef := schema.Types[field.Type.Name()]
if fieldDef.Kind == ast.Scalar {
// no user defined model, referencing a default scalar
typ = types.NewNamed(
types.NewTypeName(0, cfg.Model.Pkg(), "string", nil),
nil,
nil,
)
} else {
// no user defined model, must reference another generated model
typ = types.NewNamed(
types.NewTypeName(0, cfg.Model.Pkg(), templates.ToGo(field.Type.Name()), nil),
nil,
nil,
)
}
}

name := field.Name
Expand Down

0 comments on commit 30d235b

Please sign in to comment.