Skip to content

Commit

Permalink
Clean up after refactoring of schema generation
Browse files Browse the repository at this point in the history
  • Loading branch information
Yogu committed Jun 6, 2018
1 parent 3f041aa commit 92376ec
Show file tree
Hide file tree
Showing 101 changed files with 489 additions and 4,632 deletions.
Empty file added CHANGES.md
Empty file.
2 changes: 1 addition & 1 deletion spec/authorization/permission-descriptor.spec.ts
Expand Up @@ -7,7 +7,7 @@ import {
BinaryOperationQueryNode, BinaryOperator, ConstBoolQueryNode, FieldQueryNode, LiteralQueryNode, QueryNode,
VariableQueryNode
} from '../../src/query-tree';
import { ACCESS_GROUP_FIELD } from '../../src/schema/schema-defaults';
import { ACCESS_GROUP_FIELD } from '../../src/schema/constants';
import { expect } from 'chai';


Expand Down
60 changes: 37 additions & 23 deletions spec/performance/query-pipeline.perf.ts
@@ -1,18 +1,17 @@
import { BenchmarkConfig, BenchmarkFactories } from './support/async-bench';
import { DocumentNode, GraphQLSchema, parse, validate } from 'graphql';
import * as path from 'path';
import { DistilledOperation, distillQuery } from '../../src/graphql/query-distiller';
import { createQueryTree } from '../../src/query/query-tree-builder';
import { applyAuthorizationToQueryTree } from '../../src/authorization/execution';
import { getAQLQuery } from '../../src/database/arangodb/aql-generator';
import { QueryNode } from '../../src/query-tree';
import { DistilledOperation, distillQuery } from '../../src/graphql/query-distiller';
import { Model } from '../../src/model';
import { ObjectQueryNode, QueryNode } from '../../src/query-tree';
import { buildConditionalObjectQueryNode, QueryNodeObjectType, RootTypesGenerator } from '../../src/schema-generation';
import { compact } from '../../src/utils/utils';
import { applyAuthorizationToQueryTree } from '../../src/authorization/execution';
import { Project } from '../../src/project/project';
import { BenchmarkConfig, BenchmarkFactories } from './support/async-bench';
import { createTestProject } from './support/helpers';
import { Model } from '../../src/model';

