4.1.0
It would be necessary to have the context of the search results webpart in the custom web component to be able to call from there to the graph api with the pnp/graph libraries.
Is there any way to get the WebPartContext from the custom web component?
Thank you very much
Calling Graph API's without passing over the full context object should be doable. Why do you need the full context? You should be able to pull in npm packages in your code and run similar calls as in https://github.com/microsoft-search/pnp-modern-search/blob/main/search-parts/src/dataSources/MicrosoftSearchDataSource.ts#L606
For Graph calls, you can simply use the this._serviceScope property from the BaseWebComponent class and consume the service like this:
const msGraphClientFactory = this._serviceScope.consume<MSGraphClientFactory>(MSGraphClientFactory.serviceKey);
const msGraphClient = await msGraphClientFactory.getClient();
Due to technical reasons we can't pass the WebPart context object directly. If you need such properties, you can still pass them as HTML attributes in the web component from the Handlebars context (ex{{@root.context.site.absoluteUrl}}).
Thank you so much. This information resolve my problem!!!
@FranckyC maybe we should add this to the sample?
Good suggestion @wobba , do you have time to add it? ;)
This is related to #958?
@Laul0 not really. This one is more about how to access SPFx webpart context object info inside a webcomponent.
Most helpful comment
For Graph calls, you can simply use the
this._serviceScopeproperty from the BaseWebComponent class and consume the service like this:Due to technical reasons we can't pass the WebPart context object directly. If you need such properties, you can still pass them as HTML attributes in the web component from the Handlebars context (ex
{{@root.context.site.absoluteUrl}}).