I have a GraphQL+- query in which I want to get mutual friends of two people. But I really couldn't find any option to use some sort of intersection of two graphs... can someone help me? Here is my code:
{
catarinas_friends(func: eq(name, "Catarina"))
{
friend
{
name
}
}
michaels_friends(func: eq(name, "Michael")) {
friend
{
name
}
}
# I want to intersect those two
}
This works for you?
{
var(func: eq(name#., "Michael")) {
MF as friend
}
var(func: eq(name#., "Amit")) {
CF as friend
}
in_common(func: uid(MF)) #filter(uid(CF)){
name#.
}
}
with this dataset https://tour.dgraph.io/master/intro/4/
You can have the common friends.
You can also use K-Shortest Path Queries
The middle one in the response is the closest common entity.
Related
With strapi GraphQL it is possible to limit the number of returned entries. However, is it also possible to limit the number of returned subentries? For example, if I have "galleries" content type with a field called "images", can I limit the number of Images returned?
This is what I tried and works:
query mainQuery {
galleries(limit: 1) {
name
image {
url
id
}
}
}
And this is what I would actually like to do but does not work. There is no error or anything but the query returns all results, not just 1:
query mainQuery {
galleries {
name
image(limit: 1) {
url
id
}
}
}
I would like to fetch all galleries but only one image in each of them. Can anybody help me solve this?
I want to find all users that have set their "Company" field in their Github Homepage to "Github". I see it is a defined field in the Github Docs at https://developer.github.com/v4/object/user/. However, I can't seem to search for it.
My current query on https://developer.github.com/v4/explorer/ returns no results
{
search(query: "company:Github", type: USER, first: 100) {
userCount
edges {
node {
... on User {
login
name
company
}
}
}
}
}
To search all users by the company, query on the organization. Currently, you are passing a key-value pair as a string to search for instead of value string. Try this query to get all list of employees who have set their company name Github.
{
organization(login: "github") {
email
members(first: 100) {
totalCount
nodes {
... on User {
company
login
name
isEmployee
}
}
}
}
}
See the results in the attached image:
How can I get info about specific user or specific repo using github GraphQL? I've try this query:
{
search (query: "torvalds", type: USER, first: 1){
edges {
node {
}
}
}
}
but autocomplete for node show only __typename which return string "User".
DEMO
search returns a SearchResultItem, which is an interface. In order to access fields on it, you need to use a fragment on a concrete type like so:
{
search (query: "torvalds", type: USER, first: 1){
edges {
node {
... on User {
login
}
}
}
}
}
I made a short video tour of GitHub's GraphQL API which you might find useful: https://youtu.be/6xO87LlijoQ
EDIT: If you're just looking for a user or org and know the exact name, #stubailo's answer is actually better. You'll still need to use a fragment for most fields, but you'll get just one result of type RepositoryOwner.
The best way to get information about a specific user is to use the repositoryOwner query, like so:
{
repositoryOwner(login: "stubailo") {
login
... on User {
bio
}
}
}
Search is good too, but if you know the name of a user or organization, it's more direct to use the query above.
I am trying to use facebook api to get my friends' relationship status:
FB.api("/me/friends", {
fields: "id, name, relationship_status, significant_other, picture.type(large)"
}, function (response) {
if (response.data) {
...
$.each(response.data, function (index, data) {
if (data.significant_other) {
// If has a significant other
} else {
// If do not have a significant other
}
});
}
});
I tried to determine if a friend has a significant other by looking at the significant_other field. But how can I know if my friend has a significant other but doesn't want to disclose?
I have a solution. If relationship_status equals "In a relationship" but data.significant_other is not in the data. Then that means the friend has a significant_other but does not want to disclose.
If data isn't accessible via the API, there's no way to access that data via the API
This is pretty much a tautology, but if the data were accessible to you, you'd have it via the API call you just included in your question
I'd like to specify two user id's in SoundCloud's SC.get('/tracks') function. Is this possible?
something like this:
function getTracks() {
SC.get('/tracks', {
user_ids: {user_id: 00001, user_id: 000002}
}, function(tracks) {
// build a list of tracks from the two soundcloud users
});
}
It is not possible to filter the /tracks endpoint on user. Sorry!
The closest thing you can do is grab the tracks for each user individually:
SC.get('/users/<user_id>/tracks', function(tracks) {
...
});
So you could do two calls to SC.get() and combine the results.