Skip to content

Commit

Permalink
Halfway through shared queries
Browse files Browse the repository at this point in the history
  • Loading branch information
brianlovin committed Jan 17, 2018
1 parent a0564b4 commit a0bf364
Show file tree
Hide file tree
Showing 17 changed files with 288 additions and 249 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ test-extend.js
stats.json
iris/.env
.expo
mobile/.expo
12 changes: 6 additions & 6 deletions mobile/.expo/packager-info.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"expoServerPort": 19000,
"packagerPort": 19001,
"packagerPid": 889,
"expoServerNgrokUrl": "https://ph-tqm.brianlovin.mobile.exp.direct",
"packagerNgrokUrl": "https://packager.ph-tqm.brianlovin.mobile.exp.direct",
"ngrokPid": 913
"expoServerPort": null,
"packagerPort": null,
"packagerPid": null,
"expoServerNgrokUrl": null,
"packagerNgrokUrl": null,
"ngrokPid": null
}
26 changes: 0 additions & 26 deletions mobile/gql/channel/queries/getChannel.js

This file was deleted.

8 changes: 4 additions & 4 deletions mobile/views/Channel/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// @flow
import * as React from 'react';
import { Text, View, FlatList } from 'react-native';
import { Text, View } from 'react-native';
import compose from 'recompose/compose';
import getChannelById from '../../gql/channel/queries/getChannel';
import getChannelThreads from '../../gql/channel/queries/getChannelThreads';
import { getChannelById } from 'shared/graphql/queries/channel/getChannel';
import getChannelThreadConnection from 'shared/graphql/queries/channel/getChannelThreadConnection';
import ViewNetworkHandler from '../../components/ViewNetworkHandler';
import withSafeView from '../../components/SafeAreaView';
import ThreadFeed from '../../components/ThreadFeed';
Expand Down Expand Up @@ -34,7 +34,7 @@ type Props = {
},
};

const ChannelThreadFeed = compose(getChannelThreads)(ThreadFeed);
const ChannelThreadFeed = compose(getChannelThreadConnection)(ThreadFeed);

