neo4j-graphql-js icon indicating copy to clipboard operation
neo4j-graphql-js copied to clipboard

@relation on type does not respect non-nullable marks

Open smajl opened this issue 4 years ago • 1 comments

Unfortunately these two definitions do not produce the same schema:

type A {
  uuid: ID!
  bs: [B!]! @relation(name: "HAS_B", direction: OUT)
}

type B {
  uuid: ID!
  as: [A!]! @relation(name: "HAS_B", direction: OUT)
}

vs

type A {
  uuid: ID!
  bs: [HasB!]! # ignored
}

type B {
  uuid: ID!
  as: [HasB!]! # ignored
}

type HasB @relation(name: "HAS_B") {
  from: A
  to: B
}

In the later, the non-nullable marks ! are ignored. So when using tools like graphql-codegen you will get

export type Maybe<T> = T | null;

export type A = {
  __typename?: 'A';
  uuid: Scalars['ID'];
  bs?: Maybe<Array<Maybe<_ABs>>>; // should be `bs: Array<_ABs>`
  _id?: Maybe<Scalars['String']>;
};

export type _ABs = {
  __typename?: '_ABs';
  B?: Maybe<B>; // this is also weird, should be `B: B`
};

And that is a pain to access with strict mode TypeScript...

smajl avatar Aug 16 '19 09:08 smajl

https://github.com/neo4j-graphql/neo4j-graphql-js/issues/608

michaeldgraham avatar May 02 '21 04:05 michaeldgraham