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

Workbook package #3019

Draft
wants to merge 4 commits into
base: version-4
Choose a base branch
from
Draft

Workbook package #3019

wants to merge 4 commits into from

Conversation

ChapC
Copy link

@ChapC ChapC commented Apr 26, 2024

Category

  • Bug fix?
  • [ X ] New feature?
  • New sample?
  • Documentation update?

Related Issues

Mentioned in #3016

What's in this Pull Request?

Initial draft of Excel workbook support.
This first commit includes

  • workbook session creation
  • listing/getting tables
  • listing/getting rows

I'll implement more endpoints as I go, but have a couple of notes/questions I thought I'd post here first.

  1. Your contributing guidelines mention I should skip writing tests for endpoints that don't support app auth. According to the docs, that's all of the workbook endpoints. Is there any way I can write tests we can use for these endpoints?
  2. In my testing, I wasn't able to use workbook operations on items opened by path. These failed with "Could not obtain a WAC token". When I use getItemById, it works. I wrote this off as a Graph API bug, but haven't tested extensively.
  3. My current implementation of workbook sessions involves a workbook property on DriveItem that leads to a regular, sessionless IWorkbook and an async method getWorkbookSession that resolves to an IWorkbookWithSession. The latter is an extension of IWorkbook that adds session refresh/close methods, and uses the InjectHeaders behaviour to add the session id header. Thoughts on this approach?
  4. I've added a prefer-async behavior to the graph folder. This is to handle the long-running operation pattern that a few of the workbook endpoints support. Again, I'm not sure if this is the ideal approach, but it's what I've got at the moment.

Welcoming all feedback. Thanks!

Copy link
Member

@patrick-rodgers patrick-rodgers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really nice work! You did a great job figuring out and integrating with the library. I left a few comments for you to consider. Excited for your contribution!!

let succeeded = false;
const statusQuery = GraphQueryable(instance, `operations/${opId}`);
for (let i = 0; i < maxPolls; i++) {
await new Promise(resolve => setTimeout(resolve, pollIntervalMs));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have delay() in core you can use for this very thing.

for (let i = 0; i < maxPolls; i++) {
await new Promise(resolve => setTimeout(resolve, pollIntervalMs));

const status = await graphGet<RichLongRunningOperation>(statusQuery);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For GET you should be able to invoke the queryable itself await statusQuery<>()

instance.using(InjectHeaders({ "Prefer": "respond-async" }));

instance.on.parse(async function (url, response, result) {
if (response.status === 202) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if you get a different response? We have some standard logic wrapped up here to check for errors. Used here and here for example.

WorkbookSessionInfo
} from "@microsoft/microsoft-graph-types";

export async function getWorkbookSession(this: _DriveItem, persistChanges: boolean): Promise<IWorkbookWithSession> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the only place this will really get used is in the property in the other file you can code it there directly. i.e. remove the export here and put the code there. But if this is a function that will be used on its own this makes sense.

@patrick-rodgers
Copy link
Member

1. Your contributing guidelines mention I should skip writing tests for endpoints that don't support app auth. According to the docs, that's all of the workbook endpoints. Is there any way I can write tests we can use for these endpoints?

Not really. You can test them locally. We are working on test recording to allow us to record delegated-auth tests and replay them to validate.

2. In my testing, I wasn't able to use workbook operations on items opened by path. These failed with "Could not obtain a WAC token". When I use getItemById, it works. I wrote this off as a Graph API bug, but haven't tested extensively.

Don't know, WAC is the office protocol, perhaps that endpoint requires something special.

3. My current implementation of workbook sessions involves a workbook property on DriveItem that leads to a regular, sessionless IWorkbook and an async method getWorkbookSession that resolves to an IWorkbookWithSession. The latter is an extension of IWorkbook that adds session refresh/close methods, and uses the InjectHeaders behaviour to add the session id header. Thoughts on this approach?

I am not deeply familiar with this API, what is the difference between sessionless and with session? Do we need to expose both?

4. I've added a prefer-async behavior to the graph folder. This is to handle the long-running operation pattern that a few of the workbook endpoints support. Again, I'm not sure if this is the ideal approach, but it's what I've got at the moment.

This is pretty slick, I left a few notes inline. This isn't something we built-in for v4 launch, but I can see a ton of value to including it.

Again, nice work!

A few of the collections from the workbook endpoints support
getItemAt(index). I've implemented this in the same pattern as
the getById decorator. Currently I've only added it to the rows
collection.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants