-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor createHandler
to createHandlerFromSchema
#83
Conversation
🦋 Changeset detectedLatest commit: 674da60 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
✅ Deploy Preview for graphql-testing-library canceled.
|
/release:pr |
Please add a changeset via |
/release:pr |
A new release has been made for this PR. You can install it with:
|
/release:pr |
A new release has been made for this PR. You can install it with:
|
@@ -0,0 +1,19 @@ | |||
import type { CodegenConfig } from "@graphql-codegen/cli"; | |||
|
|||
const config: CodegenConfig = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Introduces codegen to be able to resolver typing support - will add type tests in a future PR
|
||
Object.defineProperties(globalThis, { | ||
TextDecoder: { value: TextDecoder }, // jest |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
performance
and clearImmediate
were unnecessary here and causing issues
resolvers: { | ||
Query: { | ||
products: () => | ||
Array.from({ length: products.length }, (_element, id) => ({ | ||
id, | ||
id: `${id}`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Type checking caught this :)
/release:pr |
A new release has been made for this PR. You can install it with:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really like the changes here! I was curious about beefing up the changeset and had a couple other questions, but otherwise looks great!
const sortEnumValues = () => { | ||
const key = "value"; | ||
return (a: GraphQLEnumValue, b: GraphQLEnumValue) => | ||
a[key] > b[key] ? 1 : b[key] > a[key] ? -1 : 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm curious about the use of key
here instead of a.value
, b.value
, etc. Is this a TypeScript thing to get around a private property access or something?
const schemaWithMocks = addMocksToSchema({ | ||
schema, | ||
const graphQLHandler = createHandler<Resolvers>({ | ||
typeDefs, | ||
resolvers: { | ||
Query: { | ||
products: () => | ||
Array.from({ length: products.length }, (_element, id) => ({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know this isn't part of this PR so feel free to ignore, but a potential optimization here might be to just map
over products
so you can avoid the whole array filling:
products.map((product, id) => ({
id: `${id}`,
title: product,
// etc.
})
|
||
export { createHandler }; | ||
export { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for not doing export *
🙏
.changeset/strange-socks-admire.md
Outdated
"@apollo/graphql-testing-library": patch | ||
--- | ||
|
||
Adds `createHandlerFromSchema` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see you've also added a bunch of exports for utilities. Would that be worth calling out here or in a separate changeset?
I've also noticed that createHandlerFromSchema
is more-or-less the same as createHandler
was before this since the old createHandler
took a schema
as an argument. Would it be worth calling out that breaking change to specify that createHandler
now accepts type defs and provides a bunch of the default resolvers for you?
This PR does a few things:
createHandler
with a schema documentcreateHandler
tocreateHandlerFromSchema
Resolvers
which now type checks any resolvers passed intocreateHandler
orcreateHandlerFromSchema