const QUERIES = [
`{
`{
allDeliveries {
id
items {
Expand All @@ -28,14 +27,14 @@ const QUERIES = [
}
}`,

`mutation d {
`mutation d {
deleteDelivery(id: "15027307") {
id
deliveryNumber
}
}`,

`
`
mutation m {
updateDelivery(input: {
id: "15116232",
Expand Down Expand Up @@ -88,20 +87,34 @@ interface PreparedQuery {
gql: string;
document: DocumentNode;
distilledOperation: DistilledOperation;
queryType: QueryNodeObjectType;
mutationType: QueryNodeObjectType;
queryTree: QueryNode;
authorizedQueryTree: QueryNode;
}

function buildQueryTree({distilledOperation, queryType, mutationType}: { distilledOperation: DistilledOperation, queryType: QueryNodeObjectType, mutationType: QueryNodeObjectType }): QueryNode {
if (distilledOperation.operation == 'mutation') {
return buildConditionalObjectQueryNode(ObjectQueryNode.EMPTY, mutationType, distilledOperation.selectionSet);
} else {
return buildConditionalObjectQueryNode(ObjectQueryNode.EMPTY, queryType, distilledOperation.selectionSet);
}
}

function prepareQuery(gql: string, schema: GraphQLSchema, model: Model): PreparedQuery {
const document = parse(gql);
validate(schema, document);
const distilledOperation = distillQuery(document, schema, {});
const queryTree = createQueryTree(distilledOperation, model);
const authorizedQueryTree = applyAuthorizationToQueryTree(queryTree, { authRoles: []});
const queryType = new RootTypesGenerator().generateQueryType(model);
const mutationType = new RootTypesGenerator().generateMutationType(model);
const queryTree = buildQueryTree({queryType, mutationType, distilledOperation});
const authorizedQueryTree = applyAuthorizationToQueryTree(queryTree, {authRoles: []});
return {
gql,
document,
distilledOperation,
queryType,
mutationType,
queryTree,
authorizedQueryTree
};
Expand All @@ -112,7 +125,8 @@ function testQueryPipeline(params: { parser: boolean, queryDistiller: boolean, q
params.parser ? 'parser' : undefined,
params.queryDistiller ? 'query-distiller' : undefined,
params.queryTree ? 'query-tree' : undefined,
params.aql ? 'aql' : undefined
params.aql ? 'aql' : undefined,
params.auth ? 'auth' : undefined
]).join(', ');

let schema: GraphQLSchema;
Expand All @@ -132,16 +146,16 @@ function testQueryPipeline(params: { parser: boolean, queryDistiller: boolean, q
fn() {
const preparedQuery = preparedQueries[Math.floor(Math.random() * preparedQueries.length)];
if (params.parser) {
parse(preparedQuery.gql)
parse(preparedQuery.gql);
}
if (params.queryDistiller) {
distillQuery(preparedQuery.document, schema, {});
}
if (params.queryTree) {
createQueryTree(preparedQuery.distilledOperation, model);
buildQueryTree(preparedQuery);
}
if (params.auth) {
applyAuthorizationToQueryTree(preparedQuery.queryTree, { authRoles: []});
applyAuthorizationToQueryTree(preparedQuery.queryTree, {authRoles: []});
}
if (params.aql) {
const transaction = getAQLQuery(preparedQuery.authorizedQueryTree);
Expand All @@ -152,12 +166,12 @@ function testQueryPipeline(params: { parser: boolean, queryDistiller: boolean, q
}

const benchmarks: BenchmarkFactories = [
() => testQueryPipeline({parser: true, queryDistiller: false, queryTree: false, auth: false, aql: false }),
() => testQueryPipeline({parser: false, queryDistiller: true, queryTree: false, auth: false, aql: false }),
() => testQueryPipeline({parser: false, queryDistiller: false, queryTree: true, auth: false, aql: false }),
() => testQueryPipeline({parser: false, queryDistiller: false, queryTree: true, auth: true, aql: false }),
() => testQueryPipeline({parser: false, queryDistiller: false, queryTree: false, auth: false, aql: true }),
() => testQueryPipeline({parser: true, queryDistiller: true, queryTree: true, auth: true, aql: true })
() => testQueryPipeline({parser: true, queryDistiller: false, queryTree: false, auth: false, aql: false}),
() => testQueryPipeline({parser: false, queryDistiller: true, queryTree: false, auth: false, aql: false}),
() => testQueryPipeline({parser: false, queryDistiller: false, queryTree: true, auth: false, aql: false}),
() => testQueryPipeline({parser: false, queryDistiller: false, queryTree: true, auth: true, aql: false}),
() => testQueryPipeline({parser: false, queryDistiller: false, queryTree: false, auth: false, aql: true}),
() => testQueryPipeline({parser: true, queryDistiller: true, queryTree: true, auth: true, aql: true})
];

export default benchmarks;
export default benchmarks;
4 changes: 2 additions & 2 deletions spec/performance/support/helpers.ts
Expand Up @@ -21,8 +21,8 @@ export interface TestEnvironment {

const schemaContext: SchemaContext = { loggerProvider: new Log4jsLoggerProvider('warn') };

export async function createTestProject(modelPath: string): Promise<{project: Project, schema: GraphQLSchema}> {
const project = await loadProjectFromDir(MODEL_PATH, schemaContext);
export async function createTestProject(modelPath: string = MODEL_PATH): Promise<{project: Project, schema: GraphQLSchema}> {
const project = await loadProjectFromDir(modelPath, schemaContext);
const dbConfig = await createTempDatabase();
const dbAdapter = new ArangoDBAdapter(dbConfig, schemaContext);
const schema = project.createSchema(dbAdapter);
Expand Down
@@ -1,9 +1,9 @@
import { expect } from 'chai';
import {
BinaryOperationQueryNode, BinaryOperator, ConstBoolQueryNode, LiteralQueryNode, QueryNode, UnaryOperationQueryNode,
UnaryOperator
} from '../../src/query-tree';
import { simplifyBooleans } from '../../src/query/query-tree-utils';
import { expect } from 'chai';
} from '../../../src/query-tree';
import { simplifyBooleans } from '../../../src/query-tree/utils';

describe('query-tree-utils', () => {
describe('simplifyBooleans', () => {
Expand Down
51 changes: 0 additions & 51 deletions spec/query/query-tree-builder.spec.ts

This file was deleted.

2 changes: 1 addition & 1 deletion spec/regression/initialization.ts
Expand Up @@ -3,7 +3,7 @@ import { Database } from 'arangojs';
import {ExecutionResult, graphql, GraphQLSchema} from 'graphql';
import * as fs from 'fs';
import stripJsonComments = require('strip-json-comments');
import {NAMESPACE_SEPARATOR} from "../../src/schema/schema-defaults";
import {NAMESPACE_SEPARATOR} from "../../src/schema/constants";

const DATABASE_NAME = 'cruddl-test-temp';
const DATABASE_URL = 'http://root:@localhost:8529';
Expand Down

This file was deleted.

This file was deleted.

0 comments on commit 92376ec

Please sign in to comment.