[next] Relay GraphQL Batching (#1965)

* feat: added graphqlBatch

* refactor: cleanup of json serial

* refactor: cleanup of json serilization

* feat: use react network layer

* fix: adjusted broken user

* fix: temporarily disable cache for profile query

* test: temporarily use precompiled modules

* fix: bug when updating comment count on an asset

* fix: compile modules to commonjs for jest

* test: add react-relay-network-layer to transform whitelist

* fix: use react-relay-network-layer/es

* types: add react-relay-network-modern typescript types

* feat: integrate custom error middleware

* review: add todo
This commit is contained in:
Wyatt Johnson
2018-10-15 22:46:21 +00:00
committed by GitHub
parent 9347815276
commit e9c80fc02a
27 changed files with 646 additions and 186 deletions
+25 -33
View File
@@ -1,45 +1,37 @@
import { GraphQLSchema } from "graphql";
import { Redis } from "ioredis";
import { Db } from "mongodb";
// import { graphqlBatchHTTPWrapper } from "react-relay-network-layer";
import { Config } from "talk-common/config";
import { graphqlBatchMiddleware } from "talk-server/app/middleware/graphqlBatch";
import { graphqlMiddleware } from "talk-server/graph/common/middleware";
import { TaskQueue } from "talk-server/services/queue";
import { Request } from "talk-server/types/express";
import TenantContext from "./context";
export interface TenantGraphQLMiddlewareOptions {
schema: GraphQLSchema;
config: Config;
mongo: Db;
redis: Redis;
queue: TaskQueue;
}
export default async ({
schema,
config,
mongo,
redis,
queue,
}: TenantGraphQLMiddlewareOptions) => {
return graphqlMiddleware(config, async (req: Request) => {
// Load the tenant and user from the request.
const { tenant, user, tenantCache } = req;
export default async ({ schema, config }: TenantGraphQLMiddlewareOptions) =>
graphqlBatchMiddleware(
graphqlMiddleware(config, async (req: Request) => {
if (!req.talk) {
throw new Error("talk was not set");
}
// Return the graph options.
return {
schema,
context: new TenantContext({
req,
mongo,
redis,
tenant: tenant!,
user,
tenantCache,
queue,
}),
};
});
};
const { context } = req.talk;
if (!context) {
throw new Error("context was not set");
}
const { tenant } = context;
if (!tenant) {
throw new Error("tenant was not set");
}
// Return the graph options.
return {
schema,
context: tenant,
};
})
);