使用PNP 3在SPFX中执行通用图形调用

发布于 2025-02-08 07:53:15 字数 1407 浏览 3 评论 0原文

到目前为止,我一直在使用以下内容来执行针对图形API的请求。

import { MSGraphClient } from '@microsoft/sp-http';
const graphClient: MSGraphClient = await context.msGraphClientFactory.getClient();

const uriGetAccessPackageAssignmentRequests = `/identityGovernance/entitlementManagement/accessPackageAssignments/filterByCurrentUser(on='target')?$select=id&$expand=accessPackageAssignmentResourceRoles&$filter=assignmentState ne 'Expired'`;

graphClient.api(uriGetAccessPackageAssignmentRequests).version('beta').get();

直到我决定更改为最新版本(3.4.1)中的 @pnp/Graph之前,这一直没有任何问题。

我可以使用所有预设调用,但是我找不到使用自定义端点执行通用的图形调用的方法。

在他们谈论的所有教程中,

import { graph } from "@pnp/graph";

但是如果这样做,我会收到以下错误 - >模块'“@pnp/graph”'没有导出的成员'图形'。

就像我说的那样,使用文档中所描述的方式

import { graphfi, GraphFI, SPFx as graphSPFx } from '@pnp/graph'
export const getGraph = (context?: WebPartContext): GraphFI => {
  if (_graph === null && context != null) {
    //You must add the @pnp/logging package to include the PnPLogging behavior it is no longer a peer dependency
    // The LogLevel set's at what level a message will be written to the console
    _graph = graphfi().using(graphSPFx(context)).using(PnPLogging(LogLevel.Warning))
  }
  return _graph
}

工作正常。

我只是找不到有关如何使用PNP V3进行自定义端点(如上一个)的任何内容。

谁能在这里提供帮助,或者我必须为此目的坚持使用msgraplclient?

So far I have been using the following to execute a request against the Graph API.

import { MSGraphClient } from '@microsoft/sp-http';
const graphClient: MSGraphClient = await context.msGraphClientFactory.getClient();

const uriGetAccessPackageAssignmentRequests = `/identityGovernance/entitlementManagement/accessPackageAssignments/filterByCurrentUser(on='target')?$select=id&$expand=accessPackageAssignmentResourceRoles&$filter=assignmentState ne 'Expired'`;

graphClient.api(uriGetAccessPackageAssignmentRequests).version('beta').get();

This has been working without any problems until I decided to change to @pnp/graph in the newest version (3.4.1).

I can use all the preset calls, but I cannot find a way to execute a generic graph call with a custom endpoint.

In all the tutorials they talk about

import { graph } from "@pnp/graph";

But if I do so, I get the following error -> Module '"@pnp/graph"' has no exported member 'graph'.

As I said, the described way in the documentation of using

import { graphfi, GraphFI, SPFx as graphSPFx } from '@pnp/graph'
export const getGraph = (context?: WebPartContext): GraphFI => {
  if (_graph === null && context != null) {
    //You must add the @pnp/logging package to include the PnPLogging behavior it is no longer a peer dependency
    // The LogLevel set's at what level a message will be written to the console
    _graph = graphfi().using(graphSPFx(context)).using(PnPLogging(LogLevel.Warning))
  }
  return _graph
}

is working fine.

I just cannot find anything on how to do a custom endpoint (like the one above) with pnp v3.

Can anyone help here or do I have to stick to the MSGraphClient for that purpose?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文