microsoftgraph / msgraph-sdk-go-core

Microsoft Graph SDK for Go - Core Library
https://learn.microsoft.com/graph/sdks/sdks-overview
MIT License
20 stars 10 forks source link

PageIterator doesn't give the delta link after completing the iteration #256

Closed Avihuc closed 8 months ago

Avihuc commented 11 months ago
func getUsers(ctx context.Context, client *msgraphsdk.GraphServiceClient, logger *slog.Logger) error {
    requestParameters := &graphusers.DeltaRequestBuilderGetQueryParameters{
        Select: []string{"id", "displayName", "userPrincipalName", "mail"},
    }
    configuration := &graphusers.DeltaRequestBuilderGetRequestConfiguration{
        QueryParameters: requestParameters,
    }
    result, err := client.Users().Delta().Get(ctx, configuration)
    if err != nil {
        return err
    }
    pageIterator, err := graphcore.NewPageIterator[models.Userable](result,
        client.GetAdapter(),
        models.CreateMessageCollectionResponseFromDiscriminatorValue,
    )
    if err != nil {
        return err
    }
    err = pageIterator.Iterate(
        ctx,
        func(user models.Userable) bool {
            logger.Info("fetched")
            return true
        })
    if err != nil {
        return err
    }
    // Always nil
    logger.Info("", "link", pageIterator.GetOdataDeltaLink())
    return nil
}
danyloshevchenkoingka commented 8 months ago

You should use CreateDeltaGetResponseFromDiscriminatorValue instead of CreateMessageCollectionResponseFromDiscriminatorValue

import "github.com/microsoftgraph/msgraph-sdk-go/users"

// ...

iterator, err := graphcore.NewPageIterator[*models.User](
    res,
    client.GetAdapter(),
    users.CreateDeltaGetResponseFromDiscriminatorValue,
)
microsoft-github-policy-service[bot] commented 8 months ago

This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment.