-
Notifications
You must be signed in to change notification settings - Fork 304
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3039 from patrick-rodgers/version-4
updates to better handle graph default url logic
- Loading branch information
Showing
4 changed files
with
24 additions
and
37 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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 |
---|---|---|
@@ -1,38 +1,27 @@ | ||
import { combine, isUrlAbsolute, TimelinePipe } from "@pnp/core"; | ||
import { TimelinePipe } from "@pnp/core"; | ||
import { BrowserFetchWithRetry, DefaultParse, Queryable } from "@pnp/queryable"; | ||
import { DefaultHeaders, DefaultInit } from "./defaults.js"; | ||
import { DEFAULT_GRAPH_URL } from "../index.js"; | ||
|
||
export interface IGraphBrowserProps { | ||
baseUrl?: string; | ||
} | ||
|
||
export function GraphBrowser(props?: IGraphBrowserProps): TimelinePipe<Queryable> { | ||
|
||
if (props?.baseUrl && !isUrlAbsolute(props.baseUrl)) { | ||
throw Error("GraphBrowser props.baseUrl must be absolute when supplied."); | ||
} | ||
const { baseUrl } = { | ||
baseUrl: DEFAULT_GRAPH_URL, | ||
...props, | ||
}; | ||
|
||
return (instance: Queryable) => { | ||
|
||
instance.using( | ||
DefaultHeaders(), | ||
DefaultInit(), | ||
DefaultInit(baseUrl), | ||
BrowserFetchWithRetry(), | ||
DefaultParse()); | ||
|
||
if (props?.baseUrl) { | ||
|
||
// we want to fix up the url first | ||
instance.on.pre.prepend(async (url, init, result) => { | ||
|
||
if (!isUrlAbsolute(url)) { | ||
url = combine(props.baseUrl, url); | ||
} | ||
|
||
return [url, init, result]; | ||
}); | ||
} | ||
|
||
return instance; | ||
}; | ||
} |
This file contains 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
This file contains 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