class Channel extends React.Component<Props> {
render() {
Expand Down
7 changes: 6 additions & 1 deletion shared/graphql/fragments/channel/channelMemberConnection.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,20 @@ import userInfoFragment from '../user/userInfo';

export default gql`
fragment channelMemberConnection on Channel {
memberConnection {
memberConnection(after: $after) {
pageInfo {
hasNextPage
hasPreviousPage
}
edges {
cursor
node {
...userInfo
isPro
contextPermissions {
communityId
reputation
}
}
}
}
Expand Down
74 changes: 74 additions & 0 deletions shared/graphql/queries/channel/getChannel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// @flow
import { graphql } from 'react-apollo';
import gql from 'graphql-tag';
import channelInfoFragment from 'shared/graphql/fragments/channel/channelInfo';
import channelMetaDataFragment from 'shared/graphql/fragments/channel/channelMetaData';

const getChannelByIdQuery = gql`
query getChannel($id: ID) {
channel(id: $id) {
...channelInfo
...channelMetaData
}
}
${channelInfoFragment}
${channelMetaDataFragment}
`;

const getChannelByIdOptions = {
options: ({ id }) => ({
variables: {
id,
},
}),
};

export const getChannelById = graphql(
getChannelByIdQuery,
getChannelByIdOptions
);

/*
Alternative implementation that takes a channel slug and community slug
to perform a lookup
Used to check for duplicate channel names during channel creation, and can
be used as a way to get a channel based on url params.
*/
const getChannelBySlugAndCommunitySlugQuery = gql`
query getChannel($channelSlug: String, $communitySlug: String) {
channel(channelSlug: $channelSlug, communitySlug: $communitySlug) {
...channelInfo
...channelMetaData
}
}
${channelInfoFragment}
${channelMetaDataFragment}
`;

const getChannelBySlugAndCommunitySlugOptions = {
options: ({ channelSlug, communitySlug }) => ({
variables: {
channelSlug: channelSlug.toLowerCase(),
communitySlug: communitySlug.toLowerCase(),
},
}),
};

export const getChannelBySlugAndCommunitySlug = graphql(
getChannelBySlugAndCommunitySlugQuery,
getChannelBySlugAndCommunitySlugOptions
);

const getChannelByMatchOptions = {
options: ({ match: { params: { channelSlug, communitySlug } } }) => ({
variables: {
channelSlug: channelSlug.toLowerCase(),
communitySlug: communitySlug.toLowerCase(),
},
}),
};

export const getChannelByMatch = graphql(
getChannelBySlugAndCommunitySlugQuery,
getChannelByMatchOptions
);
34 changes: 34 additions & 0 deletions shared/graphql/queries/channel/getChannelBlockedUsers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// @flow
import { graphql } from 'react-apollo';
import gql from 'graphql-tag';
import userInfoFragment from 'shared/graphql/fragments/user/userInfo';
import communityInfoFragment from 'shared/graphql/fragments/community/communityInfo';
import channelInfoFragment from 'shared/graphql/fragments/channel/channelInfo';

export const getChannelBlockedUsersQuery = gql`
query getChannelBlockedUsers($id: ID) {
channel(id: $id) {
...channelInfo
blockedUsers {
...userInfo
}
}
}
${userInfoFragment}
${communityInfoFragment}
${channelInfoFragment}
`;

const getChannelBlockedUsersOptions = {
options: ({ id }) => ({
variables: {
id,
},
fetchPolicy: 'cache-and-network',
}),
};

export default graphql(
getChannelBlockedUsersQuery,
getChannelBlockedUsersOptions
);
91 changes: 91 additions & 0 deletions shared/graphql/queries/channel/getChannelMemberConnection.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
// @flow
import { graphql } from 'react-apollo';
import gql from 'graphql-tag';
import channelInfoFragment from 'shared/graphql/fragments/channel/channelInfo';
import channelMetaDataFragment from 'shared/graphql/fragments/channel/channelMetaData';
import channelMemberConnectionFragment from 'shared/graphql/fragments/channel/channelMemberConnection';

const getChannelMemberConnectionQuery = gql`
query getChannelMemberConnection($id: ID, $after: String) {
channel(id: $id) {
...channelInfo
...channelMetaData
...channelMemberConnection
}
}
${channelInfoFragment}
${channelMetaDataFragment}
${channelMemberConnectionFragment}
`;

const LoadMoreMembers = gql`
query loadMoreChannelMembers($id: ID, $after: String) {
channel(id: $id) {
...channelInfo
...channelMetaData
...channelMemberConnection
}
}
${channelInfoFragment}
${channelMetaDataFragment}
${channelMemberConnectionFragment}
`;

const getChannelMemberConnectionOptions = {
props: ({ data: { fetchMore, error, loading, channel, networkStatus } }) => ({
data: {
error,
loading,
channel,
networkStatus: networkStatus,
hasNextPage: channel
? channel.memberConnection.pageInfo.hasNextPage
: false,
fetchMore: () =>
fetchMore({
query: LoadMoreMembers,
variables: {
id: channel.id,
after:
channel.memberConnection.edges[
channel.memberConnection.edges.length - 1
].cursor,
},
updateQuery: (prev, { fetchMoreResult }) => {
if (!fetchMoreResult.channel) {
return prev;
}

return {
...prev,
channel: {
...prev.channel,
memberConnection: {
...prev.channel.memberConnection,
pageInfo: {
...prev.channel.memberConnection.pageInfo,
...fetchMoreResult.channel.memberConnection.pageInfo,
},
edges: [
...prev.channel.memberConnection.edges,
...fetchMoreResult.channel.memberConnection.edges,
],
},
},
};
},
}),
},
}),
options: ({ id }) => ({
variables: {
id,
},
fetchPolicy: 'cache-and-network',
}),
};

export default graphql(
getChannelMemberConnectionQuery,
getChannelMemberConnectionOptions
);
32 changes: 32 additions & 0 deletions shared/graphql/queries/channel/getChannelPendingUsers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// @flow
import { graphql } from 'react-apollo';
import gql from 'graphql-tag';
import userInfoFragment from 'shared/graphql/fragments/user/userInfo';
import channelInfoFragment from 'shared/graphql/fragments/channel/channelInfo';

const getChannelPendingUsersQuery = gql`
query getChannelPendingUsers($id: ID) {
channel(id: $id) {
...channelInfo
pendingUsers {
...userInfo
}
}
}
${userInfoFragment}
${channelInfoFragment}
`;

const getChannelPendingUsersOptions = {
options: ({ id }) => ({
variables: {
id,
},
fetchPolicy: 'cache-and-network',
}),
};

export default graphql(
getChannelPendingUsersQuery,
getChannelPendingUsersOptions
);
Loading

0 comments on commit a0bf364

Please sign in to comment.