File tree 5 files changed +81
-0
lines changed
5 files changed +81
-0
lines changed Original file line number Diff line number Diff line change @@ -21,6 +21,10 @@ const resolvers = {
21
21
chats ( ) {
22
22
return chats ;
23
23
} ,
24
+
25
+ chat ( root : any , { chatId } : any ) {
26
+ return chats . find ( c => c . id === chatId ) ;
27
+ } ,
24
28
} ,
25
29
} ;
26
30
Original file line number Diff line number Diff line change @@ -17,4 +17,5 @@ type Chat {
17
17
18
18
type Query {
19
19
chats : [Chat ! ]!
20
+ chat (chatId : ID ! ): Chat
20
21
}
Original file line number Diff line number Diff line change
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports [` Query.chat should fetch specified chat 1` ] = `
4
+ Object {
5
+ " chat" : Object {
6
+ " id" : " 1" ,
7
+ " lastMessage" : Object {
8
+ " content" : " You on your way?" ,
9
+ " createdAt" : " 2018-12-31T07:20:00.000Z" ,
10
+ " id" : " 1" ,
11
+ },
12
+ " name" : " Ethan Gonzalez" ,
13
+ " picture" : " https://randomuser.me/api/portraits/thumb/men/1.jpg" ,
14
+ },
15
+ }
16
+ ` ;
Original file line number Diff line number Diff line change
1
+ import { createTestClient } from 'apollo-server-testing' ;
2
+ import { ApolloServer , gql } from 'apollo-server-express' ;
3
+ import schema from '../../schema' ;
4
+
5
+ describe ( 'Query.chat' , ( ) => {
6
+ it ( 'should fetch specified chat' , async ( ) => {
7
+ const server = new ApolloServer ( { schema } ) ;
8
+
9
+ const { query } = createTestClient ( server ) ;
10
+
11
+ const res = await query ( {
12
+ variables : { chatId : '1' } ,
13
+ query : gql `
14
+ query GetChat($chatId: ID!) {
15
+ chat(chatId: $chatId) {
16
+ id
17
+ name
18
+ picture
19
+ lastMessage {
20
+ id
21
+ content
22
+ createdAt
23
+ }
24
+ }
25
+ }
26
+ ` ,
27
+ } ) ;
28
+
29
+ expect ( res . data ) . toBeDefined ( ) ;
30
+ expect ( res . errors ) . toBeUndefined ( ) ;
31
+ expect ( res . data ) . toMatchSnapshot ( ) ;
32
+ } ) ;
33
+ } ) ;
Original file line number Diff line number Diff line change
1
+ declare module 'apollo-server-testing' {
2
+ import { ApolloServerBase } from 'apollo-server-core' ;
3
+ import { print , DocumentNode } from 'graphql' ;
4
+ import { GraphQLResponse } from 'graphql-extensions' ;
5
+
6
+ type StringOrAst = string | DocumentNode ;
7
+
8
+ // A query must not come with a mutation (and vice versa).
9
+ type Query < TVariables > = {
10
+ query : StringOrAst ;
11
+ mutation ?: undefined ;
12
+ variables ?: TVariables ;
13
+ } ;
14
+
15
+ type Mutation < TVariables > = {
16
+ mutation : StringOrAst ;
17
+ query ?: undefined ;
18
+ variables ?: TVariables ;
19
+ } ;
20
+
21
+ export const createTestClient : < TVariables > (
22
+ server : ApolloServerBase
23
+ ) => {
24
+ query : ( query : Query < TVariables > ) => Promise < GraphQLResponse > ;
25
+ mutate : ( mutation : Mutation < TVariables > ) => Promise < GraphQLResponse > ;
26
+ } ;
27
+ }
You can’t perform that action at this time.
0 commit comments