Skip to content

Instantly share code, notes, and snippets.

@tavriaforever
Created August 14, 2017 19:57
Show Gist options
  • Save tavriaforever/01a1e0bbb7deb881340f211206549a24 to your computer and use it in GitHub Desktop.
Save tavriaforever/01a1e0bbb7deb881340f211206549a24 to your computer and use it in GitHub Desktop.
const fragmentUser = `
fragment fragmentUser on User {
id
username
email
firstName
lastName
name
avatarLink
phoneNumber
country
city
birthday
isViewer
viewerRequestedFriendship
viewerReceivedFriendship
resourcePath
gender
trips (first: 20) {
totalCount
edges {
node {
id
name
}
}
}
followerCount
}
`;
const fragmentPlace = `
fragment fragmentPlace on Place {
id
name
location {
description
latitude
longitude
}
}
`;
const fragmentTrip = `
fragment fragmentTrip on Trip {
id
name
startDate
endDate
resourcePath
isPrivate
viewerIsSubscriber
viewerHasLiked
likeCount
photoCount
participantCount
cover {
...fragmentMedia
}
participants {
...fragmentUser
},
author {
...fragmentUser
},
place {
...fragmentPlace
}
comments (first: 100) {
totalCount
edges {
node {
id
message
publishTime
author {
id
name
username
avatarLink
}
}
}
}
}
`;
const fragmentMedia = `
fragment fragmentMedia on Media {
id
url
}
`;
const fragmentPublication = `
fragment fragmentPublication on Post {
id
message
isPrivate
likeCount
viewerHasLiked
trip {
id
name
}
photos {
...fragmentMedia
}
participants {
...fragmentUser
},
author {
...fragmentUser
},
place {
...fragmentPlace
}
comments (first: 100) {
totalCount
edges {
node {
id
message
publishTime
author {
id
name
username
avatarLink
}
}
}
}
}
`;
getPosts(token) {
const requestParams = _.assign(baseRequestParams, {
headers: {
Authorization: `Bearer ${token}`,
Accept: 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify({
query: `{
feed {
edges {
hitTime
fact
node {
__typename
... on Trip {
...fragmentTrip
}
... on Post {
...fragmentPublication
}
}
}
}
}
${fragmentPlace}
${fragmentUser}
${fragmentTrip}
${fragmentPublication}
${fragmentMedia}
`,
}),
});
return this.request(graphql, requestParams);
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment