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

Cleaner default resolver, cache FieldDefMap Get, preallocate #241

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion definition.go
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,6 @@ func (gt *Object) Fields() FieldDefinitionMap {
if gt.initialisedFields {
return gt.fields
}

var configureFields Fields
switch gt.typeConfig.Fields.(type) {
case Fields:
Expand Down
24 changes: 12 additions & 12 deletions executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ func executeFields(p executeFieldsParams) *Result {
p.Fields = map[string][]*ast.Field{}
}

finalResults := map[string]interface{}{}
finalResults := make(map[string]interface{}, len(p.Fields))
for responseName, fieldASTs := range p.Fields {
resolved, state := resolveField(p.ExecutionContext, p.ParentType, p.Source, fieldASTs)
if state.hasNoFieldDefs {
Expand Down Expand Up @@ -742,16 +742,16 @@ func completeObjectValue(eCtx *executionContext, returnType *Object, fieldASTs [
continue
}
selectionSet := fieldAST.SelectionSet
if selectionSet != nil {
innerParams := collectFieldsParams{
ExeContext: eCtx,
RuntimeType: returnType,
SelectionSet: selectionSet,
Fields: subFieldASTs,
VisitedFragmentNames: visitedFragmentNames,
}
subFieldASTs = collectFields(innerParams)
if selectionSet == nil {
continue
}
subFieldASTs = collectFields(CollectFieldsParams{
ExeContext: eCtx,
RuntimeType: returnType,
SelectionSet: selectionSet,
Fields: subFieldASTs,
VisitedFragmentNames: visitedFragmentNames,
})
}
executeFieldsParams := executeFieldsParams{
ExecutionContext: eCtx,
Expand Down Expand Up @@ -791,7 +791,7 @@ func completeListValue(eCtx *executionContext, returnType *List, fieldASTs []*as
}

itemType := returnType.OfType
completedResults := []interface{}{}
completedResults := make([]interface{}, 0, resultVal.Len())
for i := 0; i < resultVal.Len(); i++ {
val := resultVal.Index(i).Interface()
completedItem := completeValueCatchingError(eCtx, itemType, fieldASTs, info, val)
Expand Down Expand Up @@ -832,7 +832,7 @@ type FieldResolver interface {
// and returns it as the result, or if it's a function, returns the result
// of calling that function.
func DefaultResolveFn(p ResolveParams) (interface{}, error) {
sourceVal := reflect.ValueOf(p.Source)
sourceVal := reflect.ValueOf(p.Source)
// Check if value implements 'Resolver' interface
if resolver, ok := sourceVal.Interface().(FieldResolver); ok {
return resolver.Resolve(p)
Expand Down