cards-database icon indicating copy to clipboard operation
cards-database copied to clipboard

issue: Cannot return null for non-nullable field AttacksListItem.name

Open notaphplover opened this issue 11 months ago • 4 comments

Where are you having the issue

  • [x] GraphQL
  • [ ] JSON API

Is the issue affecting one of the two elements below ?

  • [ ] Translations
  • [x] Definitions Files (Open API, GraphQL Schema, etc)

Description

When calling the API, a server error is thrown when AttacksListItem.name is null.

Recreation steps

Just send the following query:

{
  set(id: "sm10") @locale(lang: "en") {
    id,
    name,
    cards {
      abilities { effect, name, type },
      attacks { cost, damage, effect, name },
      category,
      effect,
      energyType,
      evolveFrom,
      hp,
      id,
      image,
      item { effect, name },
      legal { expanded, standard },
      level,
      name,
      rarity,
      regulationMark,
      resistances { type, value },
      retreat,
      stage,
      suffix,
      trainerType,
      types,
      variants { firstEdition, holo, normal, reverse, wPromo },
      weaknesses { type, value }
    }
  }
}

Expected behavior

API serves a set.

Current behavior

API fails with the folowing payload:

{
  "errors": [
    {
      "message": "Cannot return null for non-nullable field AttacksListItem.name.",
      "locations": [
        {
          "line": 13,
          "column": 39
        }
      ],
      "path": [
        "set",
        "cards",
        0,
        "attacks",
        3,
        "name"
      ]
    }
  ]
}

Context

https://www.apollographql.com/blog/using-nullability-in-graphql#what-happens-if-you-try-to-return-null-for-a-non-null-field

notaphplover avatar Jan 29 '25 14:01 notaphplover

After having a look at the data, it seems the underlying issue is the lack of a fallback value when providing the attack name.

For example, consider https://github.com/tcgdex/cards-database/blob/master/data/Diamond%20%26%20Pearl/Majestic%20Dawn/65.ts:

Since their attacks names are only provided for the german language, the API fails to fetch that card:

{
  card(id: "dp5-65") @locale(lang: "en") {
    attacks { cost, damage, effect, name }
  }
}

This query fails but:

{
  card(id: "dp5-65") @locale(lang: "de") {
    attacks { cost, damage, effect, name }
  }
}

This one is successfull.

It would make a lot of sense to make this property nullable or provide a fallback value in this scenario

notaphplover avatar Jan 30 '25 10:01 notaphplover

Hi, after looking more, the problem is coming from another area, Cards that contains an attack MUST (at least it is currecntly always the case) hase a name, so the GraphQL API is correctly configured.

If a card has one value in the correct language everything else should be filled.

After testing my database I found the erroneous cards

error compiling card sm10-1
error compiling card sm9-10
error compiling card sm8-19
error compiling card sm10-20
error compiling card sm115-29
error compiling card sm6-31
error compiling card sm11-35
error compiling card sm115-44
error compiling card sm9-51
error compiling card ex2-53
error compiling card sm11-54
error compiling card ex5-55
error compiling card sm5-58
error compiling card sm5-62
error compiling card dp5-65
error compiling card sm11-71
error compiling card sm6-74
error compiling card sm5-77
error compiling card ex4-79
error compiling card ex12-83
error compiling card ex12-84
error compiling card ex5-84
error compiling card ex4-84
error compiling card ex5-85
error compiling card ex12-86
error compiling card ex5-86
error compiling card hgss3-87
error compiling card ex12-87
error compiling card ex13-87
error compiling card hgss3-89
error compiling card sm5-89
error compiling card ex12-89
error compiling card hgss2-90
error compiling card hgss2-92
error compiling card hgss2-94
error compiling card pl2-95
error compiling card sm6-96
error compiling card hgss4-99
error compiling card hgss4-101
error compiling card sm10-107
error compiling card hgss1-111
error compiling card ecard1-112
error compiling card hgss1-113
error compiling card neo4-113
error compiling card ecard2-119
error compiling card sv04-120
error compiling card ecard2-121
error compiling card ecard2-122
error compiling card ecard2-124
error compiling card sm11-126
error compiling card ecard2-127
error compiling card ecard2-129
error compiling card ecard3-129
error compiling card sm10-130
error compiling card ecard3-130
error compiling card ecard3-131
error compiling card ecard2-132
error compiling card ecard3-133
error compiling card ecard3-134
error compiling card dp6-136
error compiling card ecard3-136
error compiling card dp6-137
error compiling card ecard2-140
error compiling card sm8-144
error compiling card ecard1-144
error compiling card sv03.5-152
error compiling card sv03.5-153
error compiling card sm8-154
error compiling card sv03.5-154
error compiling card sm10-191
error compiling card sm10-192
error compiling card sm10-194
error compiling card sm12-210
error compiling card sm12-211
error compiling card sm12-212
error compiling card sm12-214
error compiling card sm11-214
error compiling card sm12-215
error compiling card sm11-215
error compiling card sm12-216
error compiling card sm11-217
error compiling card sm11-218
error compiling card sm11-220
error compiling card sm11-221
error compiling card sm11-222
error compiling card sm12-223
error compiling card sm11-225
error compiling card sm11-226
error compiling card bwp-BW85
error compiling card dpp-DP03
error compiling card dpp-DP13
error compiling card smp-SM166
error compiling card smp-SM168
error compiling card smp-SM169
error compiling card smp-SM201
error compiling card xyp-XY154
error compiling card xyp-XY63
error compiling card xyp-XY87

I am currently fixing them manually and will update here when fixed !

Aviortheking avatar Feb 06 '25 22:02 Aviortheking

fixed some more, I need one last pass mostly and every cards that made this problem should be fixed !

Aviortheking avatar Feb 19 '25 22:02 Aviortheking

Thanks a lot for taking the time !

gromon42 avatar Feb 20 '25 15:02 gromon42