microsoftgraph / msgraph-sdk-dotnet

Microsoft Graph Client Library for .NET!
https://graph.microsoft.com
Other
690 stars 246 forks source link

MS Graph Search Query response missing values #2642

Open Sdelausnay opened 2 weeks ago

Sdelausnay commented 2 weeks ago

Describe the bug

When I perform a search on SharePoint using the SDK I get a incomplete response.

var requestBody = new QueryPostRequestBody
{
    Requests = new List<SearchRequest>
    {
        new SearchRequest
        {
            EntityTypes = new List<EntityType?>
            {
                EntityType.DriveItem,
            },
            Query = new SearchQuery
            {
                QueryString = "LaaS-workshop",
            },
        },
    },
};

return await this._graphClient.Search.Query.PostAsQueryPostResponseAsync(requestBody);

Returns:

{
    "Value": [{
            "AdditionalData": {},
            "BackingStore": {
                "InitializationCompleted": false,
                "ReturnOnlyChangedValues": false
            },
            "HitsContainers": [{
                    "AdditionalData": {},
                    "Aggregations": null,
                    "BackingStore": {
                        "InitializationCompleted": false,
                        "ReturnOnlyChangedValues": false
                    },
                    "Hits": [{
                            "AdditionalData": {},
                            "BackingStore": {
                                "InitializationCompleted": false,
                                "ReturnOnlyChangedValues": false
                            },
                            "ContentSource": null,
                            "HitId": "01K2KRWNAQYQUAB7MMDZHZV4Q2GHCWZY4M",
                            "IsCollapsed": null,
                            "OdataType": null,
                            "Rank": 1,
                            "Resource": {
                                "AdditionalData": {},
                                "BackingStore": {
                                    "InitializationCompleted": false,
                                    "ReturnOnlyChangedValues": false
                                },
                                "Id": null,
                                "OdataType": "#microsoft.graph.driveItem"
                            },
                            "ResultTemplateId": null,
                            "Summary": "LaaS design workshop results xxxxxxxxxx LaaS design workshop results 2024-08-01 Contact persons Name:xxxxxxxxxxxxxxx Position: Infra \u0026 Security Architect E-mail: xxx"
                    }
                    ],
                    "MoreResultsAvailable": true,
                    "OdataType": null,
                    "Total": 30
                }
            ],
            "OdataType": null,
            "QueryAlterationResponse": null,
            "ResultTemplates": null,
            "SearchTerms": ["laas-workshop"]
        }
    ],
    "AdditionalData": {
        "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#Collection(microsoft.graph.searchResponse)"
    },
    "BackingStore": {
        "InitializationCompleted": true,
        "ReturnOnlyChangedValues": false
    },
    "OdataCount": null,
    "OdataNextLink": null
}

When I use the API itself, I get folling reponse:

{
    "value": [
        {
            "searchTerms": [
                "laas-workshop"
            ],
            "hitsContainers": [
                {
                    "hits": [
                        {
                            "hitId": "01K2KRWNAQYQUAB7MMDZHZV4Q2GHCWZY4M",
                            "rank": 1,
                            "summary": "LaaS design workshop results xxxxxxxxxxxxxx LaaS design workshop results 2024-08-01 Contact persons Name: xxxxxxxxxxxxxxxx Position: Infra & Security Architect E-mail: xxxx",
                            "resource": {
                                "@odata.type": "#microsoft.graph.driveItem",
                                "size": 694480,
                                "fileSystemInfo": {
                                    "createdDateTime": "2024-08-26T14:33:53Z",
                                    "lastModifiedDateTime": "2024-08-27T14:41:00Z"
                                },
                                "listItem": {
                                    "@odata.type": "#microsoft.graph.listItem",
                                    "id": "0028c410-8cfd-4f1e-9af2-1a31c56ce38c",
                                    "fields": {}
                                },
                                "id": "01K2KRWNAQYQUAB7MMDZHZV4Q2GHCWZY4M",
                                "createdBy": {
                                    "user": {
                                        "displayName": "xxxxxxxxxxxxxxxx",
                                        "email": "xxxxxxxxxxxxxxxxxxxxxxx"
                                    }
                                },
                                "createdDateTime": "2024-08-26T14:33:53Z",
                                "lastModifiedBy": {
                                    "user": {
                                        "displayName": "xxxxxxxxxxxx",
                                        "email": "xxxxxxxxxxxxxxx"
                                    }
                                },
                                "lastModifiedDateTime": "2024-08-27T14:41:00Z",
                                "name": "LaaS-workshop.docx",
                                "parentReference": {
                                    "driveId": "b!5bODLAnw2k2O_yzxuxxo9vCGqOyzE3ZGnqnR1S2b0x8zofUlTtSrSZLIRP9p5Q9a",
                                    "id": "01K2KRWNE5QVEAPK6PZNDKMGODJLE23R7X",
                                    "sharepointIds": {
                                        "listId": "25f5a133-d44e-49ab-92c8-44ff69e50f5a",
                                        "listItemId": "8009",
                                        "listItemUniqueId": "0028c410-8cfd-4f1e-9af2-1a31c56ce38c"
                                    },
                                    "siteId": "xxxxxx.sharepoint.com,xxxxxx,xxxxxxx"
                                },
                                "webUrl": "https://..../General/01 - Workshop/...../LaaS-workshop.docx"
                            }
                        }
                    ],
                    "total": 29,
                    "moreResultsAvailable": true
                }
            ]
        }
    ],
    "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#Collection(microsoft.graph.searchResponse)"
}

I'm using the same connection settings, tries with the official release of the SDK and the Beta version. But both have the same result. I really need the additional resource info on the files found.

Anybody an idea what the problem is?

Expected behavior

Getting the same response with the SDK as with the normal API call

How to reproduce

Run the code above and the same API call in Postman

SDK Version

5.56.0

Latest version known to work for scenario above?

No response

Known Workarounds

No response

Debug output

Click to expand log ``` ```

Configuration

No response

Other information

No response

andrueastman commented 2 weeks ago

Thanks for raising this @Sdelausnay

To confirm, are you serializing the result using a serializer like System.Text.Json do you get a different result if you follow the sugestion at https://github.com/microsoftgraph/msgraph-sdk-dotnet/issues/2638#issuecomment-2311752427

Sdelausnay commented 2 weeks ago

I have tested it but same results, no more info and if I look in the debug a the properties, all fields returned by the function are null.

andrueastman commented 2 weeks ago

Any chance you can share the results? As Kiota generated models are self-contained with serialization information, you should'nt be seeing properties like backingStore. Also properties like OdataNextLink should be correctly represented without escaping.

var jsonString = await KiotaSerializer.SerializeAsStringAsync("application/json", result, false);
Sdelausnay commented 2 weeks ago

Tested again an idd it gives some more information now, if I request some fields, they are now also added to the reponse. But still all other information I'm still missing.

                    {
                      "hitId": "01K2KRWNAQYQUAB7MMDZHZV4Q2GHCWZY4M",
                      "rank": 1,
                      "resource": {
                          "@odata.type": "#microsoft.graph.driveItem",
                          "listItem": {
                              "id": "0028c410-8cfd-4f1e-9af2-1a31c56ce38c",
                              "@odata.type": "#microsoft.graph.listItem",
                              "fields": {
                                  "title": "LaaS design workshop results"
                              }
                          }
                      },
                      "summary": "LaaS design workshop results xxxxxxxxxxxxxxx LaaS design workshop results 2024-08-01 Contact persons Name: xxxxxxxxxxxx Position: Infra \u0026 Security Architect E-mail: xxxxxx."
                  }