Skip to main content
Version: 1.0.0

getGraph

@spartanfx/react v1.0.0


@spartanfx/react / getGraph

Function: getGraph()

getGraph(context?): GraphFI

Retrieves or initializes a PnPjs GraphFI instance for Microsoft Graph API operations.

Parameters

context?

WebPartContext

Optional SPFx web part context. If provided, initializes or re-initializes the GraphFI instance.

Returns

GraphFI

A configured GraphFI instance for interacting with Microsoft Graph.

Remarks

  • The instance is created only once per provided SPFx context and reused afterwards.
  • Requires the @pnp/graph and @pnp/logging packages.
  • The instance is configured using the graphSPFx behavior with the provided context.

Call this function with a WebPartContext during initialization. Subsequent calls without parameters return the same initialized instance.

Example

// Initialize GraphFI instance
const graph = getGraph(this.context);

// Query Microsoft Graph for current user
const me = await graph.me();

// Reuse previously initialized instance
const graphInstance = getGraph();