Is it really correct that the Javascript version of the graph SDK doesn't offer typed requests?

Open
#2,004 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
42/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Quiet

Research direction

Start with the JavaScript tab in the linked Microsoft Graph search-query documentation and inspect the client.api('/search/query') request and response behavior. Compare that with the typed C# sample; done means establishing whether typed request and response support exists in this SDK and documenting or scoping the gap clearly.

Written by the indexing model from the issue text.

Description

status:waiting-for-triage

I'm coming from a C# background so forgive me if I'm wrong on this, but from the documentation it seems for example that doing a graph search in C# is fully typed, e.g:


var requestBody = new QueryPostRequestBody
{
	Requests = new List<SearchRequest>
	{
		new SearchRequest
		{
			EntityTypes = new List<EntityType?>
			{
				EntityType.ExternalItem,
			},
			ContentSources = new List<string>
			{
				"/external/connections/connectionfriendlyname",
			},
			Region = "US",
			Query = new SearchQuery
			{
				QueryString = "contoso product",
			},
			From = 0,
			Size = 25,
			Fields = new List<string>
			{
				"title",
				"description",
			},
		},
	},
};

var result = await graphClient.Search.Query.PostAsQueryPostResponseAsync(requestBody);

Which is fine, give you a SearchResponse object.

whereas in javascript you need to use the "magic string" /search/query for example:


const searchResponse = {
  requests: [
    {
      entityTypes: [
        'externalItem'
      ],
      contentSources: [
        '/external/connections/connectionfriendlyname'
      ],
       region: 'US',
       query: {
        queryString: 'contoso product'
      },
      from: 0,
      size: 25,
      fields: [
        'title',
        'description'
      ]
    }
  ]
};

await client.api('/search/query')
	.post(searchResponse);

And this returns an any type, so you have to know/guess the response?

Both samples taken from https://learn.microsoft.com/en-us/graph/api/search-query?view=graph-rest-1.0&utm_source=chatgpt.com&tabs=javascript

Is this actually correct?

Dominant language
TypeScript
Stars
833
Forks
240
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from microsoftgraph/msgraph-sdk-javascript

All issues in microsoftgraph/msgraph-sdk-javascript

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.