graph-tooling icon indicating copy to clipboard operation
graph-tooling copied to clipboard

Codegen does not differentiate between `Int` and `Int!` in schema.graphql

Open iherger opened this issue 2 years ago • 6 comments

A type with a field Int is generated the same as with field Int!, i.e.

type Event @entity {
    id: ID!
    timestamp: Int
}

and

type Event @entity {
    id: ID!
    timestamp: Int!
}

both generate the following getter and setter:

  get timestamp(): i32 {
    let value = this.get("timestamp");
    return value!.toI32();
  }

  set timestamp(value: i32) {
    this.set("timestamp", Value.fromI32(value));
  }

iherger avatar May 24 '22 16:05 iherger

I have the same issue, any progress on this?

KedziaPawel avatar Oct 03 '23 12:10 KedziaPawel

@KedziaPawel are you encountering a specific issue / unexpected behaviour? @saihaj @incrypto32 might have more context but from memory there is an issue with Assemblyscript returning the same for null and 0

azf20 avatar Oct 08 '23 22:10 azf20

My problem is that in the schema.graphql I've declared the variable as eModeCategoryId: Int, so I would expect that I can assign null to it. But in the code, I can assign only a number to it. I've added some screenshots. My @graphprotocol/graph-ts library version is 0.31.0

Screenshot 2023-10-09 at 10 43 51 Screenshot 2023-10-09 at 10 45 21

KedziaPawel avatar Oct 09 '23 08:10 KedziaPawel

OK got it - and you want to assign null to it to "unset" the field in certain cases?

azf20 avatar Oct 09 '23 09:10 azf20

Any update @azf20?

Seems to still be an issue. We've extended an entity as part of a graft. The attribute is a nullable int - Int, yet similarly generated getter is non-nullable.

thebuidler avatar Feb 02 '24 01:02 thebuidler

yes I did some research and did some improvements https://github.com/graphprotocol/graph-tooling/pull/1284 we will end up returning a default value which would be 0 which won't essentially translate to null

saihaj avatar Feb 02 '24 16:02 saihaj