Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix default scalars #605

Merged
merged 1 commit into from
Mar 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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