GraphUserFabric
@spartanfx/react / GraphUserFabric
Class: GraphUserFabric
A utility class for retrieving and caching Microsoft Graph User objects.
Remarks
- This class manages an internal cache of users to minimize repeated Graph API calls.
- If a user is not found in the local cache, it queries Microsoft Graph and adds the result to the cache.
- Provides lookup methods by User Principal Name (UPN) or login name format (e.g.,
i:0#.f|membership|user@domain.com).
Examples
Minimal usage:
const fabric = new GraphUserFabric();
const user = await fabric.getUserByUPN("john.doe@contoso.com");
console.log(user?.givenName); // "John"
Using login name format:
const fabric = new GraphUserFabric();
const user = await fabric.getUserByLoginName("i:0#.f|membership|john.doe@contoso.com");
console.log(user?.surname); // "Doe"
Constructors
Constructor
new GraphUserFabric():
GraphUserFabric
Creates a new instance of GraphUserFabric.
Returns
GraphUserFabric
Remarks
Initializes with an empty user cache. The cache will be populated on demand when lookups are performed.
Methods
getUserByLoginName()
getUserByLoginName(
loginName):Promise<User>
Retrieves a Microsoft Graph user by login name format.
Parameters
loginName
string
The login name string, typically in the format
i:0#.f|membership|user@domain.com.
Returns
Promise<User>
A promise resolving to the GraphUser, or null if no login name is provided.
Remarks
- Splits the login name by
|and uses the last segment as the UPN. - Internally calls getUserByUPN.
Example
const user = await fabric.getUserByLoginName("i:0#.f|membership|alex.smith@contoso.com");
console.log(user?.mobilePhone);
getUserByUPN()
getUserByUPN(
upn):Promise<User>
Retrieves a Microsoft Graph user by UPN, with caching.
Parameters
upn
string
The User Principal Name (e.g., user@domain.com).
Returns
Promise<User>
A promise resolving to the GraphUser, or null if no UPN is provided.
Remarks
- Checks the local cache first before calling Microsoft Graph.
- Returns
nullif the provided UPN is empty or invalid.
Example
const user = await fabric.getUserByUPN("alex.smith@contoso.com");
console.log(user?.employeeId);