-
Notifications
You must be signed in to change notification settings - Fork 232
Adding initial thoughts on Kiota JS for Graph #558
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
Merged
sebastienlevert
merged 13 commits into
microsoftgraph:dev
from
sebastienlevert:sebastienlevert/v4-js-e2e
Feb 15, 2022
Merged
Changes from 3 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
774d226
Adding initial thoughts on Kiota JS for Graph
sebastienlevert d261c77
Revert "Adding initial thoughts on Kiota JS for Graph"
sebastienlevert 15fc99f
Adding kiota e2e
sebastienlevert 7a17e7f
Updates
sebastienlevert 798159c
Update design/kiota-e2e.md
sebastienlevert dd24ad9
Adding types from our package
sebastienlevert af9ab8a
Merge branch 'sebastienlevert/v4-js-e2e' of https://github.com/sebast…
sebastienlevert 5d3bd24
Adding more concepts to the e2e
sebastienlevert a8a9794
Merge branch 'dev' into sebastienlevert/v4-js-e2e
nikithauc 2098f52
Merge branch 'dev' into sebastienlevert/v4-js-e2e
nikithauc b3a5c02
Merge branch 'dev' into sebastienlevert/v4-js-e2e
nikithauc 68b5341
Merge branch 'microsoftgraph:dev' into sebastienlevert/v4-js-e2e
sebastienlevert 53b94a8
Updates to the packages + Reformatingnm
sebastienlevert File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,147 @@ | ||
| # End-to-end usage of kiota-generated SDKs in Javascript | ||
|
|
||
| While working with the Kiota + Javascript teams, it became clear that we needed more context and provide a better vision on how we should be using a kiota-generated SDK. This design document aims at providing clarity and a better understanding on how developers will be using our SDKs and the underlying kiota packages. | ||
|
|
||
| ## Constraints | ||
|
|
||
| Before we jump into the end-to-end walk-through, it's important to set some constraints. | ||
|
|
||
| | Type | Description | | ||
| | --------- | --------------------------------------------------------------------------------------------------------------------------------------------- | | ||
| | Platforms | Node : Current and Previous LTS (14 / 16)<br /> Web : Edge, Chrome, Firefox and Safari (Latest released version + immediate previous version) | | ||
| | Modules | Node : CommonJS<br /> Web : ES Module (ES6) | | ||
| | Types | Typings should be available for both the core and the service libraries for Graph models | | ||
|
|
||
| ## NodeJS e2e using the Service library | ||
|
|
||
| ```bash | ||
| npm install @microsoft/msgraph-sdk-typescript --save | ||
| npm install @microsoft/kiota-authentication-azure --save | ||
sebastienlevert marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ``` | ||
|
|
||
| ```typescript | ||
| // App.ts | ||
|
|
||
| import { Client, User, Message, BodyType } from "@microsoft/msgraph-sdk-javascript"; | ||
sebastienlevert marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| import { AzureIdentityAuthenticationProvider } from "@microsoft/kiota-authentication-azure"; | ||
sebastienlevert marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| import { DeviceCodeCredential } from "@azure/identity"; | ||
|
|
||
| const deviceCodeCredentials = new DeviceCodeCredential({ | ||
| tenantId: "b61f9af1-d6cf-4cc0-a6f6-befb38bc00ed", | ||
| clientId: "bde251a6-0ef9-42a8-a40b-9ad9bb594b2c", | ||
| }); | ||
|
|
||
| const scopes = ["User.Read", "Mail.Send"]; | ||
|
|
||
| const graphClient = Client.init({ | ||
nikithauc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| accessTokenProvider: new AzureIdentityAccessTokenProvider(deviceCodeCredentials, scopes), | ||
sebastienlevert marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| }); | ||
|
|
||
| const me = await getMe(); | ||
| const meRaw = await getMeRaw(); | ||
| await sendMail(); | ||
| await sendMailRaw(); | ||
sebastienlevert marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| async function getMe(): Promise<User | undefined> { | ||
| return await graphClient.me.get(); | ||
| } | ||
|
|
||
| async function getMe(): Promise<User | undefined> { | ||
sebastienlevert marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return await graphClient.api("/me").get(); | ||
| } | ||
|
|
||
| async function sendMail(): Promise<void> { | ||
| const message: Message = { | ||
baywet marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| subject: "Hello Graph TypeScript SDK!", | ||
| body: { | ||
| contentType: BodyType.Html, | ||
| content: "<bold>Hello Graph TypeScript SDK!</bold>", | ||
| }, | ||
| toRecipients: [ | ||
| { | ||
| emailAddress: { | ||
| address: "[email protected]", | ||
| }, | ||
| }, | ||
| ], | ||
| }; | ||
|
|
||
| return await client.me.sendMail.post(message); | ||
| } | ||
|
|
||
| async function sendMailRaw(): Promise<void> { | ||
| const message: Message = { | ||
| subject: "Hello Graph TypeScript SDK!", | ||
| body: { | ||
| contentType: BodyType.Html, | ||
| content: "<bold>Hello Graph TypeScript SDK!</bold>", | ||
| }, | ||
| toRecipients: [ | ||
| { | ||
| emailAddress: { | ||
| address: "[email protected]", | ||
| }, | ||
| }, | ||
| ], | ||
| }; | ||
|
|
||
| return await client.api("/me/sendMail").post({ | ||
| message: message, | ||
| }); | ||
| } | ||
| ``` | ||
|
|
||
| ## NodeJS e2e using the Core library | ||
|
|
||
| ```bash | ||
sebastienlevert marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| npm install @microsoft/msgraph-sdk-javascript-core --save | ||
| npm install @microsoft/msgraph-sdk-javascript-types --save | ||
| npm install @microsoft/kiota-authentication-azure --save | ||
| ``` | ||
|
|
||
| ```typescript | ||
| // App.ts | ||
|
|
||
| import { Client } from "@microsoft/msgraph-sdk-javascript-core"; | ||
| import { AzureIdentityAuthenticationProvider } from "@microsoft/kiota-authentication-azure"; | ||
| import { DeviceCodeCredential } from "@azure/identity"; | ||
|
|
||
| const deviceCodeCredentials = new DeviceCodeCredential({ | ||
| tenantId: "b61f9af1-d6cf-4cc0-a6f6-befb38bc00ed", | ||
| clientId: "bde251a6-0ef9-42a8-a40b-9ad9bb594b2c", | ||
| }); | ||
|
|
||
| const scopes = ["User.Read", "Mail.Send"]; | ||
|
|
||
| const graphClient = Client.init({ | ||
| accessTokenProvider: new AzureIdentityAccessTokenProvider(deviceCodeCredentials, scopes), | ||
| }); | ||
|
|
||
| const me = await getMe(); | ||
| await sendMail(); | ||
|
|
||
| async function getMe(): Promise<User | undefined> { | ||
| return await graphClient.api("/me").get(); | ||
| } | ||
|
|
||
| async function sendMail(): Promise<void> { | ||
| const message: Message = { | ||
| subject: "Hello Graph TypeScript SDK!", | ||
| body: { | ||
| contentType: BodyType.Html, | ||
| content: "<bold>Hello Graph TypeScript SDK!</bold>", | ||
| }, | ||
| toRecipients: [ | ||
| { | ||
| emailAddress: { | ||
| address: "[email protected]", | ||
| }, | ||
| }, | ||
| ], | ||
| }; | ||
|
|
||
| return await client.api("/me/sendMail").post({ | ||
| message: message, | ||
| }); | ||
| } | ||
| ``` | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.