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

HowTo use costMap with non top-level objects? #39

Closed
Mika83AC opened this issue Feb 6, 2020 · 1 comment
Closed

HowTo use costMap with non top-level objects? #39

Mika83AC opened this issue Feb 6, 2020 · 1 comment

Comments

@Mika83AC
Copy link

Mika83AC commented Feb 6, 2020

Hello everyone,

given a sample schema like:

type Query {
  articles(limit: int): [Article]
}

type Article{
  id: ID!
  no: String!
  country: ListEntry
}

type ListEntry {
  id: ID!
  descript: String
}

Howto define costs for Article and ListEntry types using the costMap? (can't use the SDL way as I'm going code first, not SDL first).

Until now I only understood how to define costs for top-level queries in general without taking the accessed fields into regard (that's what the example in the readme does).

But what I wish to define is:

articles: {
   multipliers: ['limit'],
   useMultipliers: true
},
Article: {
   complexity: 1
},
ListEntry: {
   complexity: 1
},

so that the query

query {
   articles(10) {
      no,
      country {
         descript
      }
   }
}

will fail when maximumCost is set to 15, but will be fine when set to 20.

Any way to solve that with graphql-cost-analysis using costMap?

Regards,
Michael

@Mika83AC
Copy link
Author

Mika83AC commented Feb 7, 2020

Got it .... sorry guys ...

CostMap for my use case looks like this:

Query: {
   articles: {
      multipliers: ['limit'],
      useMultipliers: true,
      complexity: 1
   },
Article: {
   country: {
      complexity: 1
   },
},

@Mika83AC Mika83AC closed this as completed Feb 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant