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

Not fully understanding the purpose of this project #245

Open
badsyntax opened this issue Apr 3, 2021 · 3 comments
Open

Not fully understanding the purpose of this project #245

badsyntax opened this issue Apr 3, 2021 · 3 comments
Assignees
Labels

Comments

@badsyntax
Copy link

badsyntax commented Apr 3, 2021

Hi there.
I've been using the microsoft graph client and the types in this repo.

The thing I don't fully understand, is why the types are separate from the microsoft graph client project, and why I need to explicitly typecast. It relies on me, the consumer, knowing the types ahead of time. I don't know the request or response data schema for all the endpoints, so how am I supposed to typecast? This approach seems a little risky to me, I could be typecasting wrong and could be using the wrong data structures.

Can someone clarify the situation and explain the microsoft graph client doesn't just use the types in this repo? It would make consumers's lives a lot better!

The client should provide the types for every endpoint. In the example below, as i consumer, I expect the client to tell me the types it expects:

// `user` should be typed by default
// the return type should be typed by default
client.api(`/users/${id}`).patch(user);

If the types cannot be combined with the client, can i suggest a slightly better approach (imo) for handling types. Instead of typecasting we can use generics:

client.api(`/users/${id}`).patch<RequestType, ResponseType>(user);

AB#8842

@ghost ghost added the ToTriage label Apr 3, 2021
@badsyntax badsyntax changed the title Not fully understanding the purpose of this repo Not fully understanding the purpose of this project Apr 3, 2021
@nikithauc nikithauc self-assigned this Apr 7, 2021
@ghost ghost removed the ToTriage label Apr 7, 2021
@nikithauc
Copy link
Contributor

@badsyntax Thank you for your suggestion! The Microsoft Graph Client is the core library which is intended to be light weight with a set of specific functionalities. The typings library is intended to be an interface to the regularly updated metadata.

However, we do have plans to improve on the points you put forward in this issue.

@badsyntax
Copy link
Author

Thanks for the reply @nikithauc Tbh I still don't fully understand why it's up to the consumer to provide the correct types. Perhaps another package is required? One that provides the correct types for msgraph-sdk-javascript, eg msgraph-sdk-typescript.

@noorvir
Copy link

noorvir commented Apr 5, 2024

I agree with @badsyntax. As such this project seems almost completely useless to me, perhaps even actively worse then no types at all. Since the user has to typecast every request, you could write code like this (taken from the docs) and shoot yourself in the foot.

@nikithauc are there any alternatives to this library? Or am I missing something?

import { User } from '@microsoft/microsoft-graph-types';

export async function getUserAsync(): Promise<User> {
  return (
    client
      .api('/me')
      // Not requesting 'activities'
      .select(['displayName', 'userPrincipalName'])
      .get()
  );
}

async function getUserInfo(email: string) {
  // Returns Users type
  const u = await getUserAsync();

  // This will be null even though u is type as User which has the activities property
  console.log(u.activities);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants