Skip to content

Commit

Permalink
Inject non-spec builtin values only if defined
Browse files Browse the repository at this point in the history
  • Loading branch information
Mathew Byrne committed Mar 18, 2019
1 parent fc05501 commit d567d5c
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions codegen/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,8 +342,6 @@ func (c *Config) InjectBuiltins(s *ast.Schema) {
"Float": {Model: StringList{"github.com/99designs/gqlgen/graphql.Float"}},
"String": {Model: StringList{"github.com/99designs/gqlgen/graphql.String"}},
"Boolean": {Model: StringList{"github.com/99designs/gqlgen/graphql.Boolean"}},
"Time": {Model: StringList{"github.com/99designs/gqlgen/graphql.Time"}},
"Map": {Model: StringList{"github.com/99designs/gqlgen/graphql.Map"}},
"Int": {Model: StringList{
"github.com/99designs/gqlgen/graphql.Int",
"github.com/99designs/gqlgen/graphql.Int32",
Expand All @@ -362,6 +360,18 @@ func (c *Config) InjectBuiltins(s *ast.Schema) {
c.Models[typeName] = entry
}
}

// These are additional types that are injected if defined in the schema as scalars.
extraBuiltins := TypeMap{
"Time": {Model: StringList{"github.com/99designs/gqlgen/graphql.Time"}},
"Map": {Model: StringList{"github.com/99designs/gqlgen/graphql.Map"}},
}

for typeName, entry := range extraBuiltins {
if t, ok := s.Types[typeName]; ok && t.Kind == ast.Scalar {
c.Models[typeName] = entry
}
}
}

func (c *Config) LoadSchema() (*ast.Schema, map[string]string, error) {
Expand Down

0 comments on commit d567d5c

Please sign in to comment.