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

Query complexity #139

Merged
merged 14 commits into from
Sep 8, 2018
1 change: 1 addition & 0 deletions examples/simple-usage/graphql-query-complexity.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
declare module "graphql-query-complexity";
11 changes: 10 additions & 1 deletion examples/simple-usage/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import "reflect-metadata";
import { GraphQLServer, Options } from "graphql-yoga";
import { buildSchema } from "../../src";

import queryComplexity from "graphql-query-complexity";
Copy link
Owner

Choose a reason for hiding this comment

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

This one is not needed.

import { RecipeResolver } from "./recipe-resolver";

async function bootstrap() {
Expand All @@ -18,6 +18,15 @@ async function bootstrap() {
port: 4000,
endpoint: "/graphql",
playground: "/playground",
validationRules: req => [
Copy link
Owner

Choose a reason for hiding this comment

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

Remove this from simple-usage

queryComplexity({
maximumComplexity: 1000,
variables: req.query.variables,
onComplete: (complexity: number) => {
console.log("Query Complexity:", complexity);
},
}),
],
};

// Start the server
Expand Down
4 changes: 2 additions & 2 deletions examples/simple-usage/recipe-type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ import { Field, ObjectType, Int, Float } from "../../src";

@ObjectType({ description: "Object representing cooking recipe" })
export class Recipe {
@Field()
@Field({ complexity: 5 })
title: string;

@Field(type => String, { nullable: true, deprecationReason: "Use `description` field instead" })
get specification(): string | undefined {
return this.description;
}

@Field({ nullable: true, description: "The recipe description with preparation info" })
@Field({ complexity: 5, nullable: true, description: "The recipe" })
description?: string;

@Field(type => [Int])
Expand Down
Loading