Skip to content

Commit

Permalink
Smaller bundle size, now GraphQL handler specific stuff is not in the…
Browse files Browse the repository at this point in the history
… core packages
  • Loading branch information
ardatan committed Jul 25, 2022
1 parent 433265d commit 4764f68
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 46 deletions.
9 changes: 9 additions & 0 deletions .changeset/four-mice-taste.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
"@graphql-mesh/graphql": minor
"@graphql-mesh/mysql": minor
"@graphql-mesh/neo4j": minor
"@graphql-mesh/store": minor
"@graphql-mesh/types": minor
---

Smaller bundle size;
39 changes: 37 additions & 2 deletions packages/handlers/graphql/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ import {
getOperationASTFromRequest,
parseSelectionSet,
isAsyncIterable,
getDocumentNodeFromSchema,
} from '@graphql-tools/utils';
import { PredefinedProxyOptions, StoreProxy } from '@graphql-mesh/store';
import { ProxyOptions, StoreProxy } from '@graphql-mesh/store';
import lodashGet from 'lodash.get';
import {
getInterpolatedHeadersFactory,
Expand All @@ -39,6 +40,40 @@ const getResolverData = memoize1(function getResolverData(params: ExecutionReque
};
});

const GraphQLSchemaWithDiffing: ProxyOptions<GraphQLSchema> = {
codify: schema =>
`
import { buildASTSchema } from 'graphql';
const schemaAST = ${JSON.stringify(getDocumentNodeFromSchema(schema), null, 2)};
export default buildASTSchema(schemaAST, {
assumeValid: true,
assumeValidSDL: true
});
`.trim(),
fromJSON: schemaAST => buildASTSchema(schemaAST, { assumeValid: true, assumeValidSDL: true }),
toJSON: schema => getDocumentNodeFromSchema(schema),
validate: () => {},
/*
validate: async (oldSchema, newSchema) => {
const changes = await diff(oldSchema, newSchema);
const errors: string[] = [];
for (const change of changes) {
if (
change.criticality.level === CriticalityLevel.Breaking ||
change.criticality.level === CriticalityLevel.Dangerous
) {
errors.push(change.message);
}
}
if (errors.length) {
throw new AggregateError(errors);
}
},
*/
};

export default class GraphQLHandler implements MeshHandler {
private config: YamlConfig.Handler['graphql'];
private baseDir: string;
Expand All @@ -59,7 +94,7 @@ export default class GraphQLHandler implements MeshHandler {
this.config = config;
this.baseDir = baseDir;
this.fetchFn = fetchFn;
this.nonExecutableSchema = store.proxy('introspectionSchema', PredefinedProxyOptions.GraphQLSchemaWithDiffing);
this.nonExecutableSchema = store.proxy('introspectionSchema', GraphQLSchemaWithDiffing);
this.importFn = importFn;
this.logger = logger;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/handlers/neo4j/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export default class Neo4JHandler implements MeshHandler {
}

getCachedTypeDefs(driver: Driver) {
return this.typeDefs.getWithSet(async () => {
return this.typeDefs.getWithSet(() => {
if (this.config.typeDefs) {
return readFileOrUrl(this.config.typeDefs, {
cwd: this.baseDir,
Expand Down
2 changes: 0 additions & 2 deletions packages/store/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,8 @@
"definition": "dist/index.d.ts"
},
"dependencies": {
"@graphql-inspector/core": "3.3.0",
"@graphql-mesh/cross-helpers": "0.2.0",
"@graphql-mesh/utils": "0.37.4",
"@graphql-tools/utils": "8.8.0",
"@graphql-mesh/types": "0.78.3",
"tslib": "^2.4.0"
},
Expand Down
38 changes: 0 additions & 38 deletions packages/store/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import { fs, path as pathModule } from '@graphql-mesh/cross-helpers';
import { writeFile } from '@graphql-mesh/utils';
import { CriticalityLevel, diff } from '@graphql-inspector/core';
import { getDocumentNodeFromSchema, AggregateError } from '@graphql-tools/utils';
import { ImportFn } from '@graphql-mesh/types';
import { buildASTSchema } from 'graphql';

export class ReadonlyStoreError extends Error {}

Expand Down Expand Up @@ -109,7 +106,6 @@ export type StoreFlags = {
export enum PredefinedProxyOptionsName {
JsonWithoutValidation = 'JsonWithoutValidation',
StringWithoutValidation = 'StringWithoutValidation',
GraphQLSchemaWithDiffing = 'GraphQLSchemaWithDiffing',
}

export const PredefinedProxyOptions: Record<PredefinedProxyOptionsName, ProxyOptions<any>> = {
Expand All @@ -125,40 +121,6 @@ export const PredefinedProxyOptions: Record<PredefinedProxyOptionsName, ProxyOpt
toJSON: v => v,
validate: () => null,
},
GraphQLSchemaWithDiffing: {
codify: schema =>
`
import { buildASTSchema } from 'graphql';
const schemaAST = ${JSON.stringify(getDocumentNodeFromSchema(schema), null, 2)};
export default buildASTSchema(schemaAST, {
assumeValid: true,
assumeValidSDL: true
});
`.trim(),
fromJSON: schemaAST => buildASTSchema(schemaAST, { assumeValid: true, assumeValidSDL: true }),
toJSON: schema => getDocumentNodeFromSchema(schema),
validate: async (oldSchema, newSchema) => {
const changes = await diff(oldSchema, newSchema);
const errors: string[] = [];
for (const change of changes) {
if (
change.criticality.level === CriticalityLevel.Breaking ||
change.criticality.level === CriticalityLevel.Dangerous
) {
errors.push(change.message);
}
}
if (errors.length) {
if (errors.length === 1) {
throw errors[0];
} else {
throw new AggregateError(errors);
}
}
},
},
};

export class MeshStore {
Expand Down
4 changes: 1 addition & 3 deletions packages/types/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,9 @@ export const jsonSchema: any = configSchema;

export { YamlConfig };

export type MeshSource = {
export type MeshSource = SubschemaConfig & {
schema: GraphQLSchema;
executor?: Executor;
contextVariables?: Record<string, string>;
batch?: boolean;
};

type FetchFn = (input: RequestInfo, init?: RequestInit) => Promise<Response>;
Expand Down

0 comments on commit 4764f68

Please sign in to comment.