-
-
Notifications
You must be signed in to change notification settings - Fork 535
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Annotates queries and variables in GraphQL tests
- Loading branch information
1 parent
1434c90
commit fedf608
Showing
6 changed files
with
139 additions
and
46 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
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
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 |
---|---|---|
@@ -1,44 +1,84 @@ | ||
import { setupWorker, graphql } from 'msw' | ||
|
||
interface GetGitHubUserQuery { | ||
user: { | ||
username: string | ||
firstName: string | ||
} | ||
} | ||
|
||
interface GetGitHubUserQueryVariables { | ||
username: string | ||
} | ||
|
||
interface DeletePostQuery { | ||
deletePost: { | ||
postId: string | ||
} | ||
} | ||
|
||
interface DeletePostQueryVariables { | ||
postId: string | ||
} | ||
|
||
interface GetActiveUserQuery { | ||
user: { | ||
id: number | ||
} | ||
} | ||
|
||
interface GetActiveUserQueryVariables { | ||
foo: string | ||
} | ||
|
||
const worker = setupWorker( | ||
graphql.query('GetGithubUser', (req, res, ctx) => { | ||
const { username } = req.variables | ||
|
||
return res( | ||
ctx.data({ | ||
user: { | ||
firstName: 'John', | ||
username, | ||
}, | ||
}), | ||
) | ||
}), | ||
|
||
graphql.mutation('DeletePost', (req, res, ctx) => { | ||
const { postId } = req.variables | ||
|
||
return res( | ||
ctx.data({ | ||
deletePost: { | ||
postId, | ||
}, | ||
}), | ||
) | ||
}), | ||
|
||
graphql.query('GetActiveUser', (req, res, ctx) => { | ||
// Intentionally unused variable | ||
// eslint-disable-next-line | ||
const { foo } = req.variables | ||
|
||
return res( | ||
ctx.data({ | ||
user: { | ||
id: 1, | ||
}, | ||
}), | ||
) | ||
}), | ||
graphql.query<GetGitHubUserQuery, GetGitHubUserQueryVariables>( | ||
'GetGithubUser', | ||
(req, res, ctx) => { | ||
const { username } = req.variables | ||
|
||
return res( | ||
ctx.data({ | ||
user: { | ||
username, | ||
firstName: 'John', | ||
}, | ||
}), | ||
) | ||
}, | ||
), | ||
|
||
graphql.mutation<DeletePostQuery, DeletePostQueryVariables>( | ||
'DeletePost', | ||
(req, res, ctx) => { | ||
const { postId } = req.variables | ||
|
||
return res( | ||
ctx.data({ | ||
deletePost: { | ||
postId, | ||
}, | ||
}), | ||
) | ||
}, | ||
), | ||
|
||
graphql.query<GetActiveUserQuery, GetActiveUserQueryVariables>( | ||
'GetActiveUser', | ||
(req, res, ctx) => { | ||
// Intentionally unused variable | ||
// eslint-disable-next-line | ||
const { foo } = req.variables | ||
|
||
return res( | ||
ctx.data({ | ||
user: { | ||
id: 1, | ||
}, | ||
}), | ||
) | ||
}, | ||
), | ||
) | ||
|
||
worker.start() |