5e-srd-api icon indicating copy to clipboard operation
5e-srd-api copied to clipboard

GraphQL: Cannot query field "alignments" on type "Monster"

Open khaosophy opened this issue 2 years ago • 5 comments
trafficstars

I was looking for the monster alignment data, and found it in the REST API, but I'm not seeing it in the GraphQL (I tried alignments and alignment).

I can try to dig into this myself this week, but I wanted to post the issue first, in case I'm missing something obvious.

khaosophy avatar Jun 17 '23 20:06 khaosophy

This definitely looks like a legitimate flaw in the GraphQL schema. A PR would be most welcome!

fergcb avatar Jun 17 '23 21:06 fergcb

ahh nice catch, poked around a bit and i think i have a handle on what's going on. this stems from Monster field definitions all being slightly different from the comparable Race and Class fields

for example, we have a defintion for armor class

type ArmorClass {
  base: Int!
  dex_bonus: Boolean!
  max_bonus: Int
}

and then we have the slightly different monster variety

  type: MonsterArmorClassType!
  desc: String
  value: Int!
  armor: [Armor]
  spell: Spell
  condition: Condition
}

in the case of alignments, we have a defnition that returns an Alignment object, but if we look at the Monster schema in the database or the rest api, we can see that the Monster.alignment field is only a primitive string.

i think there's a couple options

  • add an enum definition for MonsterAlignment, and have the gql query for monster.monster-alignment return the simple string val OR
  • update the monster schema to return an Alignment

i'm going to try and get a PR up for that first option this afternoon

ecshreve avatar Jul 21 '23 21:07 ecshreve

The second option definitely seems more appealing to me! There seems almost no point in having an Alignments collection if we don't reference it from Monster documents.

fergcb avatar Jul 21 '23 21:07 fergcb

i lied a little bit by accident.

in the gql schema , we currently only return the Alignment object on root root queries, and from the IdealOption type.

in the current schema the alignment field on the Race type, a primitive string 🤔 going to think about this a little more

ecshreve avatar Jul 21 '23 21:07 ecshreve

oh yeah i made it way more complicated than it was. we should be able to get the string exposed real easy, but if we want to return an Alignment object instead it's a bit more work

localhost Screenshot 2023-07-21 at 2 57 31 PM

ecshreve avatar Jul 21 '23 21:07 ecshreve