Skip to content

Commit

Permalink
Merge pull request #422 from gracenoah/model-method-context
Browse files Browse the repository at this point in the history
accept an optional ctx parameter on model methods
  • Loading branch information
vektah authored Nov 16, 2018
2 parents 0ac6fa5 + 5faf3a2 commit d25e3b4
Show file tree
Hide file tree
Showing 9 changed files with 326 additions and 14 deletions.
30 changes: 19 additions & 11 deletions codegen/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,17 @@ type Object struct {

type Field struct {
*Type
Description string // Description of a field
GQLName string // The name of the field in graphql
GoFieldType GoFieldType // The field type in go, if any
GoReceiverName string // The name of method & var receiver in go, if any
GoFieldName string // The name of the method or var in go, if any
Args []FieldArgument // A list of arguments to be passed to this field
ForceResolver bool // Should be emit Resolver method
NoErr bool // If this is bound to a go method, does that method have an error as the second argument
Object *Object // A link back to the parent object
Default interface{} // The default value
Description string // Description of a field
GQLName string // The name of the field in graphql
GoFieldType GoFieldType // The field type in go, if any
GoReceiverName string // The name of method & var receiver in go, if any
GoFieldName string // The name of the method or var in go, if any
Args []FieldArgument // A list of arguments to be passed to this field
ForceResolver bool // Should be emit Resolver method
MethodHasContext bool // If this is bound to a go method, does the method also take a context
NoErr bool // If this is bound to a go method, does that method have an error as the second argument
Object *Object // A link back to the parent object
Default interface{} // The default value
}

type FieldArgument struct {
Expand Down Expand Up @@ -103,7 +104,10 @@ func (f *Field) IsVariable() bool {
}

func (f *Field) IsConcurrent() bool {
return f.IsResolver() && !f.Object.DisableConcurrency
if f.Object.DisableConcurrency {
return false
}
return f.MethodHasContext || f.IsResolver()
}

func (f *Field) GoNameExported() string {
Expand Down Expand Up @@ -209,6 +213,10 @@ func (f *Field) CallArgs() string {
if !f.Object.Root {
args = append(args, "obj")
}
} else {
if f.MethodHasContext {
args = append(args, "ctx")
}
}

for _, arg := range f.Args {
Expand Down
212 changes: 212 additions & 0 deletions codegen/testserver/generated.go

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

Loading

0 comments on commit d25e3b4

Please sign in to comment.