Please specify what version of the library you are using: [^2.0.3]
Please specify what version(s) of SharePoint you are targeting: [Online/O365]
Hey guys, as always, love working with the packages!
I'm using the @pnp/graph-commonjs in a Node w/ TypeScript Azure Function. And discovered a requirement to include a call to the /domains endpoint of the graph and couldn't find the functionality implemented within the graph package.
My quick & dirty (_shit-_) fix was the following:
let originalUrl = graph.data.url;
graph.append("/domains");
let domains: string[] = (await graph.select("id").get()).map((domain) => domain.id);
context.log("Domains: ", domains);
graph.data.url = originalUrl;
Now, I am fairly certain that this would be frowned upon and would like to seek your guidance as to how I might better accomplish this.
I had a look at extensions but didn't quite figure out how to use them for this purpose. I also dove fairly deep into the source code and am becoming quite keen to contribute myself ๐ However, before I feel confident doing that, I'd greatly appreciate if someone familiar with the structure of the packages could take some time and chat about it and fill me in on some of the parts I don't quite understand.
I've been dev-ing with the packages since the release of the SP Framework at work alongside finishing my BSc degree last year and would love to finally contribute to the project ๐
Follow up: Just bumped into this Invokeables documentation, shouldn't I follow this to fix my (_shit-_) fix?
@Katli95, we are super excited to hear you are interested and willing to contribute. That is awesome!!! ๐งก๐
Unfortunately, we do not have a team size that provides us the ability to set up one-on-one sessions to dive into the architecture of the library.
Although, I wanted to share with you one of the initiatives the PnP team offers around contribution guidance called "Sharing is Caring". You can learn more about the initiative here:
https://aka.ms/sharing-is-caring
We have a growing number of topics that provide hands-on guidance in live group-based sessions focused on contributing to the variety of PnP project initiatives. I encourage you to use the registration form to be notified about the sessions as they are scheduled.
You can register here:
https://forms.microsoft.com/Pages/ResponsePage.aspx?id=KtIy2vgLW0SOgZbwvQuRaXDXyCl9DkBHq4A2OG7uLpdUNzg2STBQVzlIN0FWUjNGMlA2Wk1SWlZQRy4u
We also have an introductory video on PnPjs Library Extensions coming out very soon, which helps provide some examples on how to use Extensions and may help in determining if they would be a good fit for your needs.
@PopWarner Thank you very much for the kind welcome! Form submitted and looking forward to the next session โ
I'll stay tuned for the video on extensions but in the meanwhile I'd appreciate if someone could comment on how fragile my code snippet is before closing the issue ๐
Would I be on the right track using something like the following?
let domains = await graphGet(GraphQueryable(graph), "domains");
If you intend to augment the graph library by submitting a PR then we would want you to follow the processes with regard to how our library is structured. So, in this case, I would say a folder under the packages/graph implementation for domains. Further for every new feature you implement we require a least a basic test implementation, again using our existing structure under the tests/graph folder as well as documentation in the docs/graph.
At this time there are no existing graph tests, the reasoning for which is a long story, but suffice it to say they are being worked on and we should have some coming in the next release with more rolling in as time permits.
Heheh, yes, of course, doing it otherwise wouldn't be much of a contribution. To the contrary, I'd just be adding work for others ๐
However, I'd like to object the addition of the "answered" label, because I'm still not quite sure whether my first code example is intended use, i.e. if it is supported and not subject to braking upon further updates of the library? And if it isn't supported, is my second example any better? ๐ค
// First code example:
let originalUrl = graph.data.url;
graph.append("/domains");
let domains: string[] = (await graph.select("id").get()).map((domain) => domain.id);
context.log("Domains: ", domains);
graph.data.url = originalUrl;
// Second code example:
let domains = await graphGet(GraphQueryable(graph), "domains");
Neither example is how we intend you to use the library, so I can't really say what's "right"... there is no recommended extension for non-implemented endpoints other than contributing.
Thanks for the quick responses throughout the thread @juliemturner!
Regarding your point
"there is no recommended extension for non-implemented endpoints other than contributing."
I'm wondering if I am misunderstanding the statement in the "Other Operations" part of the "Invokables" documentation
"But things get a little more interesting in that you can now do posts (or any of the operations) to any of the urls defined by a fluent chain. Meaning you can easily implement methods that are not yet part of the library."
this is the code demonstrated on the page:
spPost(SharePointQueryable(sp.web.fields, "MagicFieldCreationMethod"), {
body: JSON.stringify({
// ... this would be the post body
}),
});
so upon further inspection I believe my code should be something like:
let domains = await graphGet(GraphQueryable(graph, "domains"));
Am I maybe misunderstanding and that documentation is only relative for the sp package?
I feel like this is similar to whatever is going on in *.types.ts for the implemented endpoints, though not quite identical, because I see they use this.clone(x,y) quite often. Am I correct in thinking that this is somewhat similar to what I'd be doing if I were to add the domains endpoint?
P.s. thank all of you again for responding quickly and guiding me on to understand the library better and preparing me for contributing ๐
I had completely forgotten about the extensions documentation... although I've even spoken on the topic. Yes you should follow that guidance.
Wow 27 minute response time on a Sunday, huge thanks! And again, thanks for the help both of you โ
Look forward to submitting my PR in the next two weeks hopefully!
Looking forward to your contribution @Katli95! ๐งก๐๐๐ป
Most helpful comment
@Katli95, we are super excited to hear you are interested and willing to contribute. That is awesome!!! ๐งก๐
Unfortunately, we do not have a team size that provides us the ability to set up one-on-one sessions to dive into the architecture of the library.
Although, I wanted to share with you one of the initiatives the PnP team offers around contribution guidance called "Sharing is Caring". You can learn more about the initiative here:
https://aka.ms/sharing-is-caring
We have a growing number of topics that provide hands-on guidance in live group-based sessions focused on contributing to the variety of PnP project initiatives. I encourage you to use the registration form to be notified about the sessions as they are scheduled.
You can register here:
https://forms.microsoft.com/Pages/ResponsePage.aspx?id=KtIy2vgLW0SOgZbwvQuRaXDXyCl9DkBHq4A2OG7uLpdUNzg2STBQVzlIN0FWUjNGMlA2Wk1SWlZQRy4u
We also have an introductory video on PnPjs Library Extensions coming out very soon, which helps provide some examples on how to use Extensions and may help in determining if they would be a good fit for your needs.