-
Notifications
You must be signed in to change notification settings - Fork 538
Add support for customValidateFn and rename formatError to customFormatErrorFn #479
Add support for customValidateFn and rename formatError to customFormatErrorFn #479
Conversation
@IvanGoncharov aka graphql overlord can you please review? |
Hey @IvanGoncharov, the set cache property signature was a mistake. I've changed it to |
I also think wrapping / replacing the validate function would be better. I wrote a validation rule to analyze the query complexity and reject complex queries that depends on the input variables: graphql-query-complexity Maybe we could even add a plugin system to Initialization could look something like this: app.get('/graphql', graphqlHTTP({
schema: MyGraphQLSchema,
graphiql: true,
plugins: [
new ValidationCachePlugin(options),
// Other plugins
new FakeResultPlugin(),
// We could also add hooks for things like...
new ProfilingPlugin(),
// etc.
]
})); Might be overkill for just this one feature and this would definitely need some more detailed conception but I just wanted to throw this out here to see what you think... |
Thanks for the feedback @IvanGoncharov. Using the same pattern as the |
@jamesmoriarty Thanks 👍 |
@jamesmoriarty Thanks a lot 👍 I will try to merge it in the next few days. One issue I still have is with both |
I agree. The existing implementation made it possible. I've had a look at the graphql-js source to get ideas on consistency. I'm thinking Based on: |
@jamesmoriarty Great suggestion 👍 I like it.
Make sense 👍 |
Sure thing. |
Made the change to the naming, deprecating |
src/index.js
Outdated
} | ||
|
||
formatErrorFn = | ||
optionsData.customFormatErrorFn || optionsData.formatError; |
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.
@IvanGoncharov interestingly I couldn't change this to:
optionsData.customFormatErrorFn || optionsData.formatError || formatError
// ...
.map(errorFormatFn)
Without breaking the tests. It appears the
.map(errorFormatFn || formatError)
may be called before the options resolve. maybe around schema validation.
Might be worth resolving outside this change.
* formatError is deprecated. * customFormatErrorFn to replace formatError.
Added to README. Thanks for spending time on this @IvanGoncharov. Much appreciated. |
@jamesmoriarty I made a few small fixes like replacing |
Regarding: #474