I have a problem with typing GraphQLInputObjectType. I can't find a way to inherit Prisma 2 types.
There is no problem when I type them manually for create, delete and other similar inputs, but prisma 2 has some very complex filters that are hard to manually type.
This is what prisma 2 where types are
Prisma 2 types for "where" property
export type PersonOrganisationRoleWhereInput = {
AND?: Enumerable<PersonOrganisationRoleWhereInput>
OR?: Enumerable<PersonOrganisationRoleWhereInput>
NOT?: Enumerable<PersonOrganisationRoleWhereInput>
id?: IntFilter | number
nickname?: StringFilter | string
person?: XOR<PersonRelationFilter, PersonWhereInput>
personId?: IntFilter | number
role?: XOR<RoleRelationFilter, RoleWhereInput>
roleId?: IntFilter | number
organisation?: XOR<OrganisationRelationFilter, OrganisationWhereInput>
organisationId?: IntFilter | number
created?: DateTimeFilter | Date | string
updated?: DateTimeNullableFilter | Date | string | null
expired?: DateTimeNullableFilter | Date | string | null
Seafarer?: SeafarerListRelationFilter
}
StringFilter (Just one of many)
export type StringFilter = {
equals?: string
in?: Enumerable<string>
notIn?: Enumerable<string>
lt?: string
lte?: string
gt?: string
gte?: string
contains?: string
startsWith?: string
endsWith?: string
search?: string
mode?: QueryMode
not?: NestedStringFilter | string
}
My manual typing of graphqlInputType
export const PersonOrganisationRoleWhereInput: GraphQLInputObjectType =
new GraphQLInputObjectType({
name: 'PersonOrganisationRoleWhereInput',
fields: () => ({
id: { type: GraphQLID },
roleId: { type: GraphQLInt },
name: { type: StringFilter },
created: { type: GraphQLString },
updated: { type: GraphQLString },
expired: { type: GraphQLString },
AND: { type: GraphQLList(PersonOrganisationRoleWhereInput) },
OR: { type: GraphQLList(PersonOrganisationRoleWhereInput) },
NOT: { type: GraphQLList(PersonOrganisationRoleWhereInput) },
}),
});
My manual typing of StringFilter
export const StringFilter = new GraphQLInputObjectType({
name: 'StringFilter',
fields: () => ({
equals: { type: GraphQLString },
not: { type: GraphQLString },
in: { type: GraphQLList(GraphQLString) },
notIn: { type: GraphQLString },
lt: { type: GraphQLString },
lte: { type: GraphQLString },
gt: { type: GraphQLString },
gte: { type: GraphQLString },
contains: { type: GraphQLString },
mode: { type: GraphQLString },
}),
});
Now the problem is that prisma 2 has many types and it would take a long time to manually adjust it to GraphQLInputObjectType. Especially when they add new things with each update.
WHY DO I NEED IT? When passing args to Apollo useQuery/useMutation, graphql blocks the request as some prisma 2 types do not match my GraphQLInputObjectType. Types must match perfectly in order for it to pass.
For example:
//Prisma 2 type
id?: IntFilter | number
I cannot type GraphQLInputObjectType as prisma 2 type, as I can either set it as IntFilter or number. If it is IntFilter, I can't set a number as argument, even tho prisma 2 accepts both values.
Is there a simple way to inherit those properties inside GraphQLInputObjectType?