-
Notifications
You must be signed in to change notification settings - Fork 175
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Step 4.3: Add chat field to Query type
- Loading branch information
Showing
5 changed files
with
81 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,4 +17,5 @@ type Chat { | |
|
||
type Query { | ||
chats: [Chat!]! | ||
chat(chatId: ID!): Chat | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Query.chat should fetch specified chat 1`] = ` | ||
Object { | ||
"chat": Object { | ||
"id": "1", | ||
"lastMessage": Object { | ||
"content": "You on your way?", | ||
"createdAt": "2018-12-31T07:20:00.000Z", | ||
"id": "1", | ||
}, | ||
"name": "Ethan Gonzalez", | ||
"picture": "https://randomuser.me/api/portraits/thumb/men/1.jpg", | ||
}, | ||
} | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { createTestClient } from 'apollo-server-testing'; | ||
import { ApolloServer, gql } from 'apollo-server-express'; | ||
import schema from '../../schema'; | ||
|
||
describe('Query.chat', () => { | ||
it('should fetch specified chat', async () => { | ||
const server = new ApolloServer({ schema }); | ||
|
||
const { query } = createTestClient(server); | ||
|
||
const res = await query({ | ||
variables: { chatId: '1' }, | ||
query: gql` | ||
query GetChat($chatId: ID!) { | ||
chat(chatId: $chatId) { | ||
id | ||
name | ||
picture | ||
lastMessage { | ||
id | ||
content | ||
createdAt | ||
} | ||
} | ||
} | ||
`, | ||
}); | ||
|
||
expect(res.data).toBeDefined(); | ||
expect(res.errors).toBeUndefined(); | ||
expect(res.data).toMatchSnapshot(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
declare module 'apollo-server-testing' { | ||
import { ApolloServerBase } from 'apollo-server-core'; | ||
import { print, DocumentNode } from 'graphql'; | ||
import { GraphQLResponse } from 'graphql-extensions'; | ||
|
||
type StringOrAst = string | DocumentNode; | ||
|
||
// A query must not come with a mutation (and vice versa). | ||
type Query<TVariables> = { | ||
query: StringOrAst; | ||
mutation?: undefined; | ||
variables?: TVariables; | ||
}; | ||
|
||
type Mutation<TVariables> = { | ||
mutation: StringOrAst; | ||
query?: undefined; | ||
variables?: TVariables; | ||
}; | ||
|
||
export const createTestClient: <TVariables>( | ||
server: ApolloServerBase | ||
) => { | ||
query: (query: Query<TVariables>) => Promise<GraphQLResponse>; | ||
mutate: (mutation: Mutation<TVariables>) => Promise<GraphQLResponse>; | ||
}; | ||
} |