Skip to content

Commit

Permalink
Invoke page iterator by method not field (#167)
Browse files Browse the repository at this point in the history
  • Loading branch information
rkodev authored Mar 6, 2023
1 parent 17dbbd3 commit 9ca59de
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

## [0.34.1] - 2023-03-06

### Changed

- Change `PageIterator` to use `GetValue` method instead of `value` field to access response.

## [0.34.0] - 2023-02-23

### Added
Expand Down
13 changes: 5 additions & 8 deletions page_iterator.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@ package msgraphgocore
import (
"context"
"errors"
"net/url"
"reflect"
"unsafe"

abstractions "github.com/microsoft/kiota-abstractions-go"
"github.com/microsoft/kiota-abstractions-go/serialization"
"net/url"
"reflect"
)

// PageIterator represents an iterator object that can be used to get subsequent pages of a collection.
Expand Down Expand Up @@ -199,13 +197,12 @@ func convertToPage(response interface{}) (PageResult, error) {
if response == nil {
return page, errors.New("response cannot be nil")
}
ref := reflect.ValueOf(response).Elem()

value := ref.FieldByName("value")
if value.IsNil() {
method := reflect.ValueOf(response).MethodByName("GetValue")
if method.IsNil() {
return page, errors.New("value property missing in response object")
}
value = reflect.NewAt(value.Type(), unsafe.Pointer(value.UnsafeAddr())).Elem()
value := method.Call(nil)[0]

// Collect all entities in the value slice.
// This converts a graph slice ie []graph.User to a dynamic slice []interface{}
Expand Down
2 changes: 1 addition & 1 deletion page_iterator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func TestConstructorWithInvalidRequestAdapter(t *testing.T) {
}

func TestConstructorWithInvalidGraphResponse(t *testing.T) {
graphResponse := internal.NewUsersResponse()
graphResponse := internal.NewInvalidUsersResponse()

_, err := NewPageIterator(graphResponse, reqAdapter, ParsableCons)

Expand Down

0 comments on commit 9ca59de

Please sign in to comment.