forked from arsmn/fastgql
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request 99designs#20 from vektah/codegen-cleanup
Codegen cleanup
- Loading branch information
Showing
21 changed files
with
3,253 additions
and
2,846 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
{{ $field := . }} | ||
{{ $object := $field.Object }} | ||
|
||
{{- if $object.Stream }} | ||
func (ec *executionContext) _{{$object.GQLType}}_{{$field.GQLName}}(field graphql.CollectedField) func() graphql.Marshaler { | ||
{{- template "args.gotpl" $field.Args }} | ||
results, err := ec.resolvers.{{ $object.GQLType }}_{{ $field.GQLName }}({{ $field.CallArgs }}) | ||
if err != nil { | ||
ec.Error(err) | ||
return nil | ||
} | ||
return func() graphql.Marshaler { | ||
res, ok := <-results | ||
if !ok { | ||
return nil | ||
} | ||
var out graphql.OrderedMap | ||
out.Add(field.Alias, func() graphql.Marshaler { {{ $field.WriteJson }} }()) | ||
return &out | ||
} | ||
} | ||
{{ else }} | ||
func (ec *executionContext) _{{$object.GQLType}}_{{$field.GQLName}}(field graphql.CollectedField, {{if not $object.Root}}obj *{{$object.FullName}}{{end}}) graphql.Marshaler { | ||
{{- template "args.gotpl" $field.Args }} | ||
|
||
{{- if $field.IsConcurrent }} | ||
return graphql.Defer(func() graphql.Marshaler { | ||
{{- end }} | ||
|
||
{{- if $field.GoVarName }} | ||
res := obj.{{$field.GoVarName}} | ||
{{- else if $field.GoMethodName }} | ||
{{- if $field.NoErr }} | ||
res := {{$field.GoMethodName}}({{ $field.CallArgs }}) | ||
{{- else }} | ||
res, err := {{$field.GoMethodName}}({{ $field.CallArgs }}) | ||
if err != nil { | ||
ec.Error(err) | ||
return graphql.Null | ||
} | ||
{{- end }} | ||
{{- else }} | ||
res, err := ec.resolvers.{{ $object.GQLType }}_{{ $field.GQLName }}({{ $field.CallArgs }}) | ||
if err != nil { | ||
ec.Error(err) | ||
return graphql.Null | ||
} | ||
{{- end }} | ||
{{ $field.WriteJson }} | ||
{{- if $field.IsConcurrent }} | ||
}) | ||
{{- end }} | ||
} | ||
{{ end }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,18 @@ | ||
{{- $interface := . }} | ||
|
||
func (ec *executionContext) _{{$interface.GQLType|lcFirst}}(sel []query.Selection, it *{{$interface.FullName}}) graphql.Marshaler { | ||
switch it := (*it).(type) { | ||
func (ec *executionContext) _{{$interface.GQLType}}(sel []query.Selection, obj *{{$interface.FullName}}) graphql.Marshaler { | ||
switch obj := (*obj).(type) { | ||
case nil: | ||
return graphql.Null | ||
{{- range $implementor := $interface.Implementors }} | ||
case {{$implementor.FullName}}: | ||
return ec._{{$implementor.GQLType|lcFirst}}(sel, &it) | ||
return ec._{{$implementor.GQLType}}(sel, &obj) | ||
|
||
case *{{$implementor.FullName}}: | ||
return ec._{{$implementor.GQLType|lcFirst}}(sel, it) | ||
return ec._{{$implementor.GQLType}}(sel, obj) | ||
|
||
{{- end }} | ||
default: | ||
panic(fmt.Errorf("unexpected type %T", it)) | ||
panic(fmt.Errorf("unexpected type %T", obj)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.