Listing friends of one of my friends

Hi!

I’m having some problems trying to develop the code to list the friends of one friend. I figured this would be possible as when you go to someone’s URL https://pod.solid.community/profile/card#me you can see all their friends. I manage to do the exact same thing on my application. Is there any source code that i can reuse or look at as inspiration? Or can someone explain to me how to do this?

Thank you so much. :relaxed::heart:

What kinds of tools or code are you using to try and accomplish this?

Using LDFlex the code to get someone’s friends is very simple:

solid.data["http://webid-goes-here"].friends

This returns a list of the webIDs of that user’s friends (if they have any). Example can be seen here.

I didn’t know about this tool. I was trying to do it using the rdf lib, developing in Typescript / Angular. Is there any way of doing it using the rdf lib? If not i will just install ldflex.

Thanks!!

Just tried to install solid ldflex with npm install @solid/query-ldflex and it throws an error trying to access a repo called gwicke/web-streams-polyfill

I’m sure there is, but I’m not sure what it would be off the top of my head. LDFlex is a great tool for getting started in my opinion, as it simplifies a lot of the overhead of tools like rdflib.js. It still has the Subject-Predicate setup, it just makes it easier to read and write.

(side note: I looked up rdflib, as it’s been a while, and I think you’d need to set up a fetcher object, then load up the data like so: )

fetcher.load(webId).then(response => {
      let friend = store.any(me, FOAF(‘knows’));
     console.log(`Loaded {$friend || ‘no friends?’}`);
   }, err => {
      console.log(“Load failed “ +  err);
   });

Then you have the friend webId and you can do the same thing with their webId, or query for some other predicate.

If you’re not too react-adverse, we do have a Solid React SDK that comes with some sample code and LDFlex integration already baked into it (for the quickest start, we have a yeoman generator for a Solid React sample app). It doesn’t have a friends example (yet) but it does get you started.

I will just go with de solid ldflex option as it seems easier to understand. But i cant manage to install it using npm install @solid/query-ldflex

Are you getting an error? If so can you paste it here?

Here’s an example using solid-file-client. The fetchAndParse method returns an rdflib indexedGraph object so the code following it would work in straight rdflib as well:

async function main(){
    let profile = "https://jeffz.solid.community/profile/card"
    let store   = await fc.fetchAndParse(profile)
    let knows   = store.sym("http://xmlns.com/foaf/0.1/knows")
    let name    = store.sym("http://xmlns.com/foaf/0.1/name")
    let me      = store.sym( profile + "#me" )
    let friends = store.each( me, knows )
    friends.forEach( friend => {
        let friendsName = store.any( friend, name )
        if(typeof friendsName !="undefined"){
            console.log( freindsName.value )
        }
    })
}

1 Like

looks like this

That looks like a problem with github rather than the specific repo - are you behind a firewall or otherwise unable to install other packages? The error seems to indicate npm can’t connect to github.com

Fixed it, thanks!! I will come back here if i end up having more questions. :heart:

3 Likes

thanks!! Will try this as well

Hi again!

Trying to use this option, i include the solid-file-client in my project with npm install solid-file-client. I initialize it as const fileClient = require(‘solid-file-client’), having require previously declared as require: any as im using typescript. Anyhow, i get this error:

It is strange as im doing exactly the same as in one of my previous projects and this didnt happen. In the previous project i had the 0.4.9 and in this one it is the 0.5.1.

Any help? thanks!!!

Oh darn, that null keeps causing me problems :-). I suggest you revert to 0.4.9 for the time being. I and my collaborators are working on 1.0.0 so I’m unlikely to fix 0.5.1, perhaps I’ll remove it. @bourgeoa, any thoughts?

Personally I would use webpack with null-loader. I haven’t seen anything against it. I can prepare a normal v0.5.2

I already use it like that in a special version with rdflib and solid-auth-client as externals

1 Like

@bourgeoa You mean that we should use null-loader or the user should? If us using it would solve this, yes, please prepare a v0.5.2.

v0.5.2 Done, build Ok tested with solid-ide OK, pushed to npm 0.5.2
Should solve the null module not found error encountered here and with react solid.

@sofimrtn can you confirm ?

2 Likes

Great work @bourgeoa, thanks! And @sofimrtn - thanks for testing!

Hi again!!

Just tried version 0.5.2 and it doesn’t compile:

Doing the same with 0.4.9 works fine.

And another thing, trying your piece of code for listing friends, the last line (where i get the node values, store.any( friend, name ).value ) gives me an error i cannot understand. When I try to get the actual value of the node it prints out “Can’t get value of undefined”, but the list of friends is correct. It is actually defined as in the array you can find the correct info:

Thank you again!! :relaxed::heart:

I would stick with 0.4.9.

As for the undefined value - if store methods such as any() do not find anything, they returned undefined so it is actually bad practice to directly print the value as I did. Better to first check if any() returned something and then print the value. But, then we ask, why didn’t it get something. My guess is that you do not have a foaf:name field in your profile for the records for the people you know. It can only find fields that exist :-). If that turns out not to be the problem, come on back.