Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better GraphQL (FOR REFERENCE) #1076

Draft
wants to merge 15 commits into
base: fix-sass
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions graphql.config.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"schema": "https://www.hylo.com/noo/graphql",
"documents": "src/components/**/*.js",
"schema": "http://localhost:3001/noo/graphql",
"documents": "/src/**/*.js",
"extension": {
"endpoints": {
"default": {
"url": "https://www.hylo.com/noo/graphql"
"url": "http://localhost:3001/noo/graphql"
}
}
}
Expand Down
40 changes: 21 additions & 19 deletions src/components/CreateGroup/CreateGroup.store.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import orm from 'store/models'
import { createSelector as ormCreateSelector } from 'redux-orm'
import { AnalyticsEvents } from 'hylo-utils/constants'
import gql from 'graphql-tag'

export const MODULE_NAME = `CreateGroup`
export const ADD_GROUP_NAME = `${MODULE_NAME}/ADD_GROUP_NAME`
Expand Down Expand Up @@ -69,8 +70,8 @@ export function fetchGroupExists (slug) {
return {
type: FETCH_GROUP_EXISTS,
graphql: {
query: `
query ($slug: String) {
query: gql`
query GroupExists($slug: String) {
groupExists (slug: $slug) {
exists
}
Expand All @@ -87,28 +88,29 @@ export function createGroup (data) {
return {
type: CREATE_GROUP,
graphql: {
query: `mutation ($data: GroupInput) {
createGroup(data: $data) {
id
hasModeratorRole
group {
query: gql`
mutation CreateGroup($data: GroupInput) {
createGroup(data: $data) {
id
name
slug
parentGroups {
items {
id
hasModeratorRole
group {
id
name
slug
parentGroups {
items {
id
}
}
}
}
person {
id
}
settings {
showJoinForm
person {
id
}
settings {
showJoinForm
}
}
}
}
`,
variables: {
data
Expand Down
49 changes: 27 additions & 22 deletions src/components/CreateTopic/CreateTopic.store.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { get, omit } from 'lodash/fp'
import gql from 'graphql-tag'
import { AnalyticsEvents } from 'hylo-utils/constants'

export const MODULE_NAME = 'CreateTopic'
Expand All @@ -9,11 +10,13 @@ export function fetchGroupTopic (topicName, groupSlug) {
return {
type: FETCH_GROUP_TOPIC,
graphql: {
query: `query ($topicName: String, $groupSlug: String) {
groupTopic(groupSlug: $groupSlug, topicName: $topicName) {
id
query: gql`
query GroupTopic($topicName: String, $groupSlug: String) {
groupTopic(groupSlug: $groupSlug, topicName: $topicName) {
id
}
}
}`,
`,
variables: {
groupSlug,
topicName
Expand All @@ -30,29 +33,31 @@ export function createTopic (topicName, groupId, isDefault = false, isSubscribin
return {
type: CREATE_TOPIC,
graphql: {
query: `mutation ($topicName: String, $groupId: ID, $isDefault: Boolean, $isSubscribing: Boolean) {
createTopic(topicName: $topicName, groupId: $groupId, isDefault: $isDefault, isSubscribing: $isSubscribing) {
id
name
groupTopics {
items {
id
group {
query: gql`
mutation CreateTopic($topicName: String, $groupId: ID, $isDefault: Boolean, $isSubscribing: Boolean) {
createTopic(topicName: $topicName, groupId: $groupId, isDefault: $isDefault, isSubscribing: $isSubscribing) {
id
name
groupTopics {
items {
id
slug
group {
id
slug
}
isDefault
isSubscribed
newPostCount
postsTotal
followersTotal
visibility
}
isDefault
isSubscribed
newPostCount
postsTotal
followersTotal
visibility
}
followersTotal
postsTotal
}
followersTotal
postsTotal
}
}`,
`,
variables: {
groupId,
topicName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@
exports[`matches the last snapshot for createTopic 1`] = `
Object {
"graphql": Object {
"query": "mutation ($topicName: String, $groupId: ID, $isDefault: Boolean, $isSubscribing: Boolean) {
createTopic(topicName: $topicName, groupId: $groupId, isDefault: $isDefault, isSubscribing: $isSubscribing) {
"query": "mutation CreateTopic($topicName: String, $groupId: ID, $isDefault: Boolean, $isSubscribing: Boolean) {
createTopic(
topicName: $topicName
groupId: $groupId
isDefault: $isDefault
isSubscribing: $isSubscribing
) {
id
name
groupTopics {
Expand Down Expand Up @@ -58,7 +63,7 @@ Object {
exports[`matches the last snapshot for fetchGroupTopic 1`] = `
Object {
"graphql": Object {
"query": "query ($topicName: String, $groupSlug: String) {
"query": "query GroupTopic($topicName: String, $groupSlug: String) {
groupTopic(groupSlug: $groupSlug, topicName: $topicName) {
id
}
Expand Down
31 changes: 17 additions & 14 deletions src/components/EventInviteDialog/EventInviteDialog.store.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { createSelector } from 'redux-orm'
import orm from 'store/models'
import getMe from 'store/selectors/getMe'
import { pick, uniqBy, orderBy, flow, reject, map, reduce } from 'lodash/fp'
import gql from 'graphql-tag'
import getMe from 'store/selectors/getMe'

export const MODULE_NAME = 'EventInviteDialog'
export const INVITE_PEOPLE_TO_EVENT = `${MODULE_NAME}/INVITE_PEOPLE_TO_EVENT`
Expand Down Expand Up @@ -36,24 +37,26 @@ export function invitePeopleToEvent (eventId, inviteeIds) {
return {
type: INVITE_PEOPLE_TO_EVENT,
graphql: {
query: `mutation ($eventId: ID, $inviteeIds: [ID]) {
invitePeopleToEvent(eventId: $eventId, inviteeIds: $inviteeIds) {
id
eventInvitations {
total
hasMore
items {
id
response
person {
query: gql`
mutation InvitePeopleToEvent($eventId: ID, $inviteeIds: [ID]) {
invitePeopleToEvent(eventId: $eventId, inviteeIds: $inviteeIds) {
id
eventInvitations {
total
hasMore
items {
id
name
avatarUrl
response
person {
id
name
avatarUrl
}
}
}
}
}
}`,
`,
variables: { eventId, inviteeIds }
},
meta: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
exports[`invitePeopleToEvent matches snapshot 1`] = `
Object {
"graphql": Object {
"query": "mutation ($eventId: ID, $inviteeIds: [ID]) {
"query": "mutation InvitePeopleToEvent($eventId: ID, $inviteeIds: [ID]) {
invitePeopleToEvent(eventId: $eventId, inviteeIds: $inviteeIds) {
id
eventInvitations {
Expand Down
103 changes: 57 additions & 46 deletions src/components/FeedList/FeedList.store.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { createSelector } from 'reselect'
import { get } from 'lodash/fp'
import gql from 'graphql-tag'
import { FETCH_POSTS } from 'store/constants'
import groupViewPostsQueryFragment from 'graphql/fragments/groupViewPostsQueryFragment'
import postsQueryFragment from 'graphql/fragments/postsQueryFragment'
import GroupViewPostsQueryFragment from 'graphql/fragments/GroupViewPostsQueryFragment'
import PostsQueryFragment from 'graphql/fragments/PostsQueryFragment'
import { makeGetQueryResults, makeQueryResultsModelSelector } from 'store/reducers/queryResults'
export const MODULE_NAME = 'FeedList'
export const STORE_FETCH_POSTS_PARAM = `${MODULE_NAME}/STORE_FETCH_POSTS_PARAM`
Expand All @@ -12,11 +13,11 @@ export function fetchPosts ({ afterTime, beforeTime, context, filter, offset, or
var query, extractModel, getItems

if (context === 'groups') {
query = groupQuery
query = GroupQuery
extractModel = 'Group'
getItems = get('payload.data.group.posts')
} else if (context === 'all' || context === 'public') {
query = postsQuery
query = PostsQuery
extractModel = 'Post'
getItems = get('payload.data.posts')
} else {
Expand Down Expand Up @@ -51,52 +52,62 @@ export function fetchPosts ({ afterTime, beforeTime, context, filter, offset, or
}
}

const groupQuery = `query (
$afterTime: Date,
$beforeTime: Date,
$boundingBox: [PointInput],
$filter: String,
$first: Int,
$offset: Int,
$order: String,
$search: String,
$slug: String,
$sortBy: String,
$topic: ID
) {
group(slug: $slug, updateLastViewed: true) {
id
slug
name
locationObject {
center {
lat
lng
const GroupQuery = gql`
query GroupQuery(
$afterTime: Date,
$beforeTime: Date,
$boundingBox: [PointInput],
$filter: String,
$first: Int,
$offset: Int,
$order: String,
$search: String,
$slug: String,
$sortBy: String,
$topic: ID,
$withComments: Boolean = false
) {
group(slug: $slug, updateLastViewed: true) {
id
slug
name
locationObject {
center {
lat
lng
}
}
avatarUrl
bannerUrl
postCount
...GroupViewPostsQueryFragment
}
avatarUrl
bannerUrl
postCount
${groupViewPostsQueryFragment}
}
}`

const postsQuery = `query (
$afterTime: Date,
$beforeTime: Date,
$boundingBox: [PointInput],
$context: String,
$filter: String,
$first: Int,
$groupSlugs: [String],
$offset: Int,
$order: String,
$search: String,
$sortBy: String,
$topic: ID,
) {
${postsQueryFragment}
}`
${GroupViewPostsQueryFragment}
`

const PostsQuery = gql`
query PostsQuery(
$afterTime: Date,
$beforeTime: Date,
$boundingBox: [PointInput],
$context: String,
$filter: String,
$first: Int,
$groupSlugs: [String],
$offset: Int,
$order: String,
$search: String,
$sortBy: String,
$topic: ID,
$withComments: Boolean = false
) {
...PostsQueryFragment
}

${PostsQueryFragment}
`

export function storeFetchPostsParam (props) {
return {
Expand Down
Loading