-
Notifications
You must be signed in to change notification settings - Fork 860
Scalar lists must not be nullable #1943
Comments
@timsuchanek Just encountered this and it's especially painful with Typescript generated bindings. If you can point me in the right direction where this is generated, I can give a stab at fixing it. |
Ok, I think I've tracked the whole thing down to this point. I don't know Scala, but this part seems to be ok. That would mean that @marktani Can you perhaps help with this or ping someone who can? I am rather annoyed by this and I really want to put some effort into fixing it. |
Thanks a lot for your feedback, @FredyC. I think a great first step is to start out with a test case that fails. Then you can dive into the solution 🙂 From what I can tell, because of this inconsistent schema generation, your generated bindings accepts Thanks! |
@marktani Thank you for your response. I would love to provide a test case, but since this is Scala issue, I am not sure how that's done in there. I've been looking into some present tests, but it's so far from Jest and my head exploded :) Ultimately the issue bubbles up to this in resolvers. You can spot that I have to force type return value because of inconsistent typings. It doesn't feel like a huge issue here, but it's kinda giving up on static typing benefits here and unable to discover mistakes easily. export const myContacts: Query.myContacts = async (_, __, ctx, info) => {
const playerId = getPlayerId(ctx)
const players = await ctx.db.query.players(
{ orderBy: 'createdAt_DESC', where: { id_not: playerId } },
info,
)
return players as Player[] // <-- have to force type here
}
namespace Query {
export type myContacts = (parent: any, args: {}, context: Context, info?: GraphQLResolveInfo | string) => Promise<Player[]>
}
export interface Player {
id: ID_Output
fights: Fight[] // <-- correctly required field
} Those types are generated with my custom generator based on an assembly of Now on the other side where Prisma generates typings for binding it has its own Given datamodel type... type Player {
id: ID! @unique
fights: [Fight!]!
} The generated graphql schema looks like this type Player implements Node {
id: ID!
fights(usualInputVariables): [Fight!] # <-- missing require flag
} This issue is then transformed to Typescript (with prisma-ts binding generator). This type is then returned from export interface Player extends Node {
id: ID_Output
fights?: Fight[] // <-- wrong optional field
} |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Sorry in advance to ask without adding much to the discussion. EDIT: However, when defining the client API on schema.graphql, a [String!]! will properly require a [String!]!, not just [String!] |
@Esxiel : Yes this intended. We don't required the posts in the input because an empty list would also be a valid value in this case. Hence it does not add any guarantees about the number of elements in the relation. For single relation fields, e.g. |
Closing because this is already implemented. |
When creating a scalar list field like this:
The resulting schema generated looks like this:
The text was updated successfully, but these errors were encountered: