Skip to content

Commit cafac45

Browse files
author
Carlos Rufo
authored
Merge pull request #74 from swcarlosrj/develop
Update source code based on the latest docs
2 parents 384f1ec + 9582e18 commit cafac45

File tree

9 files changed

+1110
-1128
lines changed

9 files changed

+1110
-1128
lines changed

package.json

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@
33
"version": "0.1.0",
44
"private": true,
55
"dependencies": {
6-
"apollo-boost": "^0.1.4",
7-
"apollo-link-context": "^1.0.7",
8-
"apollo-link-ws": "^1.0.7",
9-
"graphql": "^0.13.1",
10-
"react": "^16.2.0",
11-
"react-apollo": "^2.1.0",
12-
"react-dom": "^16.2.0",
13-
"react-router": "^4.2.0",
14-
"react-router-dom": "^4.2.2",
6+
"apollo-boost": "0.1.4",
7+
"apollo-link-context": "1.0.7",
8+
"apollo-link-ws": "1.0.7",
9+
"graphql": "0.13.1",
10+
"react": "16.2.0",
11+
"react-apollo": "2.1.0",
12+
"react-dom": "16.2.0",
13+
"react-router": "4.2.0",
14+
"react-router-dom": "4.2.2",
1515
"react-scripts": "1.1.1",
16-
"subscriptions-transport-ws": "^0.9.7"
16+
"subscriptions-transport-ws": "0.9.7"
1717
},
1818
"scripts": {
1919
"start": "react-scripts start",

server/src/generated/prisma-client/index.d.ts

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
1-
// Code generated by Prisma (prisma@1.22.2). DO NOT EDIT.
1+
// Code generated by Prisma (prisma@1.23.0). DO NOT EDIT.
22
// Please don't change this file manually but run `prisma generate` to update it.
33
// For more information, please read the docs: https://www.prisma.io/docs/prisma-client/
44

5-
import { DocumentNode, GraphQLSchema } from "graphql";
6-
import { makePrismaClientClass, BaseClientOptions } from "prisma-client-lib";
5+
import { DocumentNode } from "graphql";
6+
import {
7+
makePrismaClientClass,
8+
BaseClientOptions,
9+
Model
10+
} from "prisma-client-lib";
711
import { typeDefs } from "./prisma-schema";
812

9-
type AtLeastOne<T, U = { [K in keyof T]: Pick<T, K> }> = Partial<T> &
13+
export type AtLeastOne<T, U = { [K in keyof T]: Pick<T, K> }> = Partial<T> &
1014
U[keyof U];
1115

1216
export interface Exists {
@@ -785,7 +789,10 @@ export interface VotePreviousValuesSubscription
785789
id: () => Promise<AsyncIterator<ID_Output>>;
786790
}
787791

788-
export interface UserConnection {}
792+
export interface UserConnection {
793+
pageInfo: PageInfo;
794+
edges: UserEdge[];
795+
}
789796

790797
export interface UserConnectionPromise
791798
extends Promise<UserConnection>,
@@ -803,7 +810,10 @@ export interface UserConnectionSubscription
803810
aggregate: <T = AggregateUserSubscription>() => T;
804811
}
805812

806-
export interface LinkConnection {}
813+
export interface LinkConnection {
814+
pageInfo: PageInfo;
815+
edges: LinkEdge[];
816+
}
807817

808818
export interface LinkConnectionPromise
809819
extends Promise<LinkConnection>,
@@ -946,6 +956,7 @@ export interface AggregateVoteSubscription
946956
}
947957

948958
export interface LinkEdge {
959+
node: Link;
949960
cursor: String;
950961
}
951962

@@ -961,7 +972,10 @@ export interface LinkEdgeSubscription
961972
cursor: () => Promise<AsyncIterator<String>>;
962973
}
963974

964-
export interface VoteConnection {}
975+
export interface VoteConnection {
976+
pageInfo: PageInfo;
977+
edges: VoteEdge[];
978+
}
965979

966980
export interface VoteConnectionPromise
967981
extends Promise<VoteConnection>,
@@ -981,7 +995,9 @@ export interface VoteConnectionSubscription
981995

982996
export interface UserSubscriptionPayload {
983997
mutation: MutationType;
984-
updatedFields?: String[];
998+
node: User;
999+
updatedFields: String[];
1000+
previousValues: UserPreviousValues;
9851001
}
9861002

9871003
export interface UserSubscriptionPayloadPromise
@@ -1003,6 +1019,7 @@ export interface UserSubscriptionPayloadSubscription
10031019
}
10041020

10051021
export interface UserEdge {
1022+
node: User;
10061023
cursor: String;
10071024
}
10081025

@@ -1063,7 +1080,9 @@ export interface LinkPreviousValuesSubscription
10631080

10641081
export interface LinkSubscriptionPayload {
10651082
mutation: MutationType;
1066-
updatedFields?: String[];
1083+
node: Link;
1084+
updatedFields: String[];
1085+
previousValues: LinkPreviousValues;
10671086
}
10681087

10691088
export interface LinkSubscriptionPayloadPromise
@@ -1156,7 +1175,9 @@ export interface PageInfoSubscription
11561175

11571176
export interface VoteSubscriptionPayload {
11581177
mutation: MutationType;
1159-
updatedFields?: String[];
1178+
node: Vote;
1179+
updatedFields: String[];
1180+
previousValues: VotePreviousValues;
11601181
}
11611182

11621183
export interface VoteSubscriptionPayloadPromise
@@ -1210,6 +1231,7 @@ export interface AggregateUserSubscription
12101231
}
12111232

12121233
export interface VoteEdge {
1234+
node: Vote;
12131235
cursor: String;
12141236
}
12151237

@@ -1262,7 +1284,7 @@ export type Boolean = boolean;
12621284
* Model Metadata
12631285
*/
12641286

1265-
export const models = [
1287+
export const models: Model[] = [
12661288
{
12671289
name: "Link",
12681290
embedded: false

server/src/resolvers/Mutation.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,9 @@ const jwt = require('jsonwebtoken')
33
const { APP_SECRET, getUserId } = require('../utils')
44

55
function post(parent, args, context) {
6-
const userId = getUserId(context)
76
return context.prisma.createLink({
87
url: args.url,
98
description: args.description,
10-
postedBy: { connect: { id: userId } },
119
})
1210
}
1311

src/components/LinkList.js

Lines changed: 33 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -31,20 +31,18 @@ export const FEED_QUERY = gql`
3131
const NEW_LINKS_SUBSCRIPTION = gql`
3232
subscription {
3333
newLink {
34-
node {
34+
id
35+
url
36+
description
37+
createdAt
38+
postedBy {
3539
id
36-
url
37-
description
38-
createdAt
39-
postedBy {
40-
id
41-
name
42-
}
43-
votes {
40+
name
41+
}
42+
votes {
43+
id
44+
user {
4445
id
45-
user {
46-
id
47-
}
4846
}
4947
}
5048
}
@@ -54,28 +52,26 @@ const NEW_LINKS_SUBSCRIPTION = gql`
5452
const NEW_VOTES_SUBSCRIPTION = gql`
5553
subscription {
5654
newVote {
57-
node {
55+
id
56+
link {
5857
id
59-
link {
58+
url
59+
description
60+
createdAt
61+
postedBy {
6062
id
61-
url
62-
description
63-
createdAt
64-
postedBy {
65-
id
66-
name
67-
}
68-
votes {
69-
id
70-
user {
71-
id
72-
}
73-
}
63+
name
7464
}
75-
user {
65+
votes {
7666
id
67+
user {
68+
id
69+
}
7770
}
7871
}
72+
user {
73+
id
74+
}
7975
}
8076
}
8177
`
@@ -90,7 +86,7 @@ class LinkList extends Component {
9086
const orderBy = isNewPage ? 'createdAt_DESC' : null
9187
const data = store.readQuery({
9288
query: FEED_QUERY,
93-
variables: { first, skip, orderBy }
89+
variables: { first, skip, orderBy },
9490
})
9591

9692
const votedLink = data.feed.links.find(link => link.id === linkId)
@@ -103,25 +99,26 @@ class LinkList extends Component {
10399
document: NEW_LINKS_SUBSCRIPTION,
104100
updateQuery: (prev, { subscriptionData }) => {
105101
if (!subscriptionData.data) return prev
106-
const newLink = subscriptionData.data.newLink.node
102+
const newLink = subscriptionData.data.newLink
103+
const exists = prev.feed.links.find(({ id }) => id === newLink.id)
104+
if (exists) return prev
107105

108106
return Object.assign({}, prev, {
109107
feed: {
110108
links: [newLink, ...prev.feed.links],
111109
count: prev.feed.links.length + 1,
112-
__typename: prev.feed.__typename
113-
}
110+
__typename: prev.feed.__typename,
111+
},
114112
})
115-
}
113+
},
116114
})
117115
}
118116

119117
_subscribeToNewVotes = subscribeToMore => {
120118
subscribeToMore({
121-
document: NEW_VOTES_SUBSCRIPTION
119+
document: NEW_VOTES_SUBSCRIPTION,
122120
})
123121
}
124-
125122
_getQueryVariables = () => {
126123
const isNewPage = this.props.location.pathname.includes('new')
127124
const page = parseInt(this.props.match.params.page, 10)
@@ -141,7 +138,6 @@ class LinkList extends Component {
141138
rankedLinks.sort((l1, l2) => l2.votes.length - l1.votes.length)
142139
return rankedLinks
143140
}
144-
145141
_nextPage = data => {
146142
const page = parseInt(this.props.match.params.page, 10)
147143
if (page <= data.feed.count / LINKS_PER_PAGE) {
@@ -202,4 +198,4 @@ class LinkList extends Component {
202198
}
203199
}
204200

205-
export default LinkList
201+
export default LinkList

src/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ import React from 'react'
22
import ReactDOM from 'react-dom'
33
import './styles/index.css'
44
import App from './components/App'
5-
import registerServiceWorker from './registerServiceWorker'
5+
import * as serviceWorker from './serviceWorker'
66
import { ApolloProvider } from 'react-apollo'
77
import { ApolloClient } from 'apollo-client'
88
import { createHttpLink } from 'apollo-link-http'
99
import { InMemoryCache } from 'apollo-cache-inmemory'
1010
import { BrowserRouter } from 'react-router-dom'
11-
import { AUTH_TOKEN } from './constants'
1211
import { setContext } from 'apollo-link-context'
12+
import { AUTH_TOKEN } from './constants'
1313
import { split } from 'apollo-link'
1414
import { WebSocketLink } from 'apollo-link-ws'
1515
import { getMainDefinition } from 'apollo-utilities'
@@ -60,4 +60,4 @@ ReactDOM.render(
6060
</BrowserRouter>,
6161
document.getElementById('root'),
6262
)
63-
registerServiceWorker()
63+
serviceWorker.unregister()

0 commit comments

Comments
 (0)