Skip to content
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

Remove uses of reduce/spread which causes significant latency to large middlewares #567

Merged
merged 2 commits into from
Jul 7, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
48 changes: 23 additions & 25 deletions src/applicator.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {

Check failure on line 1 in src/applicator.ts

View workflow job for this annotation

GitHub Actions / release

Cannot find name 'field'.

Check failure on line 1 in src/applicator.ts

View workflow job for this annotation

GitHub Actions / release

Cannot find name 'field'.

Check failure on line 1 in src/applicator.ts

View workflow job for this annotation

GitHub Actions / release

No overload matches this call.

Check failure on line 1 in src/applicator.ts

View workflow job for this annotation

GitHub Actions / release

Type 'string' is not assignable to type 'IResolvers<any, any>'.
GraphQLObjectType,
GraphQLFieldResolver,
GraphQLField,
Expand Down Expand Up @@ -45,11 +45,10 @@
) {
const { isDeprecated, ...restData } = field
const argsMap = field.args.reduce(
(acc, cur) => ({
...acc,
[cur.name]: cur,
}),
{} as Record<string, GraphQLArgument>,
(acc, cur) => {
acc[cur.name] = cur;
return acc;
}, {} as Record<string, GraphQLArgument>,
)
return {
...restData,
Expand Down Expand Up @@ -138,28 +137,28 @@

if (isMiddlewareFunction(middleware)) {
const resolvers = Object.keys(fieldMap).reduce(
(resolvers, fieldName) => ({
...resolvers,
[fieldName]: applyMiddlewareToField(
(resolvers, fieldName) => {
resolvers[fieldName] = applyMiddlewareToField(
fieldMap[fieldName],
options,
middleware as IMiddlewareFunction<TSource, TContext, TArgs>,
),
}),
);
return resolvers;
},
{},
)

return resolvers
} else {
const resolvers = Object.keys(middleware).reduce(
(resolvers, field) => ({
...resolvers,
[field]: applyMiddlewareToField(
(resolvers, fieldName) => {
resolvers[fieldName] = applyMiddlewareToField(
fieldMap[field],
options,
middleware[field],
),
}),
);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cannot find name 'field'. Could you please rename fieldName back to field, or use fieldName inside the function?

return resolvers;
},
{},
)

Expand All @@ -181,14 +180,14 @@
!isIntrospectionType(typeMap[type]),
)
.reduce(
(resolvers, type) => ({
...resolvers,
[type]: applyMiddlewareToType(
(resolvers, type) => {
resolvers[type] = applyMiddlewareToType(
typeMap[type] as GraphQLObjectType,
options,
middleware,
),
}),
);
return resolvers;
},
{},
)

Expand Down Expand Up @@ -216,14 +215,13 @@
const typeMap = schema.getTypeMap()

const resolvers = Object.keys(middleware).reduce(
(resolvers, type) => ({
...resolvers,
[type]: applyMiddlewareToType(
(resolvers, type) => {
resolvers[type] = applyMiddlewareToType(
typeMap[type] as GraphQLObjectType,
options,
middleware[type],
),
}),
);
ryanquinn3 marked this conversation as resolved.
Show resolved Hide resolved
},
{},
)

Expand Down