Closed nbelyh closed 1 year ago
The endpoint comes from the base Graph Queryable object (if you're not supplying one). Seems like you may be missing something.
Can you share some code for us and how your initializing your Graphfi object?
@bcameron1231 Yes, I hope so. I am initializing it like this (reproducible example):
import { graphfi } from '@pnp/graph';
import '@pnp/graph/users';
import '@pnp/graph/batching';
const client= graphfi('https://graph.microsoft.com/v1.0').using(....);
const me1 = await client.me(); // <<--- fine
console.log(me1);
const [batch, execute] = client.batched();
batch.me().then(me2 => console.log(me2))
await execute(); /// <<<--- booom, "method not allowed"
It makes query to https://graph.microsoft.com/$batch
instead of https://graph.microsoft.com/v1.0/$batch
So you don't need to pass in the Graph URL there. By default the graphFi object would point to v1.0.
If you want to specify the Graph Endpoint, you can do so by using behaviors. Endpoint, DefaultInit, GraphDefault behaviors allow you to do so.
I just tested without setting the url, with a batch, and it worked for me.
@bcameron1231 Hmm right If I remove the graph URL from graphfi(), the batched call starts working.
But then the "normal" (non-batched) call breaks, i.e. client.me()
with 'invalid url' exception 😅
The regex in the issue description source link specifically removes the '/v1.0' piece from the batching URL (thus breaking the call). Is there some reason for this?
Is the issue really with .me? Everything should work by default without you needing to specify a url.
@patrick-rodgers For me the batching issue is not with ".me" (it's with planner batching actually), but it can be reproduced with ".me". Batching ".me", like in the example above, of course does not make much sense 😅
The things that I tried: me
and me.memberOf
give an error with empty URL. But I will re-check in a clean project.
What type of application is this? SPFx, Node, Browser? We'll take a look.
By invalid URL error, I suspect you are seeing this one?
If you used DefaultInit() or GraphBrowser() (assuming this is non-spfx), it should work for now.
Yes, this one. Exact using is below, it's a browser with custom authentication (SSO):
Option 1 (results in batch call failing with "method not supported" because of missing '/v1.0' in the batch url):
const graph = graphfi('https://graph.microsoft.com/v1.0');
graph.using(
DefaultHeaders(),
DefaultInit(),
BrowserFetchWithRetry(),
DefaultParse(),
MyCustomAuthBehavior()
);
Option 2 (results in "Invalid URL"):
const graph = graphfi();
graph.using(
DefaultHeaders(),
DefaultInit(),
BrowserFetchWithRetry(),
DefaultParse(),
MyCustomAuthBehavior()
);
The MyCustomAuthBehavior
just sets the authorization header to a known value i.e. "Authorization: Bearer mytoken", it is not related to the problem.
Another note - it works fine for SharePoint, i.e. no such problem with SPFI, only graph.
Would you mind sharing with me your CustomAuth Behavior? Feel free to blur out anything that may be private.
I can't reproduce the issue you have with option 2.
@bcameron1231 It looks like this:
export function MyCustomAuthBehavior(): (instance: Queryable) => Queryable {
return (instance: Queryable) => {
instance.on.auth.replace(async (url: URL, init: RequestInit) => {
const accessToken = await AuthService.getAuthToken(); //<< this guy just returns a string
init.headers = { ...init.headers, Authorization: `Bearer ${accessToken}` };
return [url, init];
});
return instance;
};
}
I can make a demo repository if still not reproducible
Yes, I still cannot reproduce. A repository would be helpful. Thank you!
Will do, most probably tomorrow.
Just checking in to see how things are going on your end?
Closing this due to inactivity. If you continue to have issues please open a new issue, link to this issue, and provide any additional details available. Thanks!
This issue is locked for inactivity or age. If you have a related issue please open a new issue and reference this one. Closed issues are not tracked.
What version of PnPjs library you are using
3.x
Minor Version Number
3.17
Target environment
All
Additional environment details
I'm using PNPJS to call GRAPH API.
Question/Request
It seems that PNPJS makes request to
https://graph.microsoft.com/$batch
(without version). This URL seems to have stopped working. I'm receiving "Method not supported" (405)The request should be probably made to
https://graph.microsoft.com/v1.0/$batch
(this works)There is a specific code piece to remove the version, I'm wondering why? Here: https://github.com/pnp/pnpjs/blob/c807525236772b8483cc1cfee0c79ea071a28c27/packages/graph/batching.ts#L101