#define query complexity in code-first approach for the top level `Query`

4 messages · Page 1 of 1 (latest)

fervent cove
#

So the question is literally what the title is. I read the doc about query complexity and still cannot figure out how to do it. I think I might how been able to do it in pure graphql-js since there you can define your root Query type like this:

import { GraphQLList, GraphQLObjectType } from 'graphql';
import { PostObject } from '../objects/post.object';

export const RootQuery = new GraphQLObjectType({
  name: 'Query',
  extensions: {
    complexity: 1
  },
  fields: () => ({
    getPosts: {
      type: new GraphQLList(PostObject),
      // ...
    }
    // ...
  })
  // ...
})

Any comment?So the question is literally what the title is. I read the doc about query complexity and still cannot figure out how to do it. I think I might how been able to do it in pure graphql-js since there you can define your root Query type like this:

import { GraphQLList, GraphQLObjectType } from 'graphql';
import { PostObject } from '../objects/post.object';

export const RootQuery = new GraphQLObjectType({
  name: 'Query',
  extensions: {
    complexity: 1
  },
  fields: () => ({
    getPosts: {
      type: new GraphQLList(PostObject),
      // ...
    }
    // ...
  })
  // ...
})

Any comment?

soft stratus
#

Maybe using the transformSchema option on GraphQLModule.forRoot? You should be able to navigate to the root Query and modify it.

fervent cove
#

I skipped it since it was contributing only one point to the overall complexity of each query. So I just dropped it all together. Although I can still add it here:

@Resolver(() => Test)
export class TestResolver {
  @Query(() => SomeDto, { complexity: 1 }) // 1 for the query itself, but can change it to 2. This way I think I can add the complexity point of the root query.
  whatever() {}
}